90 |
90 |
91 DEF_NO_ACTIVE_ROLE_MSG = ugettext( |
91 DEF_NO_ACTIVE_ROLE_MSG = ugettext( |
92 'There is no such active role.') |
92 'There is no such active role.') |
93 |
93 |
94 DEF_ALREADY_PARTICIPATING_MSG = ugettext( |
94 DEF_ALREADY_PARTICIPATING_MSG = ugettext( |
95 'You cannot become a student because you are already participating ' |
95 'You cannot become a Student because you are already participating ' |
96 'in this program.') |
96 'in this program.') |
97 |
97 |
98 DEF_ALREADY_STUDENT_ROLE_MSG = ugettext( |
98 DEF_ALREADY_STUDENT_ROLE_MSG = ugettext( |
99 'You cannot become a Mentor or Organization Admin because you already are ' |
99 'You cannot become a Mentor or Organization Admin because you already are ' |
100 'a student in this program.') |
100 'a Student in this program.') |
101 |
101 |
102 DEF_NO_ACTIVE_PROGRAM_MSG = ugettext( |
102 DEF_NO_ACTIVE_PROGRAM_MSG = ugettext( |
103 'There is no such active program.') |
103 'There is no such active program.') |
104 |
104 |
105 DEF_NO_REQUEST_MSG = ugettext( |
105 DEF_NO_REQUEST_MSG = ugettext( |
1094 |
1094 |
1095 # fill the role_list with all the mentor and org admin roles for this user |
1095 # fill the role_list with all the mentor and org admin roles for this user |
1096 role_list = [] |
1096 role_list = [] |
1097 |
1097 |
1098 filter = {'user': user_entity, |
1098 filter = {'user': user_entity, |
|
1099 'program': program_entity, |
1099 'status': 'active'} |
1100 'status': 'active'} |
1100 |
1101 |
1101 mentor_roles = mentor_logic.getForFields(filter) |
1102 mentor_role = mentor_logic.getForFields(filter, unique=True) |
1102 if mentor_roles: |
1103 if mentor_role: |
1103 role_list += mentor_roles |
1104 # the current user has a role for the given program |
1104 |
1105 raise out_of_band.AccessViolation( |
1105 org_admin_roles = org_admin_logic.getForFields(filter) |
1106 message_fmt=DEF_ALREADY_PARTICIPATING_MSG) |
1106 if org_admin_roles: |
1107 |
1107 role_list += org_admin_roles |
1108 org_admin_role = org_admin_logic.getForFields(filter, unique=True) |
1108 |
1109 if org_admin_role: |
1109 # check if the user has a role for the retrieved program |
1110 # the current user has a role for the given program |
1110 for role in role_list: |
1111 raise out_of_band.AccessViolation( |
1111 |
|
1112 if role.program.key() == program_entity.key(): |
|
1113 # the current user has a role for the given program |
|
1114 raise out_of_band.AccessViolation( |
|
1115 message_fmt=DEF_ALREADY_PARTICIPATING_MSG) |
1112 message_fmt=DEF_ALREADY_PARTICIPATING_MSG) |
1116 |
1113 |
1117 # no roles found, access granted |
1114 # no roles found, access granted |
1118 return |
1115 return |
1119 |
1116 |
1144 # check if the current user is already a student for this program |
1141 # check if the current user is already a student for this program |
1145 student_role = student_logic.getForFields(filter, unique=True) |
1142 student_role = student_logic.getForFields(filter, unique=True) |
1146 |
1143 |
1147 if student_role: |
1144 if student_role: |
1148 raise out_of_band.AccessViolation( |
1145 raise out_of_band.AccessViolation( |
1149 message_fmt=DEF_ALREADY_PARTICIPATING_MSG) |
1146 message_fmt=DEF_ALREADY_STUDENT_ROLE_MSG) |
1150 |
1147 |
1151 return |
1148 return |
1152 |
1149 |
1153 def checkIsNotStudentForProgramOfOrg(self, django_args): |
1150 def checkIsNotStudentForProgramOfOrg(self, django_args): |
1154 """Checks if the current user has no active Student role for the program |
1151 """Checks if the current user has no active Student role for the program |