Skip to content

Commit

Permalink
use permissions trait in module
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Apr 3, 2020
1 parent c5cfc42 commit e99e340
Showing 1 changed file with 5 additions and 38 deletions.
43 changes: 5 additions & 38 deletions modules/OfflinePayments/Listeners/InstallModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -25,41 +26,7 @@ public function handle(Event $event)

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');
}
}

0 comments on commit e99e340

Please sign in to comment.