Skip to content

Commit

Permalink
actions permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
devmtm committed Feb 6, 2019
1 parent fce87fb commit 4650cad
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
<?php

namespace App\Nova\Actions;

use Laravel\Nova\Actions\Action;

class YourAction extends Action {

// ...

public $name = 'send email';

// ...

}

```

and then in the resource you can authorize the action:

```php
<?php

namespace App\Nova;

use App\Nova\Actions\YourAction;
use Illuminate\Support\Facades\Gate;
use Illuminate\Http\Request;


class Quotation extends Resource {

// ...

public function actions(Request $request) {
return [
(new YourAction())->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)
7 changes: 7 additions & 0 deletions src/Resources/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit 4650cad

Please sign in to comment.