The easiest way is to edit the request and check access in the edit / show actions.
Something like that:
Admin class
public function createQuery($context = 'list')
{
$user = $this->getConfigurationPool()->getContainer()->get('security.context')->getToken()->getUser();
$query = $this->getModelManager()->createQuery($this->getClass(), 'o');
if (!$this->isGranted('MASTER')) {
$query
->where('entity.user = :user')
->setParameter('user', $user)
;
}
return $query;
}
If the user is not a MASTER, he will only see his entities.
You can also implement the hasSubjectAccessadmin class method , for example:
protected function hasSubjectAccess()
{
$user = $this->getConfigurationPool()->getContainer()->get('security.context')->getToken()->getUser();
if (!$this->isGranted('MASTER') && $this->getSubject()->getUser() !== $user) {
return false;
}
return true;
}
and perform this type of validation in editable and displayed forms:
protected function configureFormFields(FormMapper $formMapper)
{
if (!$this->hasSubjectAccess()) {
throw new AccessDeniedException();
}
}
Another way is to implement an ACL. You can learn more about this in the official documentation.