Repository navigation
feat: GET a learner's competency statuses for a course run (#738) - #5
Open
nattynerdy wants to merge 4 commits into
Open
nattynerdy wants to merge 4 commits into
nattynerdy wants to merge 4 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'sget_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 theTag.parentchain (the taxonomy depth cap makes that a fixed set of joins), one query reads each status table, and statuses are returned asMasteryStatusmembers. A competency reported Demonstrated also carriesdemonstrated_in_course: the other course run whose course-level group was first recorded as Demonstrated (earliestmodified), orNonewhen 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 indata.py.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 settingOPENEDX_LEARNING_LEARNER_RESOLVER. It raises a bareHttp404for a learner the requester may not see or that does not exist (both render identically, so user ids cannot be probed) and DRFPermissionDeniedwhen 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.LearnerCompetencyStatusesViewatcourses/<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 unknownlearner_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.Who is affected
OPENEDX_LEARNING_LEARNER_RESOLVERis new host-facing surface, defined in ADR 0008 (docs/openedx_learning/decisions/0008-learner-resolver.rst).Supporting information
git logshows against it are this PR's own change. [BE] GET Competency Statuses for Learner in Course openedx/openedx-core#738 consumes only the competency and criterion ids from [BE] GET Competency Criteria for Course openedx/openedx-core#733's result, so feat: GET a course run's competency criteria for the learner Progress tab openedx/openedx-core#945's review can reshape its payload freely.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:
pytest tests/openedx_learning/applets/cbe -o addopts=""(857 pass, 10 skip at this branch's head; the skips need real row locks).lint-imports,pylint,pycodestyle,isort --check-only,pydocstyleandmypy --show-traceback. No migration is added;python manage.py makemigrations --check --dry-runreports no changes.tox -e docsbuilds ADR 0008 cleanly.New tests:
test_learner_statuses_api.pycovers 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, everydemonstrated_in_coursecase (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.pypins the default's self-only behavior, the identical bare 404s with no database lookup, and per-call setting reload.test_learner_statuses_views.pypins the check order with a recording resolver (including that the resolver receives the parsed plain course key and anintorNone, and is not called for a malformed key or a badlearner_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 onHttp404orNotFound, 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):
/api/cbe/v1/courses/<course run key>/competency-statuses/: your criterion and competency statuses for that run, withdemonstrated_in_coursenaming another run only where you demonstrated the competency there.?learner_id=<someone else's id>: a bare 404, identical to?learner_id=999999.Deadline
None.
Other information
lms/includesopenedx_learning's learner URLs. The learner surface needs three openedx-platform pieces: thelearner_urlsinclude (feat: let enrolled learners and course staff read a course run's competency criteria openedx/openedx-platform#39415, open), theview_course_competency_criteriapermission override from [BE] GET Competency Criteria for Course openedx/openedx-core#733, and the learner resolver with itsOPENEDX_LEARNING_LEARNER_RESOLVERsetting (feat: resolve the competency-statuses learner for the LMS openedx/openedx-platform#39425); until all three land and a core release ships this route, nothing serves it. Once served without the setting, the built-in default is self-only, which is safe but stricter than the Progress tab.demonstrated_in_courseshows a permitted caller (course staff, once the LMS resolver lands) the key and title of another course run where the learner demonstrated the competency, possibly another organization's; the LMS staff path can also name any existing user, enrolled or not, because statuses are global. The ticket's "Known limitations" section records this, and ADR 0008's Consequences state it for host resolvers.competency_statusesandcriterion_statuses. The names are new with this UNSTABLE surface; [FE] Display Subsection Competency Statuses for Learner in Course openedx/openedx-core#739/[FE] Display Competency Statuses for Learner in Course openedx/openedx-core#740 should build against them.lineageis a list of tag values while this payload keys ancestor statuses by tag id; the frontend join needs ids in the lineage, which is raised on feat: GET a course run's competency criteria for the learner Progress tab openedx/openedx-core#945 rather than changed here.🤖 Generated with Claude Code