EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
3.99k stars 1.01k forks source link

custom voter case self::NEW: #6256

Closed budzik closed 1 month ago

budzik commented 1 month ago

Describe the bug sf7.0.6 ea 4.9.4

it looks like custom voter works for edit and delete which I defined. By adding permission for ACTION::NEW, the button above grid disappears automatically in the records list.

this is just a shot - voter works for dropdown links but [add new] action is a button above the list

To Reproduce //UserVoter ... switch ($attribute) { case self::NEW: return true; break; ...

//UserCrudController ...

[\Override]

public function configureActions(Actions $actions): Actions
{
    return $actions
       // ->disable(Action::BATCH_DELETE)
       // ->setPermission(Action::EDIT, UserVoter::EDIT)
       // ->setPermission(Action::DELETE, UserVoter::DELETE)
        ->setPermission(Action::NEW, UserVoter::NEW)
    ;
}

...

budzik commented 1 month ago

looks like for global actions we should use expressions not voter.

//UserCrudController [...] use Symfony\Component\ExpressionLanguage\Expression; use App\Security\Voter\UserVoter; [...] `

public function configureActions(Actions $actions): Actions { return $actions ->disable(Action::BATCH_DELETE) ->setPermission(Action::EDIT, UserVoter::EDIT) ->setPermission(Action::DELETE, UserVoter::DELETE) ->setPermission(Action::NEW, new Expression('"ROLE_MODERATOR" in role_names')) ; } `