app/soc/logic/models/request.py
changeset 3047 cdc652533fcc
parent 2678 a525a55833f1
equal deleted inserted replaced
3046:cd08e035ac9e 3047:cdc652533fcc
    32 class Logic(base.Logic):
    32 class Logic(base.Logic):
    33   """Logic methods for the Request model.
    33   """Logic methods for the Request model.
    34   """
    34   """
    35 
    35 
    36   def __init__(self, model=soc.models.request.Request,
    36   def __init__(self, model=soc.models.request.Request,
    37                base_model=None, scope_logic=linkable_logic):
    37                base_model=None, id_based=True):
    38     """Defines the name, key_name and model for this entity.
    38     """Defines the name, key_name and model for this entity.
    39     """
    39     """
    40 
    40 
    41     super(Logic, self).__init__(model, base_model=base_model,
    41     super(Logic, self).__init__(model, base_model=base_model,
    42                                 scope_logic=scope_logic)
    42                                 id_based=id_based)
    43 
    43 
    44   def getKeyValuesFromEntity(self, entity):
    44   def isValidNewRequest(self, fields, role_logic):
    45     """See base.Logic.getKeyNameValues.
    45     """Returns True iff the given fields are for a valid new request.
       
    46 
       
    47     Args:
       
    48       fields: fields for the new Request
       
    49       logic: the Logic for the Role that is being requested
    46     """
    50     """
    47 
    51 
    48     return [entity.scope.link_id, entity.role, entity.link_id]
    52     # check for already outstanding or ignored requests
       
    53     request_fields = {
       
    54         'user': fields['user'],
       
    55         'group': fields['group'],
       
    56         'status': ['new', 'group_accepted', 'ignored']
       
    57         }
    49 
    58 
    50   def getKeyValuesFromFields(self, fields):
    59     request_entity = self.getForFields(request_fields, unique=True)
    51     """See base.Logic.getKeyValuesFromFields.
       
    52     """
       
    53 
    60 
    54     return [fields['scope_path'], fields['role'], fields['link_id']]
    61     if request_entity:
       
    62       return False
    55 
    63 
    56   def getKeyFieldNames(self):
    64     # check whether the user in the request already has the requested role
    57     """See base.Logic.getKeyFieldNames.
    65     role_fields = {
    58     """
    66         'user': fields['user'],
       
    67         'scope': fields['group'],
       
    68         'status': ['active', 'inactive']
       
    69         }
    59 
    70 
    60     return ['scope_path', 'role', 'link_id']
    71     role_entity = role_logic.getForFields(role_fields, unique=True)
       
    72 
       
    73     if role_entity:
       
    74       return False
       
    75 
       
    76     # seems to be a valid new request, so return True
       
    77     return True
    61 
    78 
    62   def _onCreate(self, entity):
    79   def _onCreate(self, entity):
    63     """Sends out a message notifying users about the new invite/request.
    80     """Sends out a message notifying users about the new invite/request.
    64     """
    81     """
    65 
    82