Skip to content

Commit

Permalink
fix: allow course staff role to be updated with email change (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto authored Sep 23, 2024
1 parent 87aa3f5 commit a14fb39
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
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)

0 comments on commit a14fb39

Please sign in to comment.