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: grant course staff exam access tokens #359

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

ilee2u
Copy link
Member

@ilee2u ilee2u commented Feb 13, 2025

JIRA: Link to JIRA ticket

Description: Add a fix to allow course staff to view the exams they create, as currently some courses staff are blocked from viewing the exams they've created.

Author concerns: List any concerns about this PR - inelegant
solutions, hacks, quick-and-dirty implementations, concerns about
migrations, etc.

Dependencies: dependencies on other outstanding PRs, issues, etc.

Installation instructions: List any non-trivial installation
instructions.

Testing instructions:

  1. Open page A
  2. Do thing B
  3. Expect C to happen
  4. If D happened instead - check failed.

Merge checklist:

  • All reviewers approved
  • CI build is green
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed

Post merge:

  • Delete working branch (if not needed anymore)

Copy link
Member

@michaelroytman michaelroytman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! I left a comment.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you agree with my suggestion below, please update the docstring and the test.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we want, but I think we should have this before line 369. On the frontend, access to the contents of the exam will always be granted to staff members. Because of this, they never see any exam functionality and will not be able to start an exam attempt. Therefore, we can short circuit early and give them access immediately if they are a staff member - no need to look at exam attempts. This makes the code easier to reason about. Does that match your understanding?

Copy link

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  edx_exams/apps/api/v1
  views.py
  edx_exams/apps/api/v1/tests
  test_views.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Member

@michaelroytman michaelroytman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@ilee2u ilee2u merged commit a73d767 into main Feb 13, 2025
4 checks passed
@ilee2u ilee2u deleted the ilee2u/fix-course-staff-access-tokens branch February 13, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants