parameters: (self, ob, **kw)
return_statement: return changed
docstring: Changes the object permissions according to the current
      state.
docstring_summary: Changes the object permissions according to the current
      state.
docstring_tokens: Changes the object permissions according to the current state .
function: def updateRoleMappingsFor(self, ob, **kw):
      # Patch updateRoleMappingsFor so that if 2 workflows define security, then
      # we should do an AND operation between each roles list for a given
      # permission
      # XXX(WORKFLOW): this is not tested: add a test with multiple workflows
      # defining different permissions
      """
      Changes the object permissions according to the current
      state.
      """
      changed = False
      state = self._getWorkflowStateOf(ob)
      tool = aq_parent(aq_inner(self))
      other_data_list = []
      new_permission_roles_dict = {}
  
      def modifyRolesForPermissionDict(ob, new_permission_roles_dict):
        """
        Copied and modified version of modifyRolesForPermission
        (Products.DCWorkflow.utils) to pass a dict as parameter and avoid multiple
        expensive calls to ac_inherited_permissions.
  
        Modifies multiple role to permission mappings.  roles is a list to
        acquire, a tuple to not acquire.
        """
        modified = False
        def ac_all_inherited_permissions_dict(ob):
          # Get all permissions not defined in ourself that are inherited
          # This will be a sequence of tuples with a name as the first item and
          # an empty tuple as the second.
          permission_roles_tuple_list = getattr(ob, '__ac_permissions__', ())
          # permission_roles_tuple_list: [(permission1, (roleA, roleB)), ...]
          permission_roles_dict = {p[0]: p[1] for p in permission_roles_tuple_list}
          def gather_permission_dict(klass, result):
            for base in klass.__bases__:
              if '__ac_permissions__' in base.__dict__:
                for p in base.__ac_permissions__:
                  name=p[0]
                  if name in result:
                    continue
                  result[name] = ()
              gather_permission_dict(base, result)
            return result
          permission_roles_dict = gather_permission_dict(ob.__class__, permission_roles_dict)
          if hasattr(ob, '_subobject_permissions'):
            for p in ob._subobject_permissions():
              permission_name=p[0]
              roles = p[1]
              if not permission_roles_dict.has_key(permission_name):
                permission_roles_dict[permission_name] = roles
          return permission_roles_dict
        inherited_permission_dict = ac_all_inherited_permissions_dict(ob)
        for name, new_roles in new_permission_roles_dict.iteritems():
          old_roles = inherited_permission_dict.get(name, ())
          p = Permission(name, old_roles, ob)
          old_roles = p.getRoles()
          if type(old_roles) != type(new_roles) or sorted(old_roles) != sorted(new_roles):
            p.setRoles(new_roles)
            modified = True
        return modified
  
      # Be careful, permissions_roles should not change from list to tuple or
      # vice-versa (in modifyRolesForPermission, list means acquire roles, tuple
      # means do not acquire)
      if state is not None and self.getWorkflowManagedPermissionList():
        # apply expensive operations out of the loop (see below), for the other
        # workflow associated to object ob
        for other_workflow in tool.getWorkflowValueListFor(ob):
          other_workflow_type = other_workflow.getPortalType()
          if other_workflow.getId() == self.getId() or other_workflow_type not in \
          ('DCWorkflowDefinition', 'Workflow'):
            continue
          other_state = other_workflow._getWorkflowStateOf(ob)
          if other_state is not None:
            other_state_permission_role_list_dict = other_state.getStatePermissionRoleListDict()
            if other_state_permission_role_list_dict:
              other_data_list.append(
                (other_workflow, other_state, other_state_permission_role_list_dict,)
              )
  
        # take care of the current state of ob for this workflow (self)
        state_permission_role_list_dict = state.getStatePermissionRoleListDict()
        acquired_permission_list = state.getAcquirePermissionList()
        for permission in self.getWorkflowManagedPermissionList():
          default_roles = []
          role_type = list
          other_role_type_list = []
          if state_permission_role_list_dict:
            roles = state_permission_role_list_dict.get(permission, default_roles)
            # store acquisition settings
            if acquired_permission_list is _marker or roles is default_roles:
              role_type = type(roles)
            else:
              role_type = list if permission in acquired_permission_list else tuple
  
            roles = set(roles)
            # in every other workflow activated on the current object, get the
            # roles associated to permission; in case of role defined
            for (other_workflow, other_state, other_state_permission_role_list_dict) \
            in other_data_list:
              other_acquired_permission_list = other_state.getAcquirePermissionList()
              if permission in other_workflow.getWorkflowManagedPermissionList():
                other_roles = other_state_permission_role_list_dict.get(permission, default_roles)
                if other_acquired_permission_list is _marker: # compatibility with DCWorkflow
                  other_role_type_list.append(type(other_roles))
                else: # ERP5 workflows
                  other_role_type_list.append(
                    list if (other_roles is default_roles or permission in
                    other_acquired_permission_list) else tuple
                  )
                # get the common values between the roles set and the other
                # workflows roles for the same permission
                roles = roles.intersection(other_roles)
  
            roles = sorted(roles)
            if role_type is tuple and list not in other_role_type_list:
              # at least, one of other workflows manage security and for all are
              # role_type are tuple (= no role acquisition for this permission)
              roles = tuple(roles)
  
            new_permission_roles_dict[permission] = roles
        changed = modifyRolesForPermissionDict(ob, new_permission_roles_dict)
      return changed
