novatoolpermissions icon indicating copy to clipboard operation
novatoolpermissions copied to clipboard

Added model parameter to RolePolicy methods

Open matthiascw opened this issue 6 years ago • 0 comments

I would suggest to accept model parameters in RolePolicy.php. In that case we are able to extend the RolePolicy.php to add behavior for specific roles.

For example I have created a custom permission canManageAdminRole and extended the RolePolicy.php with a new Policy so that all users without that permission can't view my admin role with ID 1:

namespace App\Policies;

use Silvanite\NovaToolPermissions\Policies\RolePolicy;

class RoleExtensionPolicy extends RolePolicy
{
     public function view($user, $model)
     {
        if (!$user->can('canManageAdminRole')) {
            return $model->id !== 1;
        }

        return Gate::any(['viewRoles', 'manageRoles'], $user);
    }
}

EDIT: Added a default permission whether to show the Roles resource in dashboard or not.

matthiascw avatar Feb 07 '19 08:02 matthiascw