Skip to content

feat: resolve the competency-statuses learner for the LMS - #39425

Open
ufedaseyeuconsultant wants to merge 2 commits into
openedx:masterfrom
ufedaseyeuconsultant:ufedaseyeu/738-lms-learner-resolver
Open

ufedaseyeuconsultant wants to merge 2 commits into
openedx:masterfrom
ufedaseyeuconsultant:ufedaseyeu/738-lms-learner-resolver

Conversation

@ufedaseyeuconsultant

Copy link
Copy Markdown
Contributor

Description

The openedx-platform side of openedx/openedx-core#738: the LMS learner resolver that decides whose competency statuses a request may read, with staff, enrollment, and masquerade handling. The openedx-core side (the statuses endpoint, the resolver seam, and its self-only default) is a separate PR there; the seam's contract is openedx-core's ADR 0008.

Two commits:

  • refactor: extract get_student_user from the progress tab view: ProgressTabView._get_student_user moves verbatim to lms/djangoapps/course_home_api/utils.py as get_student_user(request, course_key, student_id, is_staff), so the resolver can reuse the Progress tab's learner-selection behavior (masquerade for self, staff or CCX-coach access for a named id, bare Http404 otherwise) without duplicating it. The Progress tab calls the util; its behavior is unchanged and its tests pass as before (one test's patch target follows the moved import).
  • feat: resolve competency-statuses learner with staff rules: resolve_course_learner(request, course_key, learner_id) in the same module, mirroring ProgressTabView.get's order: course-run staff access first, then get_student_user, then a DRF PermissionDenied when the resolved learner has no active enrollment and the requester has no staff access. A learner the requester may not see and a learner id that matches no user raise the same bare Http404, so the two responses are byte-identical and user ids cannot be probed. lms/envs/common.py sets OPENEDX_LEARNING_LEARNER_RESOLVER to the new function, with the repo's setting annotations.

Who is affected

  • Learners: with an active enrollment they read their own statuses; signed-in users with neither an active enrollment nor a staff role are refused with a 403.
  • Course staff: can name a learner (enrolled or since-unenrolled) or masquerade as one; a masquerade that does not resolve to a current learner (the Learner role, a content group, a target who unenrolled) falls back to the staff member's own statuses, as on the Progress tab.
  • Operators: the setting ships pointing at this resolver, so no YAML change is needed; ADR 0008 in openedx-core documents how to replace it.

Supporting information

  • [BE] GET Competency Statuses for Learner in Course openedx-core#738: the ticket; its "Access on the LMS (openedx-platform)" scenarios are the behavior contract here.
  • openedx-core ADR 0008 (docs/openedx_learning/decisions/0008-learner-resolver.rst on the core PR's branch): the resolver contract (signature, the two exceptions, the setting).
  • A CCX coach is not exempt from the enrollment refusal (the exemption is keyed to has_access(request.user, "staff", course_key)): a coach naming an unenrolled learner gets a 403, which tells that learner apart from an unknown id. Coaches are authorized to see learners, so that distinction is accepted and documented in the resolver's docstring.
  • AI tools: Claude Code. Claude Fable 5 (claude-fable-5) planned the change and reviewed it; Claude Sonnet 5.5 sub-agents wrote the code and tests under that plan. I reviewed the result.

Testing instructions

Automated:

  1. pytest lms/djangoapps/course_home_api/tests/test_utils.py lms/djangoapps/course_home_api/progress/tests/ --ds=lms.envs.test (57 pass at this branch's head; test_utils.py alone collects 32).
  2. pylint and pycodestyle on the touched files.

New tests cover every LMS scenario of the ticket: an enrolled learner reading their own statuses (no id, own id); staff naming an enrolled and a since-unenrolled learner; staff masquerading as a specific learner (no id and own id both return the masquerade target); the three masquerade fallbacks to the requester (Learner role, content group, target who unenrolled); the bare-404 identity between a forbidden learner and an unknown id (args compared, both empty); staff of another course run getting the same bare 404; an unenrolled non-staff requester naming an enrolled learner getting the 404, not the 403; the 403 for a never-enrolled and a since-unenrolled requester asking for themselves; learner_id=0 as an unknown id on both the staff and non-staff paths; the CCX-coach refusal for an unenrolled learner (with the requester enrolled, which pins that the refusal checks the resolved learner); a DRF-wrapped request; and import_string(settings.OPENEDX_LEARNING_LEARNER_RESOLVER) resolving to the function.

Manual: none until the LMS mounts the learner URLs and an openedx-core release ships the statuses view; the setting is inert until then. After that, the manual steps on the core PR apply end to end.

Deadline

None.

Other information

  • Rollout: this PR can merge before or after the openedx-core one. The LMS serves no openedx-core learner route today: nothing under lms/ includes openedx_learning's learner URLs. The learner surface needs three platform pieces: the learner_urls include, the view_course_competency_criteria permission override from [BE] GET Competency Criteria for Course openedx-core#733, and the resolver with its setting. This PR is the third piece; until the other two land and an openedx-core release ships the statuses view, nothing reads the setting.
  • get_student_user keeps the Progress tab's known behaviors, including that course-run staff can name any existing user id; the ticket records that as a known limitation.

🤖 Generated with Claude Code

The logic that resolves the learner a request is about (self, masquerade
target, or another user for staff and CCX coaches) lived on
ProgressTabView as a private method. It moves to course_home_api/utils.py
as get_student_user so other course home API code can reuse it. The body
is unchanged. The progress tab test that patches has_ccx_coach_role now
patches it where get_student_user looks it up.

Part of openedx/openedx-core#738.

Co-Authored-By: Claude Fable 5 <[email protected]>
@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 24, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @ufedaseyeuconsultant!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform-oncall.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Add resolve_course_learner, the LMS implementation of the learner
resolver contract in openedx-core ADR 0008, and point the new
OPENEDX_LEARNING_LEARNER_RESOLVER setting at it. This is part of
openedx/openedx-core#738.

The resolver runs its checks in the same order as ProgressTabView.get,
minus its Progress-tab-enabled and course-load checks, and raises a 403 where the Progress tab
returns a 401. It checks the requester's staff access, resolves the
learner through get_student_user (own data, masquerade, or a named
learner for staff and CCX coaches), and then refuses with
PermissionDenied when the resolved learner has no active enrollment,
unless the requester has staff access. A learner the requester may not
see and an unknown learner both raise a bare Http404 with no message,
so the two exceptions are identical.

Like the Progress tab, the resolver clears the session's masquerade
field data when a staff requester names no other learner. get_student_user gains a contract
docstring, and its comment no longer refers to the progress page.

Rollout: the setting is inert until an openedx-core release ships the
learner competency statuses view that reads it.

Co-Authored-By: Claude Fable 5 <[email protected]>
@ufedaseyeuconsultant
ufedaseyeuconsultant force-pushed the ufedaseyeu/738-lms-learner-resolver branch from 9ef093d to fa8743f Compare November 24, 2026 15:38
@ufedaseyeuconsultant

Copy link
Copy Markdown
Contributor Author

@ufedaseyeuconsultant ufedaseyeuconsultant changed the title feat: resolve the competency-statuses learner with staff and masquerade rules feat: resolve the competency-statuses learner for the LMS Nov 24, 2026
@mphilbrick211 mphilbrick211 added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Nov 25, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs test run Author's first PR to this repository, awaiting test authorization from Axim open-source-contribution PR author is not from Axim or 2U

Projects

Status: Waiting on Author

Development

Successfully merging this pull request may close these issues.

3 participants