You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Short description of what this feature will allow to do:
Currently, when configuring a permission for a MenuItem, an action, a crud, or a field, the setPermission() method expects a string or an expression. It would be interesting to also accept a boolean based on conditions
Here, the permission is validated if the user has the ROLE_SUPER_ADMIN role or the ROLE_ENTERPRISE role.
Here is an example with roles, but it could be something else.
The main reason for this request is that it forces us to create a Voter on purpose for this, which is disruptive.
Or the alternative is currently something like this :
yield MenuItem::linkToCrud('Administrateurs', 'bi bi-shield-lock', User::class)
->setController(AdminCrudController::class)
->setPermission(newExpression("is_granted('".UserRole::ROLE_SUPER_ADMIN->value."') or is_granted('".UserRole::ROLE_ENTREPRISE->value."')"));
But it's not practical.
Likewise, from CRUD, it will be useful to be able to do the same thing in the configureCrud() method :
I created a helper which returns me an expression, conforming to my expectations, if it can help some people :
<?phpnamespaceApp\Helper;
useSymfony\Component\ExpressionLanguage\Expression;
classEasyAdminPermissionHelper
{
/** * Returns an Expression that checks if the user has any of the given roles. * * @param array $roles Array of role strings * @return Expression */publicstaticfunctionisGrantedAny(array$roles): Expression
{
$expressions = array_map(
fn($role) => "is_granted('{$role}')",
$roles
);
$expressionString = implode(' or ', $expressions);
returnnewExpression($expressionString);
}
/** * Returns an Expression that checks if the user has all of the given roles. * * @param array $roles Array of role strings * @return Expression */publicstaticfunctionisGrantedAll(array$roles): Expression
{
$expressions = array_map(
fn($role) => "is_granted('{$role}')",
$roles
);
$expressionString = implode(' and ', $expressions);
returnnewExpression($expressionString);
}
}
Short description of what this feature will allow to do:
Currently, when configuring a permission for a MenuItem, an action, a crud, or a field, the
setPermission()
method expects a string or an expression. It would be interesting to also accept a boolean based on conditionsExample of how to use this feature
Here, the permission is validated if the user has the ROLE_SUPER_ADMIN role or the ROLE_ENTERPRISE role.
Here is an example with roles, but it could be something else.
The main reason for this request is that it forces us to create a Voter on purpose for this, which is disruptive.
Or the alternative is currently something like this :
But it's not practical.
Likewise, from CRUD, it will be useful to be able to do the same thing in the
configureCrud()
method :EDIT :
I created a helper which returns me an expression, conforming to my expectations, if it can help some people :
And now :
The text was updated successfully, but these errors were encountered: