Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions lms/djangoapps/instructor/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2252,17 +2252,26 @@ 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_api(self):
for rolename in ["staff", "limited_staff", "instructor", "data_researcher"]:
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': rolename,
'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)
# Test role revoke action
response = self.client.post(url, {
'unique_student_identifier': self.other_user.email,
'rolename': rolename,
'action': 'revoke',
})
assert response.status_code == 200
CourseEnrollment.unenroll(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 All @@ -2273,15 +2282,6 @@ def test_modify_access_allow_with_uname(self):
})
assert response.status_code == 200

def test_modify_access_revoke(self):
url = reverse('modify_access', kwargs={'course_id': str(self.course.id)})
response = self.client.post(url, {
'unique_student_identifier': self.other_staff.email,
'rolename': 'staff',
'action': 'revoke',
})
assert response.status_code == 200

def test_modify_access_revoke_with_username(self):
url = reverse('modify_access', kwargs={'course_id': str(self.course.id)})
response = self.client.post(url, {
Expand Down Expand Up @@ -2443,6 +2443,19 @@ def assert_update_forum_role_membership(self, current_user, identifier, rolename
elif action == 'revoke':
assert rolename not in user_roles

def test_autoenroll_on_forum_role_add(self):
"""
Test forum role modification auto enrolls user.
"""
seed_permissions_roles(self.course.id)
user = UserFactory()
for rolename in ["Administrator", "Moderator", "Community TA"]:
assert CourseEnrollment.is_enrolled(user, self.course.id) is False
self.assert_update_forum_role_membership(user, user.email, rolename, "allow")
assert CourseEnrollment.is_enrolled(user, self.course.id)
self.assert_update_forum_role_membership(user, user.email, rolename, "revoke")
CourseEnrollment.unenroll(user, self.course.id)


@ddt.ddt
class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/instructor/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2812,7 +2812,8 @@ def update_forum_role_membership(request, course_id):
))

user = get_student_from_identifier(unique_student_identifier)

if action == 'allow' and not is_user_enrolled_in_course(user, course_id):
CourseEnrollment.enroll(user, course_id)
try:
update_forum_role(course_id, user, rolename, action)
except Role.DoesNotExist:
Expand Down
15 changes: 8 additions & 7 deletions lms/templates/instructor/instructor_dashboard_2/membership.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ <h3 class="hd hd-3">${_("Course Team Management")}</h3>
${_("Discussion Admins can edit or delete any post, clear misuse flags, close "
"and re-open threads, endorse responses, and see posts from all groups. "
"Their posts are marked as 'staff'. They can also add and remove the "
"discussion moderation roles to manage course team membership. Only "
"enrolled users can be added as Discussion Admins.")}"
"discussion moderation roles to manage course team membership. Any users "
"not yet enrolled in the course will be automatically enrolled when added as "
"Discussion Admin")}"
data-list-endpoint="${ section_data['list_forum_members_url'] }"
data-modify-endpoint="${ section_data['update_forum_role_membership_url'] }"
data-add-button-label="${_("Add Discussion Admin")}"
Expand All @@ -257,8 +258,8 @@ <h3 class="hd hd-3">${_("Course Team Management")}</h3>
${_("Discussion Moderators can edit or delete any post, clear misuse flags, close "
"and re-open threads, endorse responses, and see posts from all groups. "
"Their posts are marked as 'staff'. They cannot manage course team membership by "
"adding or removing discussion moderation roles. Only enrolled users can be "
"added as Discussion Moderators.")}"
"adding or removing discussion moderation roles. Any users not yet enrolled "
"in the course will be automatically enrolled when added as Discussion Moderator")}"
data-list-endpoint="${ section_data['list_forum_members_url'] }"
data-modify-endpoint="${ section_data['update_forum_role_membership_url'] }"
data-add-button-label="${_("Add Moderator")}"
Expand All @@ -271,8 +272,8 @@ <h3 class="hd hd-3">${_("Course Team Management")}</h3>
${_("Group Community TAs are members of the community who help course teams moderate discussions. Group "
"Community TAs see only posts by learners in their assigned group. They can edit or delete posts, "
"clear flags, close and re-open threads, and endorse responses, but only for posts by learners in "
"their group. Their posts are marked as 'Community TA'. Only enrolled learners can be added as Group "
"Community TAs.")}"
"their group. Their posts are marked as 'Community TA'. Any users not yet enrolled "
"in the course will be automatically enrolled when added as Group Community TA")}"
data-list-endpoint="${ section_data['list_forum_members_url'] }"
data-modify-endpoint="${ section_data['update_forum_role_membership_url'] }"
data-add-button-label="${_("Add Group Community TA")}"
Expand All @@ -285,7 +286,7 @@ <h3 class="hd hd-3">${_("Course Team Management")}</h3>
${_("Community TAs are members of the community who help course teams moderate discussions. "
"They can see posts by learners in their assigned cohort or enrollment track, and can edit or delete posts, "
"clear flags, close or re-open threads, and endorse responses. Their posts are marked as 'Community TA'. "
"Only enrolled learners can be added as Community TAs.")}"
"Any users not yet enrolled in the course will be automatically enrolled when added as Community TA")}"
data-list-endpoint="${ section_data['list_forum_members_url'] }"
data-modify-endpoint="${ section_data['update_forum_role_membership_url'] }"
data-add-button-label="${_("Add Community TA")}"
Expand Down