function_tokens: def updateRoleMappingsFor ( self , ob , * * kw ) : # Patch updateRoleMappingsFor so that if 2 workflows define security, then # we should do an AND operation between each roles list for a given # permission # XXX(WORKFLOW): this is not tested: add a test with multiple workflows # defining different permissions changed = False state = self . _getWorkflowStateOf ( ob ) tool = aq_parent ( aq_inner ( self ) ) other_data_list = [ ] new_permission_roles_dict = { } def modifyRolesForPermissionDict ( ob , new_permission_roles_dict ) : """
        Copied and modified version of modifyRolesForPermission
        (Products.DCWorkflow.utils) to pass a dict as parameter and avoid multiple
        expensive calls to ac_inherited_permissions.
  
        Modifies multiple role to permission mappings.  roles is a list to
        acquire, a tuple to not acquire.
        """ modified = False def ac_all_inherited_permissions_dict ( ob ) : # Get all permissions not defined in ourself that are inherited # This will be a sequence of tuples with a name as the first item and # an empty tuple as the second. permission_roles_tuple_list = getattr ( ob , '__ac_permissions__' , ( ) ) # permission_roles_tuple_list: [(permission1, (roleA, roleB)), ...] permission_roles_dict = { p [ 0 ] : p [ 1 ] for p in permission_roles_tuple_list } def gather_permission_dict ( klass , result ) : for base in klass . __bases__ : if '__ac_permissions__' in base . __dict__ : for p in base . __ac_permissions__ : name = p [ 0 ] if name in result : continue result [ name ] = ( ) gather_permission_dict ( base , result ) return result permission_roles_dict = gather_permission_dict ( ob . __class__ , permission_roles_dict ) if hasattr ( ob , '_subobject_permissions' ) : for p in ob . _subobject_permissions ( ) : permission_name = p [ 0 ] roles = p [ 1 ] if not permission_roles_dict . has_key ( permission_name ) : permission_roles_dict [ permission_name ] = roles return permission_roles_dict inherited_permission_dict = ac_all_inherited_permissions_dict ( ob ) for name , new_roles in new_permission_roles_dict . iteritems ( ) : old_roles = inherited_permission_dict . get ( name , ( ) ) p = Permission ( name , old_roles , ob ) old_roles = p . getRoles ( ) if type ( old_roles ) != type ( new_roles ) or sorted ( old_roles ) != sorted ( new_roles ) : p . setRoles ( new_roles ) modified = True return modified # Be careful, permissions_roles should not change from list to tuple or # vice-versa (in modifyRolesForPermission, list means acquire roles, tuple # means do not acquire) if state is not None and self . getWorkflowManagedPermissionList ( ) : # apply expensive operations out of the loop (see below), for the other # workflow associated to object ob for other_workflow in tool . getWorkflowValueListFor ( ob ) : other_workflow_type = other_workflow . getPortalType ( ) if other_workflow . getId ( ) == self . getId ( ) or other_workflow_type not in ( 'DCWorkflowDefinition' , 'Workflow' ) : continue other_state = other_workflow . _getWorkflowStateOf ( ob ) if other_state is not None : other_state_permission_role_list_dict = other_state . getStatePermissionRoleListDict ( ) if other_state_permission_role_list_dict : other_data_list . append ( ( other_workflow , other_state , other_state_permission_role_list_dict , ) ) # take care of the current state of ob for this workflow (self) state_permission_role_list_dict = state . getStatePermissionRoleListDict ( ) acquired_permission_list = state . getAcquirePermissionList ( ) for permission in self . getWorkflowManagedPermissionList ( ) : default_roles = [ ] role_type = list other_role_type_list = [ ] if state_permission_role_list_dict : roles = state_permission_role_list_dict . get ( permission , default_roles ) # store acquisition settings if acquired_permission_list is _marker or roles is default_roles : role_type = type ( roles ) else : role_type = list if permission in acquired_permission_list else tuple roles = set ( roles ) # in every other workflow activated on the current object, get the # roles associated to permission; in case of role defined for ( other_workflow , other_state , other_state_permission_role_list_dict ) in other_data_list : other_acquired_permission_list = other_state . getAcquirePermissionList ( ) if permission in other_workflow . getWorkflowManagedPermissionList ( ) : other_roles = other_state_permission_role_list_dict . get ( permission , default_roles ) if other_acquired_permission_list is _marker : # compatibility with DCWorkflow other_role_type_list . append ( type ( other_roles ) ) else : # ERP5 workflows other_role_type_list . append ( list if ( other_roles is default_roles or permission in other_acquired_permission_list ) else tuple ) # get the common values between the roles set and the other # workflows roles for the same permission roles = roles . intersection ( other_roles ) roles = sorted ( roles ) if role_type is tuple and list not in other_role_type_list : # at least, one of other workflows manage security and for all are # role_type are tuple (= no role acquisition for this permission) roles = tuple ( roles ) new_permission_roles_dict [ permission ] = roles changed = modifyRolesForPermissionDict ( ob , new_permission_roles_dict ) return changed