Skip to content

Commit

Permalink
fix: grant course staff exam access tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ilee2u committed Feb 13, 2025
1 parent 2d9f4fa commit 39b2793
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions edx_exams/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,26 @@ def test_access_no_due_date(self, attempt_status, response_status):
if response_status == 200:
self.assert_valid_exam_access_token(response, self.user, no_due_date_exam)

def test_access_user_is_course_staff(self):
"""
Verify the endpoint grants access for an exam
with no due date, if started exam attempt.
"""
allowed_time_limit_mins = self.exam.time_limit_mins
start_time = timezone.now() - timedelta(minutes=allowed_time_limit_mins/2)
ExamAttempt.objects.create(
user=self.user,
exam=self.exam,
attempt_number=1,
status='started',
start_time=start_time,
allowed_time_limit_mins=allowed_time_limit_mins
)

response = self.get_exam_access(self.user, self.url)
self.assertEqual(200, response.status_code)
self.assert_valid_exam_access_token(response, self.user, self.exam)

def test_access_not_granted_if_hide_after_due(self):
"""
Verify the endpoint does not grant access for past-due exam
Expand Down
4 changes: 4 additions & 0 deletions edx_exams/apps/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ def get_response(cls, exam, user):
elif exam.due_date is not None and timezone.now() >= exam.due_date:
grant_access, response_status = True, status.HTTP_200_OK

# If user is course staff, then grant them access
elif user.has_course_staff_permission(exam.course_id):
grant_access, response_status = True, status.HTTP_200_OK

if grant_access:
log.info('Creating exam access token')
access_token = sign_token_for(user.lms_user_id, expiration_window, claims)
Expand Down

0 comments on commit 39b2793

Please sign in to comment.