diff --git a/src/Fields/Role.php b/src/Fields/Role.php index 7972255..a6c207c 100644 --- a/src/Fields/Role.php +++ b/src/Fields/Role.php @@ -36,7 +36,7 @@ public function __construct($name, $attribute = null, $resolveCallback = null) public function options() { return $this->withMeta([ - 'options' => \DC\PermissionTool\Models\Role::get()->map(function ($role) { + 'options' => \DigitalCloud\PermissionTool\Models\Role::get()->map(function ($role) { return [ 'display' => $role->name, 'value' => $role->id, diff --git a/src/Policies/PermissionPolicy.php b/src/Policies/PermissionPolicy.php index 594ed0f..2dd72c3 100644 --- a/src/Policies/PermissionPolicy.php +++ b/src/Policies/PermissionPolicy.php @@ -10,6 +10,26 @@ class PermissionPolicy { use HandlesAuthorization; + public function attachAnyRole() + { + return true; + } + + public function detachRole() + { + return true; + } + + public function attachAnyUser() + { + return true; + } + + public function detachUser() + { + return true; + } + public function viewAny(): bool { return true; diff --git a/src/Policies/RolePolicy.php b/src/Policies/RolePolicy.php index 9840185..c2abe89 100644 --- a/src/Policies/RolePolicy.php +++ b/src/Policies/RolePolicy.php @@ -10,6 +10,26 @@ class RolePolicy { use HandlesAuthorization; + public function attachAnyPermission() + { + return true; + } + + public function detachPermission() + { + return true; + } + + public function attachAnyUser() + { + return true; + } + + public function detachUser() + { + return true; + } + public function viewAny(): bool { return true; diff --git a/src/Resources/Role.php b/src/Resources/Role.php index 354f86c..a4a6d50 100644 --- a/src/Resources/Role.php +++ b/src/Resources/Role.php @@ -75,12 +75,15 @@ public function fields(Request $request) } $resourceName = strtolower(substr(strrchr($resource, "\\"), 1)); $resourcePermissions = [ - "create $resourceName" => "create $resourceName", - "update $resourceName" => "update $resourceName", - "view $resourceName" => "view $resourceName", - "delete $resourceName" => "delete $resourceName", - "force delete $resourceName" => "force delete $resourceName", - "restore $resourceName" => "restore $resourceName" + "viewAny $resourceName" => "viewAny $resourceName", + "create $resourceName" => "create $resourceName", + "update $resourceName" => "update $resourceName", + "view $resourceName" => "view $resourceName", + "delete $resourceName" => "delete $resourceName", + "force delete $resourceName" => "force delete $resourceName", + "restore $resourceName" => "restore $resourceName", + "attach $resourceName" => "attach $resourceName", + "detach $resourceName" => "detach $resourceName" ]; foreach ($resourcePermissions as $resourcePermission) { $dbPermision = \DigitalCloud\PermissionTool\Models\Permission::firstOrCreate( diff --git a/src/ToolServiceProvider.php b/src/ToolServiceProvider.php index 21ab524..d901af1 100644 --- a/src/ToolServiceProvider.php +++ b/src/ToolServiceProvider.php @@ -32,7 +32,14 @@ public function boot() Gate::policy(config('permission.models.permission'), PermissionPolicy::class); Gate::policy(config('permission.models.role'), RolePolicy::class); - + +// Super admin all permissions +// Gate::before(function ($user, $ability) { +// if ($user->email == 'mail@example.com') { +// return true; +// } +// }); + Nova::serving(function (ServingNova $event) { // });