symfony2 : twig extension is_granted('EDIT', comment) doesn't work in a foreach loop
Asked Answered
K

1

5

The code of the official ACL example works : http://symfony.com/doc/current/cookbook/security/acl.html

If I do that, no problem...

{% if is_granted('EDIT', comment) %}
    Edit
{% endif %}

... but if I want a "Granted Access" to an associated object, it doesn't work.

{% for comment in news.comments %}
    comment.content
    {% if is_granted('EDIT', comment) %}
        Edit
    {% endif %}
{% endfor %}

I think the twig extension can't know that "comment" is a "Comment Entity".

The query searches "Proxies\JblNewsBundleEntityCommentProxy" instead of "Jbl\NewsBundle\Entity\Comment" :

SELECT a.ancestor_id FROM acl_object_identities o INNER JOIN acl_classes c ON c.id = o.class_id INNER JOIN acl_object_identity_ancestors a ON a.object_identity_id = o.id WHERE ((o.object_identifier = '38' AND c.class_type = 'Proxies\\JblNewsBundleEntityCommentProxy'))

But I don't know how to fix that.

Have you a solution, please ?

Kanter answered 30/3, 2012 at 17:0 Comment(0)
E
9

It's fixed in symfony 2.1.

For old, 2.0 version the fix is here:

Overriding the ObjectIdentityRetrievalStrategy to check if a domain object is a Doctrine proxy

Eos answered 30/3, 2012 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.