app/soc/logic/models/role.py
changeset 2664 06d4f4d06f64
parent 2072 eb4565a8e5b4
child 2672 7bc9d3b962af
equal deleted inserted replaced
2663:d270bd8b7417 2664:06d4f4d06f64
    31 
    31 
    32 DEF_LAST_RESIGN_ERROR_FMT = "This user can't be " \
    32 DEF_LAST_RESIGN_ERROR_FMT = "This user can't be " \
    33     "resigned, please make sure it's not the last %(name)s."
    33     "resigned, please make sure it's not the last %(name)s."
    34 
    34 
    35 
    35 
       
    36 ROLE_LOGICS = {}
       
    37 
       
    38 
       
    39 def registerRoleLogic(role_logic):
       
    40   """Adds the specified Role Logic to the known ones.
       
    41 
       
    42   Args:
       
    43     role_logic: Instance of or subclass from Role Logic
       
    44   """
       
    45 
       
    46   global ROLE_LOGICS
       
    47   name = role_logic.role_name
       
    48   ROLE_LOGICS[name] = role_logic
       
    49 
       
    50 
    36 class Logic(base.Logic):
    51 class Logic(base.Logic):
    37   """Logic methods for the Role model.
    52   """Logic methods for the Role model.
    38   """
    53   """
    39 
    54 
    40   def __init__(self, model=soc.models.role.Role,
    55   def __init__(self, model=soc.models.role.Role,
    41                base_model=None, scope_logic=None, disallow_last_resign=False):
    56                base_model=None, scope_logic=None, role_name=None,
       
    57                disallow_last_resign=False):
    42     """Defines the name, key_name and model for this entity.
    58     """Defines the name, key_name and model for this entity.
       
    59 
       
    60     Args:
       
    61       role_name: The name of this role used for instance for Requests
       
    62       dissallow_last_resign: Iff True and a given role entity is the last of
       
    63         its kind in its scope then this role can not be resigned.
    43     """
    64     """
    44 
    65 
    45     super(Logic, self).__init__(model, base_model=base_model,
    66     super(Logic, self).__init__(model, base_model=base_model,
    46                                 scope_logic=scope_logic)
    67                                 scope_logic=scope_logic)
       
    68 
       
    69     self.role_name = role_name
       
    70     registerRoleLogic(self)
    47 
    71 
    48     self.disallow_last_resign = disallow_last_resign
    72     self.disallow_last_resign = disallow_last_resign
    49 
    73 
    50 
    74 
    51   def getGroupEntityFromScopePath(self, group_logic, scope_path):
    75   def getGroupEntityFromScopePath(self, group_logic, scope_path):
    52     """Returns a group entity by using the given scope_path.
    76     """Returns a group entity by using the given scope_path.
    53     
    77 
    54     Args:
    78     Args:
    55       group_logic: logic for the group which should be retrieved
    79       group_logic: logic for the group which should be retrieved
    56       scope_path : the scope path of the entity
    80       scope_path : the scope path of the entity
    57     """
    81     """
    58     group_key_fields = scope_path.rsplit('/', 1)
    82     group_key_fields = scope_path.rsplit('/', 1)