app/soc/views/helper/access.py
changeset 1559 283046e54c01
parent 1558 5ff25327371e
child 1577 b0bb5c8b5f78
equal deleted inserted replaced
1558:5ff25327371e 1559:283046e54c01
  1062             message_fmt=DEF_ALREADY_PARTICIPATING_MSG)
  1062             message_fmt=DEF_ALREADY_PARTICIPATING_MSG)
  1063 
  1063 
  1064     # no roles found, access granted
  1064     # no roles found, access granted
  1065     return
  1065     return
  1066 
  1066 
       
  1067   def checkIsNotStudentForProgramInScope(self, django_args):
       
  1068     """Checks if the current user is not a student for the given
       
  1069        program in django_args.
       
  1070 
       
  1071     Args:
       
  1072       django_args: a dictionary with django's arguments
       
  1073 
       
  1074      Raises:
       
  1075        AccessViolationResponse: if the current user has a student
       
  1076                                 role for the given program.
       
  1077     """
       
  1078 
       
  1079     if django_args.get('seed'):
       
  1080       key_name = django_args['seed']['scope_path']
       
  1081     else:
       
  1082       key_name = django_args['scope_path']
       
  1083 
       
  1084     program_entity = program_logic.getFromKeyName(key_name)
       
  1085     user_entity = user_logic.getForCurrentAccount()
       
  1086 
       
  1087     filter = {'user': user_entity,
       
  1088               'scope': program_entity,
       
  1089               'status': 'active'}
       
  1090 
       
  1091     # check if the current user is already a student for this program
       
  1092     student_role = student_logic.getForFields(filter, unique=True)
       
  1093 
       
  1094     if student_role:
       
  1095       raise out_of_band.AccessViolation(
       
  1096           message_fmt=DEF_ALREADY_PARTICIPATING_MSG)
       
  1097 
       
  1098     return
       
  1099 
  1067   def checkIsNotStudentForProgramOfOrg(self, django_args):
  1100   def checkIsNotStudentForProgramOfOrg(self, django_args):
  1068     """Checks if the current user has no active Student role for the program
  1101     """Checks if the current user has no active Student role for the program
  1069        that the organization in the scope_path is participating in.
  1102        that the organization in the scope_path is participating in.
  1070 
  1103 
  1071     Args:
  1104     Args: