RickDBCN / filament-email

Log emails in your Filament project
https://filament-email-demo.marcogermani.it/
MIT License
77 stars 23 forks source link

Use policy #33

Closed JeromeSiau closed 8 months ago

JeromeSiau commented 8 months ago

What happened?

I don't use Shield but I use very simple laravel policies

It seems my policy is ignored and I'm not sure how to fit it

How to reproduce the bug

  1. install plugin
  2. create a policy with the same name php artisan make:policy EmailPolicy
  3. Set return false in viewAny, the page should not be visible in the navigation anymore

It's the first time I'm trying to use a policy on a resource coming from a plugin so I might do something wrong

Package Version

1.0.10

PHP Version

8.2.14

Laravel Version

10.10

Which operating systems does with happen with?

macOS

Notes

No response

JeromeSiau commented 8 months ago

Hi,

I find out how to do it. Laraval is not able to auto-discover policies when it's in the vendor directory, so you just need to help Laravel by manually registering the policy in the App\Providers\AuthServiceProvider

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The model to policy mappings for the application.
     *
     * @var array<class-string, class-string>
     */
    protected $policies = [
        'RickDBCN\FilamentEmail\Models\Email' => 'App\Policies\EmailPolicy',
    ];

...
stuartcusackie commented 1 month ago

This seems to have no effect on the menu item. I can't hide it with this method, and I don't use spatie roles on this project. Laravel: 10.48.20, Filament Email: v1.5.1

Alternative solution is to use the config and add a custom hasRole() method to your user model.