CoopTilleulsAclSonataAdminExtensionBundle icon indicating copy to clipboard operation
CoopTilleulsAclSonataAdminExtensionBundle copied to clipboard

AclSonataAdmin and Inheritance

Open StephanePate opened this issue 9 years ago • 13 comments

I have a bundle like the SonataProductBundle where in the sandbox "Travels" and "Goodies" entities have the "Product" entity as parent. When I enable the AclSonataAdminExtension and go to the ProductAdmin, I have an empty list of Products (even if I am OWNER of a list of sub-entities Travels & Goodies for example) because the Acl is managed at the entity level I guess.

Is there a way to avoid this ?

StephanePate avatar Sep 08 '15 09:09 StephanePate

This bundle doesn't support inheritance (at least, AFAIK this has never been tested). But feedback and PRs about inheritance support are very welcome.

dunglas avatar Sep 08 '15 09:09 dunglas

Thanks for your quick answer, I'll try to find a way and feed you back if I get something functional !

StephanePate avatar Sep 08 '15 10:09 StephanePate

overriding the postPersist method of carAdmin (sandbox) with:

    /**
     * {@inheritdoc}
     */
    public function postPersist($object)
    {
        if ($this->isAclEnabled()) {
            $objectIdentity = new ObjectIdentity($object->getId(), get_parent_class($object));
            $acl = $this->getSecurityHandler()->createAcl($objectIdentity);

            $user = $this->tokenStorage->getToken()->getUser();
            $securityIdentity = UserSecurityIdentity::fromAccount($user);

            $this->getSecurityHandler()->addObjectOwner($acl, $securityIdentity);
            $this->getSecurityHandler()->addObjectClassAces($acl, $this->getSecurityHandler()->buildSecurityInformation($this));
            $this->getSecurityHandler()->updateAcl($acl);           
        }
    }

seems to do the trick (the car list is not empty anymore...), with injection of tokenStorage in the admin class.

It could be done exactly the same way but with a very sligth modification of the createObjectSecurity method of AclSecurityHandler class if it could allow creation of the $objectIdentity = new ObjectIdentity($object->getId(), get_parent_class($object)) ... What do you think ?

StephanePate avatar Sep 09 '15 19:09 StephanePate

Looking for same functionality. It seems https://github.com/MrGreenStuff/MrGreenStuffAclSonataAdminExtensionBundle doing exactly what's needed. Somehow the code looks a bit unoptimized, but will give it a try.

vbartusevicius avatar Sep 11 '15 14:09 vbartusevicius

Can you open a PR to add this feature upstream? Cc @MrGreenStuff

dunglas avatar Sep 11 '15 14:09 dunglas

Not really the same issue I think : MrGreen addresses the "embedded admin" (with relation 1 to N between "Parent" and "Child" Entities (that are both concrete Classes without inheritance between both). My concern is between "Parent" and "Child" Entities where the parent is possibly an Abstract Class (like car in the sandbox) and the child is a concrete Class extending the parent.

As the ACL Classes are totally seggregated from the DomainObjects, my proposal is to accept (in AclSecurityHandler) that an abstract class in the DomainObject (the parent) would have acl entries (for the object ids of their children) attached to it, as if it was a concrete one.

StephanePate avatar Sep 11 '15 15:09 StephanePate

@dunglas - it seems that https://github.com/MrGreenStuff/MrGreenStuffAclSonataAdminExtensionBundle is a bit abandoned. Is it possible to merge that fork here without the author itself?

vbartusevicius avatar Sep 15 '15 09:09 vbartusevicius

Yes as long as it's the same license it should be ok.

dunglas avatar Sep 15 '15 09:09 dunglas

@dunglas - I've already propose a PR 2 year ago with my fork but it was not accepted because it's for specific case. My Fork it's not well optimized but now you can use this bundle https://github.com/GoDisco/AclTreeBundle and modify my bundle to use it or make a new fork of this bundle and use it in. It's will be more optimized and usable not only in the sonata admin.

MrGreenStuff avatar Sep 15 '15 10:09 MrGreenStuff

The old PR if you want to merge : https://github.com/coopTilleuls/CoopTilleulsAclSonataAdminExtensionBundle/pull/10

MrGreenStuff avatar Sep 15 '15 11:09 MrGreenStuff

I already implemented a Voter to forbid accessing items, whitch are not visible by @MrGreenStuff implementation. There currenty is a security issue: if user opens an item for editing, and then he changes the id in URL and submits, then in edit form a requested item will be loaded, ignoring the fact that he does not have permissions to edit.

vbartusevicius avatar Sep 15 '15 13:09 vbartusevicius

@dunglas, any news on merging that PR?

vbartusevicius avatar Sep 21 '15 20:09 vbartusevicius

If you're speaking about #10, it needs some work before being merged (see my comments on that PR).

I'll take a look at the security issue asap.

dunglas avatar Sep 22 '15 07:09 dunglas