This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » eZ Publish 5 Platform » Check if user has can_edit in template?
expandshrink

Check if user has can_edit in template?

Check if user has can_edit in template?

Wednesday 11 February 2015 4:32:05 pm - 5 replies

in the past you could use {section show=$Nodes.item.can_edit}

on ezp5 how can I use is_granted to accomplish the same thing?
I know how to do it in php but that requires  $this->isGranted(new AuthorizationAttribute('xyz','xyz')).

Thursday 12 February 2015 9:57:30 am

Hi!

I couldn't find a simple way to do this in Twig (I didn't spend too much time searching though), so I created a simple Twig extension: https://gist.github.com/stianmartinsen/d3de309f975c0940fa97

Hope you'll find it somewhat useful! happy.gif Emoticon

Thursday 12 February 2015 2:28:49 pm

This looks better to me then having to create custom controllers to do the checks.  Thank you for sharing.

Saturday 14 March 2015 2:02:36 pm

Hello,

my guts tell me that you should really at the very least fetch this info from the controller (just override it with your own), test permissions from here, and assign them to template variables.

What's your use-case here ? Maybe there is a different way to solve this. Nonetheless, it is clear that we haven't dedicated much thinking to write permissions check from twig, as we don't use any yet. Perfect time to describe what you'd like to do blunk.gif Emoticon

Saturday 14 March 2015 2:40:23 pm

I have a view that returns a list of content.

In the list if the user has edit permissions there is a link beside it to allow them to edit it. If they on have view permissions they are not presented with the edit option.

I believe in this simple case the template should be able to tell if the user has this permission.

Saturday 14 March 2015 2:47:14 pm

I see.

Well, the Twig helper isn't a bad approach. I guess you could argue about permissions checking from the view layer, but we have seen worse violations happy.gif Emoticon

I'd be curious to know what others think.

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from