[gen] added obj.mayEdit, an additional condition for editing an object (similar to mayDelete); bugfix: specifying a workflow for a User class crashed because, in installer.py, Appy took into account the standard workflow on this Class instead of the custom one.

This commit is contained in:
Gaetan Delannay 2012-06-01 15:57:19 +02:00
parent e3b7f5364f
commit 0d7afb685f
9 changed files with 49 additions and 25 deletions

View file

@ -992,14 +992,17 @@ class ToolMixin(BaseMixin):
elem is the one-line user info as shown on every page; second line is
the URL to edit user info.'''
appyUser = self.appy().appyUser
res = [appyUser.title]
info = [appyUser.title]
rolesToShow = [r for r in appyUser.roles \
if r not in ('Authenticated', 'Member')]
if rolesToShow:
res.append(', '.join([self.translate('role_%s'%r) \
for r in rolesToShow]))
return (' | '.join(res), appyUser.o.getUrl(mode='edit', page='main',
nav=''))
info.append(', '.join([self.translate('role_%s'%r) \
for r in rolesToShow]))
# Edit URL for the appy user.
url = None
if appyUser.o.mayEdit():
url = appyUser.o.getUrl(mode='edit', page='main', nav='')
return (' | '.join(info), url)
def generateUid(self, className):
'''Generates a UID for an instance of p_className.'''

View file

@ -879,12 +879,10 @@ class BaseMixin:
'''Returns the workflow applicable for p_self (or for any instance of
p_className if given), or its name, if p_name is True.'''
if not className:
appyClass = self.wrapperClass.__bases__[-1]
wrapperClass = self.wrapperClass
else:
appyClass = self.getTool().getAppyClass(className)
if hasattr(appyClass, 'workflow'): wf = appyClass.workflow
else:
wf = gen.WorkflowAnonymous
wrapperClass = self.getTool().getAppyClass(className, wrapper=True)
wf = wrapperClass.getWorkflow()
if not name: return wf
return WorkflowDescriptor.getWorkflowName(wf)
@ -957,13 +955,23 @@ class BaseMixin:
return True
def mayDelete(self):
'''May the currently logged user delete this object? This condition
comes as an addition/refinement to the corresponding workflow
permission.'''
'''May the currently logged user delete this object?.'''
res = self.allows('Delete objects')
if not res: return
# An additional, user-defined condition, may refine the base permission.
appyObj = self.appy()
if hasattr(appyObj, 'mayDelete'): return appyObj.mayDelete()
return True
def mayEdit(self):
'''May the currently logged user edit this object?.'''
res = self.allows('Modify portal content')
if not res: return
# An additional, user-defined condition, may refine the base permission.
appyObj = self.appy()
if hasattr(appyObj, 'mayEdit'): return appyObj.mayEdit()
return True
def executeAppyAction(self, actionName, reindex=True):
'''Executes action with p_fieldName on this object.'''
appyType = self.getAppyType(actionName)