8
votes

I've installed SonataAdminBundle, SonataUserBundle and FOSUserBundle as well as CoopTilleulsAclSonataAdminExtensionBundle while using ACL in the SonataAdminBundle.

The listings are filtered by owners and all is fine. Customer A can see just his items, customer b also just his ones. But if i'm going to create a new object i can see items of other customers too.

Lets say a customer can create groups that will be used to assign products to. This is done while creating a product as a dropdown list (many-to-one relation as of products view). But i also can see groups that have been created by another customer.

How can i filter this? I think i have to do any filtering in the ProductsAdmin.php. Or does it have to happen in the ProductsRepository.php? I can't find any hints in the docs so far and would appriciate any kind of hint or link where i can find informations for this.

1
@Filchev I have been reading this several times before, especially the part with CoopTilleulsAclSonataAdminExtensionBundle, which works in List Mode but not in Edit modeMichael
Still looking for a good answer.Michael

1 Answers

0
votes

You need to either overwrite the edit twig template or create a custom select box. See this question about about overriding. I don`t know your entity structure but the process should go like

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

Custom select query in the admin class like

    $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
))