app/soc/views/helper/access.py
changeset 1085 0afbdd0905ef
parent 1080 d533408811ba
child 1107 a878188e225c
equal deleted inserted replaced
1084:9c4221f7b747 1085:0afbdd0905ef
   422     raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
   422     raise out_of_band.LoginRequest(message_fmt=login_message_fmt)
   423 
   423 
   424   @allowDeveloper
   424   @allowDeveloper
   425   @denySidebar
   425   @denySidebar
   426   def checkIsGroupActive(self, django_args, group_logic):
   426   def checkIsGroupActive(self, django_args, group_logic):
   427     """Raises an alternate HTTP response if Group state is not active.
   427     """Raises an alternate HTTP response if Group status is not active.
   428 
   428 
   429     Args:
   429     Args:
   430       django_args: a dictionary with django's arguments
   430       django_args: a dictionary with django's arguments
   431 
   431 
   432     Raises:
   432     Raises:
   433       AccessViolationResponse:
   433       AccessViolationResponse:
   434       * if no Group is found
   434       * if no Group is found
   435       * if the Group state is not active
   435       * if the Group status is not active
   436     """
   436     """
   437 
   437 
   438     fields = {'link_id': django_args['link_id']}
   438     fields = {'link_id': django_args['link_id']}
   439 
   439 
   440     if django_args.get('scope_path'):
   440     if django_args.get('scope_path'):
   441       fields['scope_path'] = django_args['scope_path']
   441       fields['scope_path'] = django_args['scope_path']
   442 
   442 
   443     group_entity = group_logic.logic.getFromFieldsOr404(**fields)
   443     group_entity = group_logic.logic.getFromFieldsOr404(**fields)
   444 
   444 
   445     if group_entity.state == 'active':
   445     if group_entity.status == 'active':
   446       return
   446       return
   447 
   447 
   448     # TODO tell the user that this group is not active
   448     # TODO tell the user that this group is not active
   449     self.deny(django_args)
   449     self.deny(django_args)
   450 
   450 
   451 
   451 
   452   def checkCanMakeRequestToGroup(self, django_args, group_logic):
   452   def checkCanMakeRequestToGroup(self, django_args, group_logic):
   453     """Raises an alternate HTTP response if the specified group is not in an
   453     """Raises an alternate HTTP response if the specified group is not in an
   454     active state.
   454     active status.
   455 
   455 
   456     Note that state hasn't been implemented yet
   456     Note that status hasn't been implemented yet
   457 
   457 
   458     Args:
   458     Args:
   459       group_logic: Logic module for the type of group which the request is for
   459       group_logic: Logic module for the type of group which the request is for
   460     """
   460     """
   461 
   461 
   463         group_logic.logic, django_args['scope_path'])
   463         group_logic.logic, django_args['scope_path'])
   464 
   464 
   465     if not group_entity:
   465     if not group_entity:
   466       raise out_of_band.Error(DEF_GROUP_NOT_FOUND_MSG, status=404)
   466       raise out_of_band.Error(DEF_GROUP_NOT_FOUND_MSG, status=404)
   467 
   467 
   468     if group_entity.state != 'active':
   468     if group_entity.status != 'active':
   469       # TODO tell the user that this group is not active
   469       # TODO tell the user that this group is not active
   470       self.deny(django_args)
   470       self.deny(django_args)
   471 
   471 
   472     return
   472     return
   473 
   473 
   474   def checkCanCreateFromRequest(self, django_args, role_name):
   474   def checkCanCreateFromRequest(self, django_args, role_name):
   475     """Raises an alternate HTTP response if the specified request does not exist
   475     """Raises an alternate HTTP response if the specified request does not exist
   476        or if it's state is not group_accepted. Also when the group this request
   476        or if it's status is not group_accepted. Also when the group this request
   477        is from is in an inactive or invalid state access will be denied.
   477        is from is in an inactive or invalid status access will be denied.
   478     """
   478     """
   479 
   479 
   480     self.checkIsUser(django_args)
   480     self.checkIsUser(django_args)
   481 
   481 
   482     user_entity = user_logic.getForCurrentAccount()
   482     user_entity = user_logic.getForCurrentAccount()
   488         'scope_path': django_args['scope_path'],
   488         'scope_path': django_args['scope_path'],
   489         'role': role_name}
   489         'role': role_name}
   490 
   490 
   491     request_entity = request_logic.getFromFieldsOr404(**fields)
   491     request_entity = request_logic.getFromFieldsOr404(**fields)
   492 
   492 
   493     if request_entity.state != 'group_accepted':
   493     if request_entity.status != 'group_accepted':
   494       # TODO tell the user that this request has not been accepted yet
   494       # TODO tell the user that this request has not been accepted yet
   495       self.deny(django_args)
   495       self.deny(django_args)
   496 
   496 
   497     if request_entity.scope.state in ['invalid', 'inactive']:
   497     if request_entity.scope.status in ['invalid', 'inactive']:
   498       # TODO tell the user that it is not possible to create this role anymore
   498       # TODO tell the user that it is not possible to create this role anymore
   499       self.deny(django_args)
   499       self.deny(django_args)
   500 
   500 
   501     return
   501     return
   502 
   502 
   503   def checkCanProcessRequest(self, django_args, role_name):
   503   def checkCanProcessRequest(self, django_args, role_name):
   504     """Raises an alternate HTTP response if the specified request does not exist
   504     """Raises an alternate HTTP response if the specified request does not exist
   505        or if it's state is completed or denied. Also Raises an alternate HTTP response
   505        or if it's status is completed or denied. Also Raises an alternate HTTP response
   506        whenever the group in the request is not active.
   506        whenever the group in the request is not active.
   507     """
   507     """
   508 
   508 
   509     fields = {'link_id': django_args['link_id'],
   509     fields = {'link_id': django_args['link_id'],
   510         'scope_path': django_args['scope_path'],
   510         'scope_path': django_args['scope_path'],
   511         'role': role_name}
   511         'role': role_name}
   512 
   512 
   513     request_entity = request_logic.getFromFieldsOr404(**fields)
   513     request_entity = request_logic.getFromFieldsOr404(**fields)
   514 
   514 
   515     if request_entity.state in ['completed', 'denied']:
   515     if request_entity.status in ['completed', 'denied']:
   516       # TODO tell the user that this request has been processed
   516       # TODO tell the user that this request has been processed
   517       self.deny(django_args)
   517       self.deny(django_args)
   518 
   518 
   519     if request_entity.scope.state != 'active':
   519     if request_entity.scope.status != 'active':
   520       # TODO tell the user that this group cannot process requests
   520       # TODO tell the user that this group cannot process requests
   521       self.deny(django_args)
   521       self.deny(django_args)
   522 
   522 
   523     return
   523     return
   524 
   524 
   525   def checkIsMyGroupAcceptedRequest(self, django_args):
   525   def checkIsMyGroupAcceptedRequest(self, django_args):
   526     """Raises an alternate HTTP response if the specified request does not exist
   526     """Raises an alternate HTTP response if the specified request does not exist
   527        or if it's state is not group_accepted.
   527        or if it's status is not group_accepted.
   528     """
   528     """
   529 
   529 
   530     self.checkIsUser(django_args)
   530     self.checkIsUser(django_args)
   531 
   531 
   532     user_entity = user_logic.getForCurrentAccount()
   532     user_entity = user_logic.getForCurrentAccount()
   543 
   543 
   544     if not request_entity:
   544     if not request_entity:
   545       # TODO return 404
   545       # TODO return 404
   546       self.deny(django_args)
   546       self.deny(django_args)
   547 
   547 
   548     if request_entity.state != 'group_accepted':
   548     if request_entity.status != 'group_accepted':
   549       self.deny(django_args)
   549       self.deny(django_args)
   550 
   550 
   551     return
   551     return
   552 
   552 
   553   @allowDeveloper
   553   @allowDeveloper
   574       scope_path = django_args['scope_path']
   574       scope_path = django_args['scope_path']
   575     if 'link_id' in django_args:
   575     if 'link_id' in django_args:
   576       scope_path = django_args['link_id']
   576       scope_path = django_args['link_id']
   577 
   577 
   578     fields = {'user': self.user,
   578     fields = {'user': self.user,
   579               'state': 'active'}
   579               'status': 'active'}
   580 
   580 
   581     if scope_path:
   581     if scope_path:
   582       fields['scope_path'] = scope_path
   582       fields['scope_path'] = scope_path
   583 
   583 
   584     host = host_logic.getForFields(fields, unique=True)
   584     host = host_logic.getForFields(fields, unique=True)
   631     else:
   631     else:
   632       scope_path = django_args['link_id']
   632       scope_path = django_args['link_id']
   633 
   633 
   634     fields = {'user': user,
   634     fields = {'user': user,
   635               'scope_path': scope_path,
   635               'scope_path': scope_path,
   636               'state': 'active'}
   636               'status': 'active'}
   637 
   637 
   638     host = host_logic.getForFields(fields, unique=True)
   638     host = host_logic.getForFields(fields, unique=True)
   639 
   639 
   640     if host:
   640     if host:
   641       return
   641       return
   671     else:
   671     else:
   672       scope_path = django_args['link_id']
   672       scope_path = django_args['link_id']
   673 
   673 
   674     fields = {'user': user,
   674     fields = {'user': user,
   675               'scope_path': scope_path,
   675               'scope_path': scope_path,
   676               'state': 'active'}
   676               'status': 'active'}
   677 
   677 
   678     club_admin_entity = club_admin_logic.getForFields(fields, unique=True)
   678     club_admin_entity = club_admin_logic.getForFields(fields, unique=True)
   679 
   679 
   680     if club_admin_entity:
   680     if club_admin_entity:
   681       return
   681       return
   706 
   706 
   707     user = user_logic.getForCurrentAccount()
   707     user = user_logic.getForCurrentAccount()
   708 
   708 
   709     properties = {
   709     properties = {
   710         'applicant': user,
   710         'applicant': user,
   711         'state': 'accepted'
   711         'status': 'accepted'
   712         }
   712         }
   713 
   713 
   714     application = app_logic.logic.getForFields(properties, unique=True)
   714     application = app_logic.logic.getForFields(properties, unique=True)
   715 
   715 
   716     if application:
   716     if application:
   803               'scope_path': django_args['scope_path'],
   803               'scope_path': django_args['scope_path'],
   804               }
   804               }
   805 
   805 
   806     role_entity = role_logic.logic.getFromFieldsOr404(**fields)
   806     role_entity = role_logic.logic.getFromFieldsOr404(**fields)
   807 
   807 
   808     if role_entity.state != 'active':
   808     if role_entity.status != 'active':
   809       # role is not active
   809       # role is not active
   810       self.deny(django_args)
   810       self.deny(django_args)
   811 
   811 
   812 
   812 
   813   @allowDeveloper
   813   @allowDeveloper
   841               'scope_path': django_args['scope_path'],
   841               'scope_path': django_args['scope_path'],
   842               }
   842               }
   843 
   843 
   844     role_entity = role_logic.logic.getFromFieldsOr404(**fields)
   844     role_entity = role_logic.logic.getFromFieldsOr404(**fields)
   845 
   845 
   846     if role_entity.state != 'active':
   846     if role_entity.status != 'active':
   847       # cannot manage this entity
   847       # cannot manage this entity
   848       self.deny(django_args)
   848       self.deny(django_args)
   849 
   849 
   850     fields = {'link_id': self.user.link_id,
   850     fields = {'link_id': self.user.link_id,
   851         'scope_path': django_args['scope_path'],
   851         'scope_path': django_args['scope_path'],
   852         'state' : 'active'
   852         'status' : 'active'
   853         }
   853         }
   854 
   854 
   855     manage_entity = manage_role_logic.logic.getForFields(fields, unique=True)
   855     manage_entity = manage_role_logic.logic.getForFields(fields, unique=True)
   856 
   856 
   857     if not manage_entity:
   857     if not manage_entity: