Skip to content

Commit

Permalink
fix: auto enroll users when added as staff (#32561)
Browse files Browse the repository at this point in the history
The course team management section under Instructor > Membership tab
allows users to be added a role even if are not enrolled in the course.
This is behaviour does not match the help text displayed in the section.

This PR updates modify_access api to enrolls user if they are not enrolled
after adding them to a role as well as changes the help text to reflect
actual changes.
  • Loading branch information
navinkarkera committed Apr 26, 2024
1 parent 734a550 commit 61b8961
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cms/templates/manage_users.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h3 class="title-3">${_("Course Team Roles")}</h3>
<p>${_("Course team members with the Staff role are course co-authors. They have full writing and editing privileges on all course content.")}</p>
## Note that the "Admin" role below is identified as "Instructor" in the Django admin panel.
<p>${_("Admins are course team members who can add and remove other course team members.")}</p>
<p>${_("All course team members can access content in Studio, the LMS, and Insights, but are not automatically enrolled in the course.")}</p>
<p>${_("All course team members can access content in Studio, the LMS, and Insights, and they are automatically enrolled in the course.")}</p>
</div>

% if show_transfer_ownership_hint:
Expand Down
3 changes: 3 additions & 0 deletions lms/djangoapps/instructor/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2253,13 +2253,16 @@ def test_modify_access_bad_role(self):
assert response.status_code == 400

def test_modify_access_allow(self):
assert CourseEnrollment.is_enrolled(self.other_user, self.course.id) is False
url = reverse('modify_access', kwargs={'course_id': str(self.course.id)})
response = self.client.post(url, {
'unique_student_identifier': self.other_user.email,
'rolename': 'staff',
'action': 'allow',
})
assert response.status_code == 200
# User should be auto enrolled in the course
assert CourseEnrollment.is_enrolled(self.other_user, self.course.id)

def test_modify_access_allow_with_uname(self):
url = reverse('modify_access', kwargs={'course_id': str(self.course.id)})
Expand Down
7 changes: 5 additions & 2 deletions lms/djangoapps/instructor/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,12 @@ def modify_access(request, course_id):
course = get_course_with_access(
request.user, 'instructor', course_id, depth=None
)
unique_student_identifier = request.POST.get('unique_student_identifier')
try:
user = get_student_from_identifier(request.POST.get('unique_student_identifier'))
user = get_student_from_identifier(unique_student_identifier)
except User.DoesNotExist:
response_payload = {
'unique_student_identifier': request.POST.get('unique_student_identifier'),
'unique_student_identifier': unique_student_identifier,
'userDoesNotExist': True,
}
return JsonResponse(response_payload)
Expand Down Expand Up @@ -1044,6 +1045,8 @@ def modify_access(request, course_id):

if action == 'allow':
allow_access(course, user, rolename)
if not is_user_enrolled_in_course(user, course_id):
CourseEnrollment.enroll(user, course_id)
elif action == 'revoke':
revoke_access(course, user, rolename)
else:
Expand Down
4 changes: 2 additions & 2 deletions lms/static/js/fixtures/instructor_dashboard/membership.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h3 class="hd hd-3">Course Team Management</h3>
</div>

<div class="auth-list-container active" data-rolename="staff" data-display-name="Staff" data-info-text="
Course team members with the Staff role help you manage your course. Staff can enroll and unenroll learners, as well as modify their grades and access all course data. Staff also have access to your course in Studio and Insights. You can only give course team roles to enrolled users."
Course team members with the Staff role help you manage your course. Staff can enroll and unenroll learners, as well as modify their grades and access all course data. Staff also have access to your course in Studio and Insights. Any users not yet enrolled in the course will be automatically enrolled when added as Staff."
data-list-endpoint="/courses/course-v1:edx+ed202+2017_T3/instructor/api/list_course_role_members"
data-modify-endpoint="/courses/course-v1:edx+ed202+2017_T3/instructor/api/modify_access"
data-add-button-label="Add Staff">
Expand All @@ -33,7 +33,7 @@ <h3 class="hd hd-3">Course Team Management</h3>
<div class="info">
Course team members with the Staff role help you manage your course. Staff can enroll and unenroll learners,
as well as modify their grades and access all course data. Staff also have access to your course in Studio and
Insights. You can only give course team roles to enrolled users.
Insights. Any users not yet enrolled in the course will be automatically enrolled when added as Staff.
</div>
<div class="member-list">
<table>
Expand Down
2 changes: 1 addition & 1 deletion lms/static/js/instructor_dashboard/membership.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ such that the value can be defined later than this assignment (file load order).
text: identifier
}));
}
}
}
return displayResponse.$task_response.append($taskResSection);
};
if (errors.length === 0 && successes.length === 0 && noUsers.length === 0) {
Expand Down
16 changes: 10 additions & 6 deletions lms/templates/instructor/instructor_dashboard_2/membership.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ <h3 class="hd hd-3">${_("Course Team Management")}</h3>
${_("Course team members with the Staff role help you manage your course. "
"Staff can enroll and unenroll learners, as well as modify their grades and "
"access all course data. Staff also have access to your course in Studio and "
"Insights. You can only give course team roles to enrolled users.")}"
"Insights. Any users not yet enrolled in the course will be automatically "
"enrolled when added as Staff.")}"
data-list-endpoint="${ section_data['list_course_role_members_url'] }"
data-modify-endpoint="${ section_data['modify_access_url'] }"
data-add-button-label="${_("Add Staff")}"
Expand All @@ -185,7 +186,8 @@ <h3 class="hd hd-3">${_("Course Team Management")}</h3>
${_("Course team members with the Limited Staff role help you manage your course. "
"Limited Staff can enroll and unenroll learners, as well as modify their grades and "
"access all course data. Limited Staff don't have access to your course in Studio. "
"You can only give course team roles to enrolled users.")}"
"Any users not yet enrolled in the course will be automatically enrolled when added "
"as Limited Staff.")}"
data-list-endpoint="${ section_data['list_course_role_members_url'] }"
data-modify-endpoint="${ section_data['modify_access_url'] }"
data-add-button-label="${_("Add Limited Staff")}"
Expand All @@ -199,8 +201,8 @@ <h3 class="hd hd-3">${_("Course Team Management")}</h3>
${_("Course team members with the Admin role help you manage your course. "
"They can do all of the tasks that Staff can do, and can also add and "
"remove the Staff and Admin roles, discussion moderation roles, and the "
"beta tester role to manage course team membership. You can only give "
"course team roles to enrolled users.")}"
"beta tester role to manage course team membership. Any users not yet "
"enrolled in the course will be automatically enrolled when added as Admin.")}"
data-list-endpoint="${ section_data['list_course_role_members_url'] }"
data-modify-endpoint="${ section_data['modify_access_url'] }"
data-add-button-label="${_("Add Admin")}"
Expand All @@ -213,7 +215,8 @@ <h3 class="hd hd-3">${_("Course Team Management")}</h3>
data-info-text="
${_("Beta Testers can see course content before other learners. "
"They can make sure that the content works, but have no additional "
"privileges. You can only give course team roles to enrolled users.")}"
"privileges. Any users not yet enrolled in the course will be automatically "
"enrolled when added as Beta Tester.")}"
data-list-endpoint="${ section_data['list_course_role_members_url'] }"
data-modify-endpoint="${ section_data['modify_access_url'] }"
data-add-button-label="${_("Add Beta Tester")}"
Expand All @@ -237,7 +240,8 @@ <h3 class="hd hd-3">${_("Course Team Management")}</h3>
data-rolename="data_researcher"
data-display-name="${_("Course Data Researcher")}"
data-info-text="
${_("Course Data Researchers can access the data download tab.")}"
${_("Course Data Researchers can access the data download tab. Any users not yet "
"enrolled in the course will be automatically enrolled when added as Course Data Researcher.")}"
data-list-endpoint="${ section_data['list_course_role_members_url'] }"
data-modify-endpoint="${ section_data['modify_access_url'] }"
data-add-button-label="${_("Add Course Data Researcher")}"
Expand Down

0 comments on commit 61b8961

Please sign in to comment.