def updateRoleMappingsFor(self, ob): """Changes the object permissions according to the current state. """ changed = 0 sdef = self._getWorkflowStateOf(ob) if sdef is None: return 0 # Update the role -> permission map. if self.permissions: for p in self.permissions: roles = [] if sdef.permission_roles is not None: roles = sdef.permission_roles.get(p, roles) if modifyRolesForPermission(ob, p, roles): changed = 1 # Update the group -> role map. groups = self.getGroups() managed_roles = self.getRoles() if groups and managed_roles: for group in groups: roles = () if sdef.group_roles is not None: roles = sdef.group_roles.get(group, ()) if modifyRolesForGroup(ob, group, roles, managed_roles): changed = 1 return changed
def testModifyRolesForGroup(self): modifyRolesForGroup(self.ob, '(Group) Administrators', ['Owner'], ['Member', 'Owner']) modifyRolesForGroup(self.ob, '(Group) Users', [], ['Member']) self.assertEqual(self.ob.__ac_local_roles__, { '(Group) Administrators': ['Manager', 'Owner'], }) modifyRolesForGroup(self.ob, '(Group) Administrators', ['Member'], ['Member', 'Owner']) modifyRolesForGroup(self.ob, '(Group) Users', ['Member'], ['Member']) self.assertEqual( self.ob.__ac_local_roles__, { '(Group) Administrators': ['Manager', 'Member'], '(Group) Users': ['Member'], })
def testModifyRolesForGroup(self): modifyRolesForGroup( self.ob, '(Group) Administrators', ['Owner'], ['Member', 'Owner']) modifyRolesForGroup( self.ob, '(Group) Users', [], ['Member']) self.assertEqual(self.ob.__ac_local_roles__, { '(Group) Administrators': ['Manager', 'Owner'], }) modifyRolesForGroup( self.ob, '(Group) Administrators', ['Member'], ['Member', 'Owner']) modifyRolesForGroup( self.ob, '(Group) Users', ['Member'], ['Member']) self.assertEqual(self.ob.__ac_local_roles__, { '(Group) Administrators': ['Manager', 'Member'], '(Group) Users': ['Member'], })
def updateRoleMappingsFor(self, obj): """Changes the objject permissions according to the current state. """ # Delay if we are executing a transition - the event handler will # do the work. if getattr(self, '_v_executing_transition', False): self._v_executing_transition = False # XXX: May not be right return True changed = False state = self._getWorkflowStateOf(obj) if state is None: return False # Update roles/permission mappings if self.permissions: for p in self.permissions: roles = [] if state.permission_roles is not None: roles = state.permission_roles.get(p, roles) if modifyRolesForPermission(obj, p, roles): changed = 1 # Update the group/local role mappings groups = self.getGroups() managed_roles = self.getRoles() if groups and managed_roles: for group in groups: roles = () if state.group_roles is not None: roles = state.group_roles.get(group, ()) if modifyRolesForGroup(obj, group, roles, managed_roles): changed = True return changed