fix: enroll users when added to a forum role (#32436)
This commit is contained in:
@@ -2252,17 +2252,26 @@ class TestInstructorAPILevelsAccess(SharedModuleStoreTestCase, LoginEnrollmentTe
|
||||
})
|
||||
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)})
|
||||
@@ -2273,15 +2282,6 @@ class TestInstructorAPILevelsAccess(SharedModuleStoreTestCase, LoginEnrollmentTe
|
||||
})
|
||||
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, {
|
||||
@@ -2443,6 +2443,19 @@ class TestInstructorAPILevelsAccess(SharedModuleStoreTestCase, LoginEnrollmentTe
|
||||
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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -229,8 +229,9 @@ from openedx.core.djangolib.markup import HTML, Text
|
||||
${_("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")}"
|
||||
@@ -257,8 +258,8 @@ from openedx.core.djangolib.markup import HTML, Text
|
||||
${_("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")}"
|
||||
@@ -271,8 +272,8 @@ from openedx.core.djangolib.markup import HTML, Text
|
||||
${_("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")}"
|
||||
@@ -285,7 +286,7 @@ from openedx.core.djangolib.markup import HTML, Text
|
||||
${_("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")}"
|
||||
|
||||
Reference in New Issue
Block a user