Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow course staff role to be updated with email change #321

Merged
merged 1 commit into from
Sep 23, 2024
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
5 changes: 1 addition & 4 deletions edx_exams/apps/core/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def listen_for_course_access_role_added(sender, signal, **kwargs): # pylint: di
if role not in COURSE_STAFF_ROLES:
return

user, _ = User.objects.get_or_create(
username=user_data.pii.username,
email=user_data.pii.email,
)
user, _ = User.objects.get_or_create(username=user_data.pii.username)
CourseStaffRole.objects.get_or_create(
user=user,
course_id=course_key,
Expand Down
26 changes: 26 additions & 0 deletions edx_exams/apps/core/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,29 @@ def test_course_access_role_remove_single_role(self):
roles,
['instructor']
)

def test_course_access_role_email_change(self):
"""
Test that if a user updates their email, additional course staff roles are able to be added.
"""
role_event_data = self._get_event_data(self.course_id, self.existing_user.username, 'staff')
event_metadata = self._get_event_metadata(COURSE_ACCESS_ROLE_ADDED)
event_kwargs = {
'course_access_role_data': role_event_data,
'metadata': event_metadata,
}
listen_for_course_access_role_added(None, COURSE_ACCESS_ROLE_ADDED, **event_kwargs)

self.existing_user.email = '[email protected]'
self.existing_user.save()

other_course = 'course-v1:another-course-2024'
role_event_data = self._get_event_data(other_course, self.existing_user.username, 'staff')
event_metadata = self._get_event_metadata(COURSE_ACCESS_ROLE_ADDED)
event_kwargs = {
'course_access_role_data': role_event_data,
'metadata': event_metadata,
}
listen_for_course_access_role_added(None, COURSE_ACCESS_ROLE_ADDED, **event_kwargs)

self.assertEqual(len(CourseStaffRole.objects.filter(user=self.existing_user)), 2)
Loading