Skip to content

Commit

Permalink
fix: Extension role changing keeps functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Jul 22, 2024
1 parent 070f551 commit 5dad41b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
20 changes: 18 additions & 2 deletions app/Http/Controllers/API/Settings/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,16 @@ public function extensions(Request $request)
*/
public function setExtensions(Request $request)
{
Permission::where([
$extensions = Permission::where([
'morph_id' => $request->role_id,
'type' => 'extension',
'key' => 'id',
])->delete();
]);

$role = Role::find($request->role_id);
$oldExtensions = $role->permissions->where('type', 'extension')->pluck('value')->toArray();

$extensions->delete();

foreach ($request->extensions as $extension) {
Permission::grant(
Expand All @@ -272,6 +277,17 @@ public function setExtensions(Request $request)
);
}

// Detect removed extensions and remove their functions
$newExtensions = $request->extensions;
$removedExtensions = array_diff($oldExtensions, $newExtensions);
foreach ($removedExtensions as $extension) {
Permission::where([
'morph_id' => $request->role_id,
'type' => 'function',
'value' => Extension::find($extension)->name,
])->delete();
}

AuditLog::write(
'role',
'edit',
Expand Down
15 changes: 0 additions & 15 deletions app/Models/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,6 @@ public function license()
return $this->hasOne('App\Models\License', 'extension_id');
}

/**
* Boot model
*
* @return void
*/
protected static function boot()
{
parent::boot();
static::addGlobalScope('extensions', function (
\Illuminate\Database\Eloquent\Builder $builder
) {
$builder->orderBy('order');
});
}

/**
* Get extension servers
*
Expand Down
2 changes: 1 addition & 1 deletion storage/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.3
2.1-dev

0 comments on commit 5dad41b

Please sign in to comment.