vyuldashev / nova-permission

A Laravel Nova tool for Spatie's laravel-permission library
https://novapackages.com/packages/vyuldashev/nova-permission
419 stars 217 forks source link

Hide Roles and Permissions from Nova navigation using policies #129

Closed JonoB closed 4 years ago

JonoB commented 4 years ago

I'm trying to hide the Permissions and Roles from the sidebar using a policy, but it doesn't seem to be working for me

// AuthServiceProvider

    protected $policies = [
        \Spatie\Permission\Models\Permission::class => \App\Policies\PermissionPolicy::class,
        \Spatie\Permission\Models\Role::class => \App\Policies\RolePolicy::class,
    ];
// App/Policies/PermissionPolicy

    public function viewAny(User $user)
    {
        return false;
    }

But the permissions are still shown in the Nova navigation. What am I missing?

vyuldashev commented 4 years ago

From readme:


// in app/Providers/NovaServiceProvider.php

// ...

public function tools()
{
    return [
        // ...
        \Vyuldashev\NovaPermission\NovaPermissionTool::make()
            ->roleResource(CustomRole::class)
            ->permissionResource(CustomPermission::class),
    ];
}```
JonoB commented 4 years ago

Works now, thanks!

For the sake of correctness, it should refer to the Policies, and not the Resources:

    public function tools()
    {
        return [
            \Vyuldashev\NovaPermission\NovaPermissionTool::make()
                ->rolePolicy(RolePolicy::class)
                ->permissionPolicy(PermissionPolicy::class),
        ];
    }