serenysoft / nova-permissions

Laravel Nova 4 Roles & Permissions
72 stars 25 forks source link

There is no permission named `viewAnyRole` for guard `web` Error #10

Closed Bamux closed 1 year ago

Bamux commented 1 year ago

I have a fresh Laravel (v10.1.5 with PHP v8.2.0) installation, including Nova. I can also successfully log into the Nova backend. When I follow your installation instructions step by step and then try to log into the Nova backend, I get the following error message.

Spatie\Permission\Exceptions\PermissionDoesNotExist There is no permission named viewAnyRole for guard web.

https://flareapp.io/share/W7zRa0k7#F94

Do you have any idea what could be causing this?

leandrogehlen commented 1 year ago

https://github.com/serenysoft/nova-permissions#database-seeding

arturasfrontit commented 1 year ago

https://github.com/serenysoft/nova-permissions#database-seeding

what if we have custom names and your seeder is not suitable for us?

leandrogehlen commented 1 year ago

The seeder is an example only. You should modify as you see fit

arturasfrontit commented 1 year ago

The seeder is an example only. You should modify as you see fit

you have integrated check for:

There is no permission named `viewAnyRole` for guard `web`.
There is no permission named `updateRole` for guard `web`
leandrogehlen commented 1 year ago

https://nova.laravel.com/docs/4.0/resources/authorization.html

arturasfrontit commented 1 year ago

https://nova.laravel.com/docs/4.0/resources/authorization.html

Its package predefined policies, I want change them.

can you make optional? NovaPermissions.php

Gate::policy(config('permission.models.permission'), $this->permissionPolicy);
Gate::policy(config('permission.models.role'), $this->rolePolicy);

registering new classes in provider doesn't override them

leandrogehlen commented 1 year ago

Does not make sense to do it. It's only include these permissions in your Seeder

Please see: https://github.com/serenysoft/nova-permissions/commit/d617b844036fd6618cec4e871a354c3a2e519d94

arturasfrontit commented 1 year ago

Does not make sense to do it. It's only include these permissions in your Seeder

Please see: d617b84

I wanted to overite PermissionPolicy to return false in all methods. You defined it in NovaPermissions.php and AuthServiceProvider can't overide it. I found another solution to override you file, but it would be nice to turn off it in package config

leandrogehlen commented 1 year ago

if you don't want the permissions to be available, use disablePermissions() https://github.com/serenysoft/nova-permissions#customizations

arturasfrontit commented 1 year ago

if you don't want the permissions to be available, use disablePermissions() https://github.com/serenysoft/nova-permissions#customizations

I want use custom policies instead of yours NovaPermissions.php

if($enabled) {
  Gate::policy(config('permission.models.permission'), $this->permissionPolicy);
  Gate::policy(config('permission.models.role'), $this->rolePolicy);
}
buttjer commented 1 year ago

@arturasfrontit Our solution was using a Role Policy and the default Nova way with canSeeWhen.

    public function tools(): array
    {
        return [
            \Sereny\NovaPermissions\NovaPermissions::make()
                ->hideFieldsFromPermission(['group'])
                ->canSeeWhen('viewAnyRole', User::class),
        ];
    }

@leandrogehlen Consider to make this the default. Or at least if there is not viewAnyRole in the permission table. because it is not documented that this is necessary.

leandrogehlen commented 1 year ago

ref https://github.com/serenysoft/nova-permissions/issues/34#issuecomment-1756205519