Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added model parameter to RolePolicy methods #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

matthiascw
Copy link

@matthiascw matthiascw commented Feb 7, 2019

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 matthiascw changed the title Added model parameter to RolePolicy Added model parameter to RolePolicy methods Feb 7, 2019
yayann added a commit to SGS-Optimisation/novatoolpermissions that referenced this pull request Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant