JMSSecurityExtraBundle icon indicating copy to clipboard operation
JMSSecurityExtraBundle copied to clipboard

Extension of is_expr_granted

Open alsar opened this issue 12 years ago • 2 comments

I wrote my own expression function, which expects two objects as parameters. But currently it is only possible to pass one object to the is_expr_granted method in Twig templates.

Would it be possible to extend the function to make this work?

alsar avatar Dec 11 '12 20:12 alsar

Could you describe the use-case a bit?

schmittjoh avatar Dec 11 '12 20:12 schmittjoh

I was playing a little bit with the SecurityExtraBundle and found out, that I really don't need to pass two objects.

Here is what I basically wanted to do in the first place. I had a function which expected two arguments, like this:

/**
 * @Service()
 */
class ApplicationFormExpressionEvaluator
{
    /**
     * @SecurityFunction("mayEditApplicationForm")
     */
    public function mayEditApplicationForm(AbstractApplicationForm $applicationForm, User $user)
...

That's why I wanted to pass the $applicationForm object and the $user object as arguments to the is_expr_granted function. But then I discovered that I can do this in my template like this:

is_expr_granted("mayEditApplicationForm(object, token.getUser())", applicationForm)

In this situation I really just need to pass the applicationForm object as an argument. I took this even further and dropped the $user object from the expression function and rather injected the security context directly into the ApplicationFormExpressionEvaluator service. So at the end i ended up with like this:

is_expr_granted("mayEditApplicationForm(object)", applicationForm)

So I don't know really if there is a use case with two objects as parameters. :) If you think the question is still relevant, and we could find a use case, we can discuss this further, otherwise just close the issue.

alsar avatar Dec 13 '12 00:12 alsar