Skip to content

Commit 13cdb7f

Browse files
fix: Use specific sort order for Instructor Dashboard roles. (#38478)
1 parent f20a666 commit 13cdb7f

3 files changed

Lines changed: 45 additions & 9 deletions

File tree

lms/djangoapps/instructor/access.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
FORUM_ROLE_COMMUNITY_TA,
5454
)
5555

56+
INSTRUCTOR_DASHBOARD_ROLE_SORT_ORDER = (
57+
'staff', 'limited_staff', 'instructor', 'beta', 'data_researcher',
58+
*FORUM_ROLES, 'ccx_coach',
59+
)
60+
5661
ROLE_DISPLAY_NAMES = {
5762
'instructor': _('Admin'),
5863
'staff': _('Staff'),

lms/djangoapps/instructor/tests/test_api_v2.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,6 +2885,29 @@ def test_list_roles_with_ccx_enabled(self):
28852885
ccx_entry = next(r for r in response.data['results'] if r['role'] == 'ccx_coach')
28862886
assert ccx_entry['display_name'] == 'CCX Coach'
28872887

2888+
@override_settings(FEATURES={**settings.FEATURES, 'CUSTOM_COURSES_EDX': True})
2889+
def test_roles_sort_order(self):
2890+
"""Roles are returned in the expected display order, with ccx_coach last."""
2891+
ccx_course = CourseFactory.create(
2892+
org='edX',
2893+
number='SortX',
2894+
run='2024',
2895+
display_name='Sort Order Test Course',
2896+
enable_ccx=True,
2897+
)
2898+
url = reverse('instructor_api_v2:course_team_roles', kwargs={'course_id': str(ccx_course.id)})
2899+
instructor = InstructorFactory.create(course_key=ccx_course.id)
2900+
self.client.force_authenticate(user=instructor)
2901+
response = self.client.get(url)
2902+
2903+
assert response.status_code == status.HTTP_200_OK
2904+
returned_roles = [r['role'] for r in response.data['results']]
2905+
assert returned_roles == [
2906+
'staff', 'limited_staff', 'instructor', 'beta', 'data_researcher',
2907+
'Administrator', 'Moderator', 'Group Moderator', 'Community TA',
2908+
'ccx_coach',
2909+
]
2910+
28882911
def test_list_roles_unauthenticated(self):
28892912
"""Unauthenticated request returns 401."""
28902913
response = self.client.get(self.url)

lms/djangoapps/instructor/views/api_v2.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
from lms.djangoapps.instructor import enrollment, permissions
8989
from lms.djangoapps.instructor.access import (
9090
FORUM_ROLES,
91+
INSTRUCTOR_DASHBOARD_ROLE_SORT_ORDER,
9192
ROLE_DISPLAY_NAMES,
9293
ROLES,
9394
allow_access,
@@ -3080,11 +3081,11 @@ class CourseTeamRolesView(DeveloperErrorViewMixin, APIView):
30803081
{
30813082
"course_id": "course-v1:edX+DemoX+Demo_Course",
30823083
"results": [
3083-
{"role": "beta", "display_name": "Beta Tester"},
3084-
{"role": "data_researcher", "display_name": "Data Researcher"},
3085-
{"role": "instructor", "display_name": "Admin"},
3084+
{"role": "staff", "display_name": "Staff"},
30863085
{"role": "limited_staff", "display_name": "Limited Staff"},
3087-
{"role": "staff", "display_name": "Staff"}
3086+
{"role": "instructor", "display_name": "Admin"},
3087+
{"role": "beta", "display_name": "Beta Tester"},
3088+
{"role": "data_researcher", "display_name": "Data Researcher"}
30883089
]
30893090
}
30903091
@@ -3112,15 +3113,22 @@ def get(self, request, course_id):
31123113
if editable and not has_access(request.user, 'instructor', course):
31133114
roles = set(FORUM_ROLES)
31143115

3116+
role_order = {role: i for i, role in enumerate(INSTRUCTOR_DASHBOARD_ROLE_SORT_ORDER)}
3117+
31153118
results = [
31163119
{'role': rolename, 'display_name': str(ROLE_DISPLAY_NAMES[rolename])}
3117-
for rolename in sorted(roles)
3120+
for rolename in sorted(
3121+
roles, key=lambda r: role_order.get(r, len(INSTRUCTOR_DASHBOARD_ROLE_SORT_ORDER))
3122+
)
31183123
]
31193124

3120-
return Response({
3121-
'course_id': str(course_key),
3122-
'results': results,
3123-
}, status=status.HTTP_200_OK)
3125+
return Response(
3126+
{
3127+
'course_id': str(course_key),
3128+
'results': results,
3129+
},
3130+
status=status.HTTP_200_OK
3131+
)
31243132

31253133

31263134
@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch')

0 commit comments

Comments
 (0)