outl1ne / nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
MIT License
273 stars 97 forks source link

Applying a policy on the Settings model has no effect #39

Closed Sitethief closed 3 years ago

Sitethief commented 3 years ago

I could not get a Policy working on the Settings model. I tried the automatic way just by making a SettingsPolicy, and also tried registering the policy in the AuthServiceProvider. I quick fixed it with a temporary solution by wrapping the fields in NovaServiceProvider in an if statement dependent on the user permissions, but this still has the drawback of the settings page still being visible, albeit empty.

Am I missing something, or is this simply not implemented? or is there maybe a way to do this that I haven't found yet?

alexrififi commented 3 years ago

@Sitethief you can use authorization for tool

like this (app/Providers/NovaServiceProvider.php)

public function tools(): array
{
    return [
        NovaSettings::make()->canSee( fn() => is_user_can_settings() ),
    ];
}
Tarpsvo commented 3 years ago

Hi @Sitethief!

I added support for per-field authorization in version 3.1.0. If you want to hide the whole thing from the sidebar, I think @medvinator provided a pretty good solution.

I also added it to the README: https://github.com/optimistdigital/nova-settings#authorization

Thanks and good luck guys!

Sitethief commented 3 years ago

Yes, that works! Thanks!