[Zope] RE: What method do I use to check access? (and how do I do 'getitem' in an external method?)

Howard Clinton Shaw III shawh@sths.org
Tue, 8 Jun 1999 14:32:29 -0500


On Mon, 07 Jun 1999, Jay, Dylan wrote:
<snip>
> 
> Ok, I'm still working on the problem. I've come upon a snag however. If I
> pass in SomeObject above I will get an "You are not authorized to access
> SomeObject" error. So instead I need to pass in the object id and get the
> object myself. However I have had no luck working out how to do this. What I
> need is the getitem method in an external method. Searching through all the
> code as left me none the wiser.
> 
> Here's the closest I have.
> 
> from AccessControl.Permission import Permission
> 
> def hasPermission(self, pname, objName, AUTHENTICATED_USER):
>   SomeObject = self.__getitem__(objName)

try this.
SomeObject = eval('self.'+pname)

However, indications from the above are that it might give an error; if so, can be
much easier....
try:
	SomeObject = eval('self.'+pname)
except:
	# He ain't allowed to do that
else:
	# He is allowed to do that

And not have to fight with any permissions stuff.

>   P = Permission(pname,'',SomeObject)
>   P.obj=SomeObject
>   for i in AUTHENTICATED_USER.getRoles():
>     if i in P.getRoles():
>       return 1
--
Howard Clinton Shaw III - Grum
St. Thomas High School
#include "disclaimer.h"