use permissions trait in module
This commit is contained in:
parent
c5cfc42a7c
commit
e99e340964
@ -3,11 +3,12 @@
|
||||
namespace Modules\OfflinePayments\Listeners;
|
||||
|
||||
use App\Events\Module\Installed as Event;
|
||||
use App\Models\Auth\Role;
|
||||
use App\Models\Auth\Permission;
|
||||
use App\Traits\Permissions;
|
||||
|
||||
class InstallModule
|
||||
{
|
||||
use Permissions;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
@ -25,41 +26,7 @@ class InstallModule
|
||||
|
||||
protected function updatePermissions()
|
||||
{
|
||||
$permissions = [];
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
$this->createModuleSettingPermission('offline-payments', 'read');
|
||||
$this->createModuleSettingPermission('offline-payments', 'update');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user