Commit a453f33a authored by Julien Muchembled's avatar Julien Muchembled

Display permissions on workflow states for used roles on the workflow.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25617 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 507767e1
...@@ -32,26 +32,15 @@ from DocumentationHelper import DocumentationHelper ...@@ -32,26 +32,15 @@ from DocumentationHelper import DocumentationHelper
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.DCWorkflowGraph.DCWorkflowGraph import getGraph from Products.DCWorkflowGraph.DCWorkflowGraph import getGraph
def getStatePermissionsOfRole(state, role):
""" def getRoleList(workflow):
Returns list of permissions for a given role with AVMC format above role_set = set()
A = Access contents information for state in workflow.states.objectValues():
V = View if state.permission_roles:
M = Modify Portal Content for role_list in state.permission_roles.itervalues():
C = Add Portal Content role_set.update(role_list)
""" return sorted(role_set)
permissions = ""
permission_roles = state.permission_roles
if permission_roles:
if role in permission_roles.get('Access contents information', ()):
permissions += "A"
if role in permission_roles.get('View', ()):
permissions += "V"
if role in permission_roles.get('Modify portal content', ()):
permissions += "M"
if role in permission_roles.get('Add portal content', ()):
permissions += "C"
return permissions
class DCWorkflowDocumentationHelper(DocumentationHelper): class DCWorkflowDocumentationHelper(DocumentationHelper):
""" """
...@@ -97,55 +86,28 @@ class DCWorkflowDocumentationHelper(DocumentationHelper): ...@@ -97,55 +86,28 @@ class DCWorkflowDocumentationHelper(DocumentationHelper):
""" """
return "DC Workflow" return "DC Workflow"
# Specific methods security.declareProtected(Permissions.AccessContentsInformation, 'getRoleColumnList')
security.declareProtected(Permissions.AccessContentsInformation, 'getStateIdList') def getRoleColumnList(self):
def getStateIdList(self): """Return the list of pertinent columns for permissions on states."""
""" return [(role.lower().replace(' ', '_') + '_permissions', role)
""" for role in getRoleList(self.getDocumentedObject())]
state_list = []
states = getattr(self.getDocumentedObject(), 'states', None)
if states is not None:
for state in states.objectValues():
state_list.append(state.getId())
return state_list
security.declareProtected(Permissions.AccessContentsInformation, 'getStateItemList')
def getStateItemList(self):
"""
"""
state_list = []
states = getattr(self.getDocumentedObject(), 'states', None)
if states is not None:
for state in states.objectValues():
state_list.append((getattr(state, "id", ""),
getattr(state, "title", ""),
getStatePermissionsOfRole(state, 'Owner'),
getStatePermissionsOfRole(state, 'Assignor'),
getStatePermissionsOfRole(state, 'Assignee'),
getStatePermissionsOfRole(state, 'Associate'),
getStatePermissionsOfRole(state, 'Author'),
getStatePermissionsOfRole(state, 'Auditor')
))
return state_list
security.declareProtected(Permissions.AccessContentsInformation, 'getStateUriList')
def getStateUriList(self): def getStateUriList(self):
""" return ['%s/states#%s' % (self.uri, state)
""" for state in sorted(self.getDocumentedObject().states.objectIds())]
state_id_list = self.getStateIdList()
return map(lambda x: ('%s/states/%s' % (self.uri, x)), state_id_list)
security.declareProtected(Permissions.AccessContentsInformation, 'getStateURIList') security.declareProtected(Permissions.AccessContentsInformation, 'getStateItemList')
def getStateURIList(self): def getStateItemList(self, **kw):
""" """
""" """
state_item_list = self.getStateItemList() item_list = []
klass = self.getDocumentedObject().__class__ role_column_list = self.getRoleColumnList()
class_name = klass.__name__ for uri in self.getStateUriList():
module = klass.__module__ helper = self.getDocumentationHelper('DCWorkflowStateDocumentationHelper', uri)
uri_prefix = '%s.%s.' % (module, class_name) for column_id, role in role_column_list:
return map(lambda x: ('%s%s' % (uri_prefix, x[0]), x[1], x[2], x[3], x[4], x[5], x[6], x[7]), state_item_list) setattr(helper, column_id, helper.getPermissionsOfRole(role))
item_list.append(helper)
return item_list
security.declareProtected(Permissions.AccessContentsInformation, 'getTransitionIdList') security.declareProtected(Permissions.AccessContentsInformation, 'getTransitionIdList')
def getTransitionIdList(self): def getTransitionIdList(self):
...@@ -278,7 +240,6 @@ class DCWorkflowDocumentationHelper(DocumentationHelper): ...@@ -278,7 +240,6 @@ class DCWorkflowDocumentationHelper(DocumentationHelper):
worklist_list.append((wl.__name__, title, wl.__dict__["description"],guard_roles)) worklist_list.append((wl.__name__, title, wl.__dict__["description"],guard_roles))
return worklist_list return worklist_list
security.declareProtected(Permissions.AccessContentsInformation, 'getWorklistURIList') security.declareProtected(Permissions.AccessContentsInformation, 'getWorklistURIList')
def getWorklistURIList(self): def getWorklistURIList(self):
""" """
...@@ -321,7 +282,6 @@ class DCWorkflowDocumentationHelper(DocumentationHelper): ...@@ -321,7 +282,6 @@ class DCWorkflowDocumentationHelper(DocumentationHelper):
)) ))
return script_list return script_list
security.declareProtected(Permissions.AccessContentsInformation, 'getScriptURIList') security.declareProtected(Permissions.AccessContentsInformation, 'getScriptURIList')
def getScriptURIList(self): def getScriptURIList(self):
""" """
...@@ -347,7 +307,6 @@ class DCWorkflowDocumentationHelper(DocumentationHelper): ...@@ -347,7 +307,6 @@ class DCWorkflowDocumentationHelper(DocumentationHelper):
""" """
"" ""
security.declareProtected(Permissions.AccessContentsInformation, 'getGraphImageData') security.declareProtected(Permissions.AccessContentsInformation, 'getGraphImageData')
def getGraphImageData(self, format='png'): def getGraphImageData(self, format='png'):
""" """
...@@ -355,4 +314,5 @@ class DCWorkflowDocumentationHelper(DocumentationHelper): ...@@ -355,4 +314,5 @@ class DCWorkflowDocumentationHelper(DocumentationHelper):
""" """
return getGraph(self, wf_id=getattr(self.getDocumentedObject(), "__name__", ''), format=format) return getGraph(self, wf_id=getattr(self.getDocumentedObject(), "__name__", ''), format=format)
InitializeClass(DCWorkflowDocumentationHelper) InitializeClass(DCWorkflowDocumentationHelper)
...@@ -30,7 +30,7 @@ from AccessControl import ClassSecurityInfo ...@@ -30,7 +30,7 @@ from AccessControl import ClassSecurityInfo
from Globals import InitializeClass from Globals import InitializeClass
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from DocumentationHelper import DocumentationHelper from DocumentationHelper import DocumentationHelper
from DCWorkflowDocumentationHelper import getStatePermissionsOfRole from DCWorkflowDocumentationHelper import getRoleList
class DCWorkflowStateDocumentationHelper(DocumentationHelper): class DCWorkflowStateDocumentationHelper(DocumentationHelper):
""" """
...@@ -53,43 +53,38 @@ class DCWorkflowStateDocumentationHelper(DocumentationHelper): ...@@ -53,43 +53,38 @@ class DCWorkflowStateDocumentationHelper(DocumentationHelper):
""" """
return self.getDocumentedObject().transitions return self.getDocumentedObject().transitions
def getPermissionsOfRole(self, role): security.declareProtected(Permissions.AccessContentsInformation, 'getRoleList')
return getStatePermissionsOfRole(self.getDocumentedObject(), role) def getRoleList(self):
security.declareProtected(Permissions.AccessContentsInformation, 'getPermissionsOfRoleOwner')
def getPermissionsOfRoleOwner(self):
"""
"""
return self.getPermissionsOfRole('Owner')
security.declareProtected(Permissions.AccessContentsInformation, 'getPermissionsOfRoleAssignor')
def getPermissionsOfRoleAssignor(self):
"""
"""
return self.getPermissionsOfRole('Assignor')
security.declareProtected(Permissions.AccessContentsInformation, 'getPermissionsOfRoleAssignee')
def getPermissionsOfRoleAssignee(self):
""" """
""" """
return self.getPermissionsOfRole('Assignee') return getRoleList(self.getDocumentedObject().getWorkflow())
security.declareProtected(Permissions.AccessContentsInformation, 'getPermissionsOfRoleAssociate') security.declareProtected(Permissions.AccessContentsInformation, 'getPermissionsList')
def getPermissionsOfRoleAssociate(self): def getPermissionsList(self):
""" """
""" """
return self.getPermissionsOfRole('Associate') return map(self.getPermissionsOfRole, self.getRoleList())
security.declareProtected(Permissions.AccessContentsInformation, 'getPermissionsOfRoleAuthor') def getPermissionsOfRole(self, role):
def getPermissionsOfRoleAuthor(self):
"""
""" """
return self.getPermissionsOfRole('Author') Returns list of permissions for a given role with AVMC format above
A = Access contents information
V = View
M = Modify Portal Content
C = Add Portal Content
"""
permissions = ""
permission_roles = self.getDocumentedObject().permission_roles
if permission_roles:
if role in permission_roles.get('Access contents information', ()):
permissions += "A"
if role in permission_roles.get('View', ()):
permissions += "V"
if role in permission_roles.get('Modify portal content', ()):
permissions += "M"
if role in permission_roles.get('Add portal content', ()):
permissions += "C"
return permissions
security.declareProtected(Permissions.AccessContentsInformation, 'getPermissionsOfRoleAuditor')
def getPermissionsOfRoleAuditor(self):
"""
"""
return self.getPermissionsOfRole('Auditor')
InitializeClass(DCWorkflowStateDocumentationHelper) InitializeClass(DCWorkflowStateDocumentationHelper)
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# #
############################################################################## ##############################################################################
from urllib import quote
from Acquisition import Implicit, aq_base from Acquisition import Implicit, aq_base
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass from Globals import InitializeClass
...@@ -118,6 +119,13 @@ class DocumentationHelper(Implicit): ...@@ -118,6 +119,13 @@ class DocumentationHelper(Implicit):
def __init__(self, uri): def __init__(self, uri):
self.uri = uri self.uri = uri
security.declareProtected(Permissions.AccessContentsInformation, 'getViewUrl')
def getViewUrl(self, **kw):
"""
"""
return 'DocumentationHelper_viewDocumentationHelper?uri=%s&class_name=%s' \
% (quote(self.uri), self.__class__.__name__)
security.declareProtected(Permissions.AccessContentsInformation, 'getId') security.declareProtected(Permissions.AccessContentsInformation, 'getId')
def getId(self): def getId(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment