JMSSecurityExtraBundle icon indicating copy to clipboard operation
JMSSecurityExtraBundle copied to clipboard

Bug in is_expr_granted

Open ioleo opened this issue 10 years ago • 0 comments

Hi,

I've got this function in my controller:

<?php
/* use annotations to mark Route and Template */
public function myCustomAction()
{
    // fetch my object
    $myObject = $this->getDoctrine()->getRepository('someRepo')->find('somePK');

    // this returns true
    $test1 = $this->get('security.context')->isGranted(
        array(new Expression('canEdit(object)')), 
        $myObject
    );

    return array(
        'test1' => $test1,
        'myObject' => $myObject
    );
}

But when I try to evaluate the same expression in twig template I'm getting diffrent resuts:

{% set test2 = is_expr_granted("canEdit(object)", myObject) %}

test1 (controller): {{ test1 ? 'true' : 'false' }}<br />
test2 (view): {{ test2 ? 'true' : 'false' }}

The result is:

test1 (controller): true
test2 (view): false

Why? The canEdit is a method in by custom expression evaluator class with a simple check if user has ROLE_X.

ioleo avatar Sep 27 '13 17:09 ioleo