Howto use has_permission (was RE: [Zope] How to test for a user h aving a permission?)
Maybe I'm being dumb, but this doesn't work for me: This doesn't work at all: <dtml-if "AUTHENTICATED_USER.has_permission('View',subfolder)"> <dtml-if "AUTHENTICATED_USER.has_permission('Access contents information',subfolder)"> This always returns false: <dtml-if "AUTHENTICATED_USER.has_permission('View','subfolder')"> <dtml-if "AUTHENTICATED_USER.has_permission('Access contents information','subfolder')"> How do I use this? Regards, Phil +----------------------------------+ | Phil Mayers, Network Support | | Centre for Computing Services | | Imperial College | +----------------------------------+ -----Original Message----- From: Hamish Lawson [mailto:hamish_lawson@yahoo.co.uk] Sent: 15 March 2001 00:06 To: Dieter Maurer; Tim Cook Cc: zope@zope.org Subject: Re: [Zope] How to test for a user having a permission? Tim Cook wrote:
<dtml-if expr="AUTHENTICATED_USER.has_permission('Edit','PARENTS[0]')"> <a href="<dtml-var absolute_url>/manage_main">Edit</a> </dtml-if>
Thanks. Brian Lloyd also mentioned has_permission() in reply to my post on the (mis)use of hasRole(). Dieter Maurer wrote:
Look in the embedded Online Help system -> API reference -> User
I'd already had a look in the online help, but there's no section for User (at least in my Zope installation), and the section for AuthenticatedUser doesn't list has_permission() - perhaps it ought to. I will concede, though, that I could easily enough have done a grep through the Zope source for the likely candidates, "def hasPermission" or "def has_permission" <sheepish grin>. Hamish Lawson ____________________________________________________________ Do You Yahoo!? Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk or your free @yahoo.ie address at http://mail.yahoo.ie _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
"Mayers, Philip J" wrote:
Maybe I'm being dumb, but this doesn't work for me:
This doesn't work at all: <dtml-if "AUTHENTICATED_USER.has_permission('View',subfolder)"> <dtml-if "AUTHENTICATED_USER.has_permission('Access contents information',subfolder)">
This always returns false: <dtml-if "AUTHENTICATED_USER.has_permission('View','subfolder')"> <dtml-if "AUTHENTICATED_USER.has_permission('Access contents information','subfolder')">
How do I use this?
I'll venture a guess that you are wanting to test a level below where you are actually attempting to use this method? It works (for me) by calling it from with the document/folder that I want to check the permission on. I use a method let's call it can_edit. It could be located in the root. It contains the code I posted before. Wherever I want to put the Edit link on the page I call that method <dtml-var can_edit>. It operates in the context of the calling document/folder because of the PARENTS[0]. I'm not sure you can make it work on an object that is not in the aquisition path? HTH, -- Tim Cook, President - FreePM,Inc. http://www.FreePM.com Office: (901) 884-4126 ONLINE DEMO: http://www.freepm.org:8080/FreePM
participants (2)
-
Mayers, Philip J -
Tim Cook