Using ACLs for SonataAdminBundle in configureFormFields

I installed SonataAdminBundle, SonataUserBundle and FOSUserBundle, as well as CoopTilleulsAclSonataAdminExtensionBundle using ACLs in SonataAdminBundle.

Lists are filtered out by the owners and everything is in order. Client A can only see his items, client b is also just him. But if I am going to create a new object, I can also see elements of other clients.

Suppose a customer can create groups that will be used to assign products. This is done when creating the product in the form of a drop-down list (many-to-one relationship, as well as the presentation of products). But I also see groups created by another client.

How can I filter this out? I think I need to do filtering in ProductAdmin.php. Or should this happen in ProductsRepository.php? I can’t find any hints in the documents so far and will use any hint or link where I can find information for this.

+8
symfony sonata-admin sonata
source share
1 answer

You need to either overwrite the branch editing template or create a custom flag. See this override question . I do not know your entity structure, but the process should look like

{% for object in objects %} {% if owned by this user flag display %} {{object}} {% endif %} {% endfor%} 

Custom select request in admin class, e.g.

  $em = $this->getConfigurationPool()->getContainer()->get('doctrine.orm.entity_manager'); $user = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser(); $query = $em->createQueryBuilder('p') ->select('p') ->from('MyBundle:Product', 'p') ->where('p.user = :user') ->setParameter('user', $user); $formMapper ... ->add('categoria', 'sonata_type_model', array( 'required' => true, 'query' => $query )) 
0
source share

All Articles