EasyCorp / EasyAdminBundle

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

Pass class name (or empty object) to index/new action voters #6101

Closed zorn-v closed 1 month ago

zorn-v commented 9 months ago

Currently there is no proper way to determine on which entity index/new action performed. It is useful for some sort of ACL like "user can create/view listing of some entity but not of other entities" stored in DB for example.

Actually you can get crudControllerFqcn query parameter and call getEntityFqcn static method on it now, but it is not good way I think.

systemasis commented 2 months ago

Seconded.

It's easy to block menu items but a pain to set permissions for a whole CRUD, especially with the actions piling up.

Even better would be to have a voter for a whole CRUD.

zorn-v commented 2 months ago

Even better would be to have a voter for a whole CRUD.

You can use setEntityPermission in configureCrud

systemasis commented 2 months ago

Indeed, though it only accepts an Expression which is, IMO, not on par with a voter.

zorn-v commented 2 months ago

it only accepts an Expression

No, it also accept string, and you can pass role there

systemasis commented 2 months ago

Indeed, I misread the related documentation.

zorn-v commented 2 months ago

Best documentation is source code :wink: https://github.com/EasyCorp/EasyAdminBundle/blob/8f17e48533b1c5979328fe71b9a02275d45baa84/src/Config/Crud.php#L392