@@ -128,6 +128,7 @@ def user_editable(request_user, target_user):
128128 coordinator_courses = Coordinator .objects .filter (user = request_user ).values_list (
129129 "course" , flat = True
130130 )
131+ print (coordinator_courses )
131132 if Student .objects .filter (
132133 user = target_user , course__in = coordinator_courses
133134 ).exists ():
@@ -150,35 +151,38 @@ def has_permission(request_user, target_user):
150151
151152 # If the request_user can edit the target_user's profile, return True
152153 # This includes superusers, if the request_user is the target_user, or
153- # if the request_user is a coordinator or a course the target_user is in
154+ # if the request_user is a coordinator of a course the target_user is in
154155 if user_editable (request_user , target_user ):
155156 return True
156157
157158 # If the target user is a mentor, return True
158159 if Mentor .objects .filter (user = target_user ).exists ():
159160 return True
160161
162+ ### For future use for students to contact other students in their section
161163 # If requestor is a student, get all the sections they are in
162164 # If the target user is a student in any of those sections, return True
163- if Student .objects .filter (user = request_user ).exists ():
164- if Student .objects .filter (user = target_user ).exists ():
165- request_user_sections = Student .objects .filter (
166- user = request_user
167- ).values_list ("section" , flat = True )
168- target_user_sections = Student .objects .filter (user = target_user ).values_list (
169- "section" , flat = True
170- )
171- if set (request_user_sections ) & set (target_user_sections ):
172- return True
173-
174- # If requestor is a mentor, get all the courses they mentor
175- # If the target user is a student or mentor in any of those courses , return True
165+ # if Student.objects.filter(user=request_user).exists():
166+ # if Student.objects.filter(user=target_user).exists():
167+ # request_user_sections = Student.objects.filter(
168+ # user=request_user
169+ # ).values_list("section", flat=True)
170+ # target_user_sections = Student.objects.filter(user=target_user).values_list(
171+ # "section", flat=True
172+ # )
173+ # if set(request_user_sections) & set(target_user_sections):
174+ # return True
175+
176+ # If requestor is a mentor, get all the sections they mentor
177+ # If the target user is a student in any of those sections , return True
176178 if Mentor .objects .filter (user = request_user ).exists ():
177- mentor_courses = Mentor .objects .filter (user = request_user ).values_list (
178- "course " , flat = True
179+ mentor_sections = Mentor .objects .filter (user = request_user ).values_list (
180+ "section " , flat = True
179181 )
180182
181- if Student .objects .filter (user = target_user , course__in = mentor_courses ).exists ():
183+ if Student .objects .filter (
184+ user = target_user , section__in = mentor_sections
185+ ).exists ():
182186 return True
183187
184188 return False
0 commit comments