Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

twig

symfony

acl

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 ?

like image 722
Jonathan Avatar asked Mar 30 '12 17:03

Jonathan


1 Answers

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

like image 143
meze Avatar answered Sep 17 '22 13:09

meze