diff --git a/README.md b/README.md index d2bda66..b94fc23 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Nova Permission Tool. -This tool allows you to create and manage rules and permissions for nova resources. After installation, the default nova resource permissions will be generated for all available resources. +This tool allows you to create and manage rules and permissions for nova resources. After installation, the default nova resource permissions will be generated for all available resources and resource actions. # Requirements & Dependencies This tool uses [Spatie Permission](https://github.com/spatie/laravel-permission) package. @@ -45,5 +45,57 @@ public function tools() ``` +To allow the tool to generate permissions actions, you need to se the name of the action. Actions with no names will not be generated automatically. + +```php +canSee(function ($request) { + return Gate::check('send email'); // the same name of the action + })->canRun(function ($request) { + return Gate::check('send email'); // the same name of the action + }) + ]; + } + + // ... +} + +``` + ## Images ![per](https://user-images.githubusercontent.com/41853913/50079673-e1971880-01f2-11e9-9e45-d9c0c7e1b861.PNG) diff --git a/src/Resources/Role.php b/src/Resources/Role.php index a4a6d50..9367e34 100644 --- a/src/Resources/Role.php +++ b/src/Resources/Role.php @@ -85,6 +85,13 @@ public function fields(Request $request) "attach $resourceName" => "attach $resourceName", "detach $resourceName" => "detach $resourceName" ]; + // add resource actions + $object = new $resource($resource::$model); + foreach ($object->actions($request) as $action) { + if($action->name) { + $resourcePermissions[$action->name] = $action->name; + } + } foreach ($resourcePermissions as $resourcePermission) { $dbPermision = \DigitalCloud\PermissionTool\Models\Permission::firstOrCreate( ['name' => $resourcePermission], ['guard_name' => 'web']