use permissions trait in module
This commit is contained in:
parent
c5cfc42a7c
commit
e99e340964
@ -3,11 +3,12 @@
|
|||||||
namespace Modules\OfflinePayments\Listeners;
|
namespace Modules\OfflinePayments\Listeners;
|
||||||
|
|
||||||
use App\Events\Module\Installed as Event;
|
use App\Events\Module\Installed as Event;
|
||||||
use App\Models\Auth\Role;
|
use App\Traits\Permissions;
|
||||||
use App\Models\Auth\Permission;
|
|
||||||
|
|
||||||
class InstallModule
|
class InstallModule
|
||||||
{
|
{
|
||||||
|
use Permissions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the event.
|
* Handle the event.
|
||||||
*
|
*
|
||||||
@ -25,41 +26,7 @@ class InstallModule
|
|||||||
|
|
||||||
protected function updatePermissions()
|
protected function updatePermissions()
|
||||||
{
|
{
|
||||||
$permissions = [];
|
$this->createModuleSettingPermission('offline-payments', 'read');
|
||||||
|
$this->createModuleSettingPermission('offline-payments', 'update');
|
||||||
$permissions[] = Permission::firstOrCreate([
|
|
||||||
'name' => 'read-offline-payments-settings'
|
|
||||||
], [
|
|
||||||
'display_name' => 'Read Offline Payments Settings',
|
|
||||||
'description' => 'Read Offline Payments Settings',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$permissions[] = Permission::firstOrCreate([
|
|
||||||
'name' => 'update-offline-payments-settings'
|
|
||||||
], [
|
|
||||||
'display_name' => 'Update Offline Payments Settings',
|
|
||||||
'description' => 'Update Offline Payments Settings',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$permissions[] = Permission::firstOrCreate([
|
|
||||||
'name' => 'delete-offline-payments-settings'
|
|
||||||
], [
|
|
||||||
'display_name' => 'Delete Offline Payments Settings',
|
|
||||||
'description' => 'Delete Offline Payments Settings',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$roles = Role::all()->filter(function ($r) {
|
|
||||||
return $r->hasPermission('read-admin-panel');
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach ($roles as $role) {
|
|
||||||
foreach ($permissions as $permission) {
|
|
||||||
if ($role->hasPermission($permission->name)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$role->attachPermission($permission);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user