Skip to content

Commit 81eed53

Browse files
fix: Copilot PR feedback
1 parent 21b5656 commit 81eed53

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

lms/djangoapps/instructor/permissions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def has_permission(self, request, view):
9797
class CourseTeamPermission(BasePermission):
9898
"""
9999
Allow access to course team management endpoints for users with
100-
instructor (Admin) access or the Discussion Admin (forum Administrator) role.
100+
instructor (Admin) access or the Discussion Admin (staff + forum Administrator) role.
101101
"""
102102
def has_permission(self, request, view):
103103
try:
@@ -107,7 +107,9 @@ def has_permission(self, request, view):
107107
course = get_course_by_id(course_key)
108108
if has_access(request.user, 'instructor', course):
109109
return True
110-
if has_forum_access(request.user, course_key, FORUM_ROLE_ADMINISTRATOR):
110+
if has_access(request.user, 'staff', course) and has_forum_access(
111+
request.user, course_key, FORUM_ROLE_ADMINISTRATOR
112+
):
111113
return True
112114
return False
113115

lms/djangoapps/instructor/tests/test_api_v2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,3 +3507,14 @@ def test_plain_staff_cannot_access_team_endpoints(self):
35073507
self.client.force_authenticate(user=self.staff_user)
35083508
response = self.client.get(url)
35093509
assert response.status_code == status.HTTP_403_FORBIDDEN
3510+
3511+
def test_non_staff_forum_admin_cannot_access_team_endpoints(self):
3512+
"""Non-staff user with only forum Administrator role should get 403."""
3513+
non_staff_forum_admin = UserFactory.create()
3514+
admin_role = Role.objects.get(course_id=self.course_key, name='Administrator')
3515+
admin_role.users.add(non_staff_forum_admin)
3516+
3517+
url = reverse('instructor_api_v2:course_team', kwargs={'course_id': str(self.course_key)})
3518+
self.client.force_authenticate(user=non_staff_forum_admin)
3519+
response = self.client.get(url)
3520+
assert response.status_code == status.HTTP_403_FORBIDDEN

lms/djangoapps/instructor/views/api_v2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,7 @@ class CourseTeamRolesView(DeveloperErrorViewMixin, APIView):
24182418
24192419
* 200: OK
24202420
* 401: User is not authenticated
2421-
* 403: User lacks instructor permissions
2421+
* 403: User lacks course team management permissions (requires instructor or discussion Administrator role)
24222422
"""
24232423
permission_classes = (IsAuthenticated, permissions.CourseTeamPermission)
24242424

@@ -2543,7 +2543,7 @@ class CourseTeamView(DeveloperErrorViewMixin, APIView):
25432543
* 200: OK (GET, POST - role granted/revoked)
25442544
* 400: Invalid parameters
25452545
* 401: User is not authenticated
2546-
* 403: User lacks instructor permissions
2546+
* 403: User lacks course team management permissions (requires instructor or discussion Administrator role)
25472547
* 404: Course not found
25482548
"""
25492549
permission_classes = (IsAuthenticated, permissions.CourseTeamPermission)
@@ -2710,7 +2710,7 @@ class CourseTeamMemberView(DeveloperErrorViewMixin, APIView):
27102710
* 200: Role(s) revoked successfully
27112711
* 400: Invalid parameters
27122712
* 401: User is not authenticated
2713-
* 403: User lacks instructor permissions
2713+
* 403: User lacks course team management permissions (requires instructor or discussion Administrator role)
27142714
* 404: Course or user not found
27152715
* 409: Cannot remove own instructor access
27162716
"""

lms/djangoapps/instructor/views/serializers_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def get_tabs(self, data):
190190
},
191191
])
192192

193-
if access['instructor'] or access['forum_admin']:
193+
if access['instructor'] or (access['staff'] and access['forum_admin']):
194194
tabs.append({
195195
'tab_id': 'course_team',
196196
'title': _('Course Team'),

0 commit comments

Comments
 (0)