1- #$Id: actions.py,v 1.40.2.9 2006-01-13 03:34:34 richard Exp $
1+ #$Id: actions.py,v 1.40.2.10 2006-01-20 02:13:51 richard Exp $
22
33import re , cgi , StringIO , urllib , Cookie , time , random , csv
44
@@ -124,6 +124,11 @@ def handle(self):
124124 self ._ ('%(classname)s %(itemid)s has been retired' )% {
125125 'classname' : self .classname .capitalize (), 'itemid' : nodeid })
126126
127+ def hasPermission (self , permission , classname = Action ._marker , itemid = None ):
128+ if itemid is None :
129+ itemid = self .nodeid
130+ return self .hasPermission (permission , classname , itemid )
131+
127132class SearchAction (Action ):
128133 name = 'search'
129134 permissionType = 'View'
@@ -435,7 +440,7 @@ def _editnodes(self, all_props, all_links):
435440 def _changenode (self , cn , nodeid , props ):
436441 """Change the node based on the contents of the form."""
437442 # check for permission
438- if not self .editItemPermission (props ):
443+ if not self .editItemPermission (props , classname = cn , itemid = nodeid ):
439444 raise exceptions .Unauthorised , self ._ (
440445 'You do not have permission to edit %(class)s'
441446 ) % {'class' : cn }
@@ -447,7 +452,7 @@ def _changenode(self, cn, nodeid, props):
447452 def _createnode (self , cn , props ):
448453 """Create a node based on the contents of the form."""
449454 # check for permission
450- if not self .newItemPermission (props ):
455+ if not self .newItemPermission (props , classname = cn ):
451456 raise exceptions .Unauthorised , self ._ (
452457 'You do not have permission to create %(class)s'
453458 ) % {'class' : cn }
@@ -461,7 +466,8 @@ def isEditingSelf(self):
461466 return (self .nodeid == self .userid
462467 and self .db .user .get (self .nodeid , 'username' ) != 'anonymous' )
463468
464- def editItemPermission (self , props ):
469+ _cn_marker = []
470+ def editItemPermission (self , props , classname = _cn_marker , itemid = None ):
465471 """Determine whether the user has permission to edit this item.
466472
467473 Base behaviour is to check the user can edit this class. If we're
@@ -475,17 +481,23 @@ def editItemPermission(self, props):
475481 "You do not have permission to edit user roles" )
476482 if self .isEditingSelf ():
477483 return 1
478- if self .hasPermission ('Edit' , itemid = self .nodeid ):
484+ if itemid is None :
485+ itemid = self .nodeid
486+ if classname is self ._cn_marker :
487+ classname = self .classname
488+ if self .hasPermission ('Edit' , itemid = itemid , classname = classname ):
479489 return 1
480490 return 0
481491
482- def newItemPermission (self , props ):
492+ def newItemPermission (self , props , classname = None ):
483493 """Determine whether the user has permission to create this item.
484494
485495 Base behaviour is to check the user can edit this class. No additional
486496 property checks are made.
487497 """
488- return self .hasPermission ('Create' )
498+ if not classname :
499+ classname = self .client .classname
500+ return self .hasPermission ('Create' , classname = classname )
489501
490502class EditItemAction (EditCommon ):
491503 def lastUserActivity (self ):
0 commit comments