Skip to content

feat: GET a learner's competency statuses for a course run (#738) - #5

Open
nattynerdy wants to merge 4 commits into
neuley/738-depsfrom
neuley/738-learner-competency
Open

nattynerdy wants to merge 4 commits into
neuley/738-depsfrom
neuley/738-learner-competency

Conversation

@nattynerdy

Copy link
Copy Markdown
Owner

Description

openedx#738, the openedx-core side: a GET endpoint that returns a learner's stored competency and criterion statuses for a course run, scoped to exactly the items the openedx#733 criteria endpoint reports, with a deployer-replaceable learner resolver deciding whose statuses a request may read. The openedx-platform side of the ticket (the LMS resolver with staff, enrollment, and masquerade handling) is a separate PR there.

Four commits:

  • get_learner_competency_statuses(*, user_id, course_key) (applets/cbe/api.py, in __all__, UNSTABLE). It calls [BE] GET Competency Criteria for Course openedx/openedx-core#733's get_course_competency_criteria() for scope, so archived and disabled records are excluded exactly as the criteria endpoint excludes them, and a course with no live course-level group costs one query and never reads the status tables. One query resolves every ancestor tag id over the Tag.parent chain (the taxonomy depth cap makes that a fixed set of joins), one query reads each status table, and statuses are returned as MasteryStatus members. A competency reported Demonstrated also carries demonstrated_in_course: the other course run whose course-level group was first recorded as Demonstrated (earliest modified), or None when there is no such run or when this course run's own course-level group is Demonstrated, so the field only ever points at credit this run's criteria did not earn. A staff correction under ADR 0004 can rewrite those rows and change which run is named. The return shapes are frozen dataclasses in data.py.
  • The learner resolver (applets/cbe/rest_api/learner_resolver.py). The routes that name a learner ask one callable, resolver(request, course_key, learner_id) -> User, loaded per call from the top-level setting OPENEDX_LEARNING_LEARNER_RESOLVER. It raises a bare Http404 for a learner the requester may not see or that does not exist (both render identically, so user ids cannot be probed) and DRF PermissionDenied when the requester may read no learner data for the course run. The built-in default admits only the requester, with no database lookup for foreign ids. The default's docstring and ADR 0008 define the contract the LMS implements.
  • LearnerCompetencyStatusesView at courses/<course_key>/competency-statuses/ in [BE] GET Competency Criteria for Course openedx/openedx-core#733's learner URLs, with [BE] GET Competency Criteria for Course openedx/openedx-core#733's authentication. Check order: 401, then 400 for a malformed course key (same message as [BE] GET Competency Criteria for Course openedx/openedx-core#733), then the same bare 404 for a non-integer or unknown learner_id, then the resolver, then the read, so a refused requester is refused even for a course with no criteria. The payload is the ticket's two arrays, ordered by id, and carries nothing identifying the learner.
  • ADR 0008 (Proposed) records the resolver seam: the setting, the signature, the two exceptions, the self-only default, and the rejected alternatives. The README points hosts at it.

Who is affected

Supporting information

Testing instructions

Automated:

  1. pytest tests/openedx_learning/applets/cbe -o addopts="" (857 pass, 10 skip at this branch's head; the skips need real row locks).
  2. The quality checks as CI runs them: lint-imports, pylint, pycodestyle, isort --check-only, pydocstyle and mypy --show-traceback. No migration is added; python manage.py makemigrations --check --dry-run reports no changes. tox -e docs builds ADR 0008 cleanly.

New tests: test_learner_statuses_api.py covers statuses returned by id with their stored values, ancestor statuses following the remaining lineage (and disappearing with the last competency that carries the ancestor), parity with openedx#733's result for each of the ticket's seven archived states (including an archived course-level group, an archived taxonomy with live tags, and a disabled taxonomy), a six-level tag chain, every demonstrated_in_course case (another run named by earliest demonstration, null when this run's own group is Demonstrated, null for only-here, null when demonstrated only through sub-competencies or not at all, another learner's Demonstrated rows ignored), the database-side ordering of both reads, and query counts measured against a openedx#733 baseline rather than a hard-coded number. test_learner_resolver.py pins the default's self-only behavior, the identical bare 404s with no database lookup, and per-call setting reload. test_learner_statuses_views.py pins the check order with a recording resolver (including that the resolver receives the parsed plain course key and an int or None, and is not called for a malformed key or a bad learner_id), byte-identical 404 bodies across a non-canonical id, an unknown id, another user's id, and a 5000-digit id, the view discarding a message a host resolver puts on Http404 or NotFound, empty results for courses with no criteria while the learner holds statuses from other runs, the exact payload shape with no learner identity in it, a configured resolver being honored, and the startup system check for a mistyped resolver path.

Manual, against a devstack with recorded statuses (record one by grading a subsection that carries a criterion, so the roll-up writes status rows):

  1. As a learner, GET /api/cbe/v1/courses/<course run key>/competency-statuses/: your criterion and competency statuses for that run, with demonstrated_in_course naming another run only where you demonstrated the competency there.
  2. Repeat with ?learner_id=<someone else's id>: a bare 404, identical to ?learner_id=999999.
  3. Repeat with a malformed course key: a 400 naming the malformed key.

Deadline

None.

Other information

🤖 Generated with Claude Code

ufedaseyeuconsultant and others added 4 commits November 24, 2026 16:49
Add get_learner_competency_statuses(*, user_id, course_key), which returns
a learner's stored criterion and competency statuses for the live criteria
of a course run. The competencies and criteria come from
get_course_competency_criteria(), so an archived record hides a status
exactly when it hides the record there. Competency statuses also cover
the ancestors of the returned competencies, found with one query over
the Tag parent chain.

The result is a frozen LearnerCompetencyStatuses dataclass whose status
fields hold MasteryStatus members. A Demonstrated competency status
carries demonstrated_in_course: the other course run whose course-level
group was first recorded as Demonstrated for the learner, as a
LearnerCourseRun, or None. It is also None when the course-level group of
the requested course run is Demonstrated. A course run with no live
course-level group costs one query, and the count does not grow with the
number of rows.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
resolve_learner loads the callable named by the top-level
OPENEDX_LEARNING_LEARNER_RESOLVER setting on every call and falls back
to default_learner_resolver, which admits only the requester. A refusal
is an Http404 or a DRF PermissionDenied, and the contract is UNSTABLE. A
Django system check reports a configured path that cannot be imported.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add GET cbe/v1/courses/<course_key>/competency-statuses/, which returns
one learner's competency and criterion statuses for a course run as the
arrays competency_statuses and criterion_statuses. The optional
learner_id query parameter is resolved through the deployer-replaceable
learner resolver; the default admits only the requester. Checks run in
the order sign-in (401), course key (400), learner_id (404), resolver
(404/403). A learner_id that is not a canonical positive decimal integer
(no leading zeros, signs, spaces, underscores, or non-ASCII digits, and
at most 18 digits, which always fits a signed 64-bit id, so a host lookup
cannot error on it) is a 404, and the view re-raises any 404 from the
resolver without its message. The response is unpaginated and carries
nothing that identifies the learner.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add a proposed ADR for the setting, signature, exceptions and self-only
default of the learner resolver, including that a 404 about a learner
takes precedence over a 403, and a README paragraph telling hosts about
the setting.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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