-
Notifications
You must be signed in to change notification settings - Fork 58
Description
Hi everyone. This issue is not about a bug, but to bring a discussion about the state of a functionality.
Currently, we can define a role per action in our entities to lock some users from accessing the show
action for example. This is fine and great, but here is the issue...
I was trying to get results from an autocomplete
field on a user with an inferior role. So I configured my entity like this :
easy_admin:
entities:
MyEntity:
class: path\to\MyEntity
role: ROLE_ADMIN # the role is applied to all actions
autocomplete:
role: ROLE_USER # the role attribute is overrided for this action
I could not understand why this would not work, until I find that the isActionAllowed()
is overrided in the EasyAdminController.php
of this bundle. Here is how it looks like :
protected function isActionAllowed($actionName)
{
switch ($actionName) {
// autocomplete action is mapped to list action for access permissions
case 'autocomplete':
// embeddedList action is mapped to list action for access permissions
case 'embeddedList':
$actionName = 'list';
break;
// newAjax action is mapped to new action for access permissions
case 'newAjax':
$actionName = 'new';
break;
default:
break;
}
// Get item for edit/show or custom actions => security voters may apply
$easyadmin = $this->request->attributes->get('easyadmin');
$subject = $easyadmin['item'] ?? null;
$this->get(AdminAuthorizationChecker::class)->checksUserAccess($this->entity, $actionName, $subject);
return parent::isActionAllowed($actionName);
}
You can see that the autocomplete
action is treated like the list
one.
And this is where I'm lost : is there a particular reason we're not able to configure the autocomplete
action to be used by a lesser role? If not, it would be great to "fix" this by removing this action from the switch
case.
I'm open to discuss about it.
Have a great day/night.