Repository navigation
enrollments(pin): enrollment pinning and minimal user creation - #20
Conversation
Complete Milestone 2: migration 0005 adds enrollments pinning published program versions, with the database refusing drafts and silent version repointing outright. A deliberately minimal user-creation path (manage_users) issues first credentials through the existing reset-code flow; enrollment (assign_training) gains API endpoints, an Enrollments panel on published versions, and a create-user card on the status page. The milestone exit is proven by test: a complete invented program published, a trainee enrolled, the version exported, and reproduced byte-identically on a clean installation — then published and enrolled there too. Refs #19
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f38eb0c0b6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| tx.commit().await?; | ||
|
|
||
| let issued = issue_reset_code( |
There was a problem hiding this comment.
Keep account creation and initial code atomic
If the process stops or storing/auditing the reset code fails after this commit, the API returns no credential but leaves behind an account whose random password is unknowable; retrying creation then reports username_taken. Create the user, initial reset code, and both audit events in one transaction so a failed request cannot leave an unusable partial account.
Useful? React with 👍 / 👎.
| let mut tx = pool.begin().await?; | ||
| let user_id = create(&mut tx, username, display_name, &password_hash).await?; |
There was a problem hiding this comment.
Return UsernameTaken for insert-time conflicts
When two authorized requests create the same case-insensitive username concurrently, both can pass the preflight lookup before the expensive password hash runs; the unique index rejects the second create, but this error bubbles out as a 500 instead of the documented username_taken conflict. Translate the insert's unique-constraint violation to CreateUserRefusal::UsernameTaken rather than relying only on the racy lookup.
Useful? React with 👍 / 👎.
| loadEnrollment().catch(() => { | ||
| enrollees = []; | ||
| roster = []; | ||
| }); |
There was a problem hiding this comment.
Surface enrollment-load failures instead of an empty roster
If either enrollment or user-roster request fails, including on a transient server/network error, this catch converts the failure into two empty arrays without displaying an error. The panel consequently tells the coordinator that nobody is enrolled and offers no trainees even when records exist, so preserve the prior data or render a distinct load-error state instead.
Useful? React with 👍 / 👎.
Primary Issue
Closes #19
Closes #12
Problem And Outcome
The Milestone 2 exit — "a complete invented training program can be published, enrolled, exported, and reproduced" — lacked enrollment, and enrolling needed trainees to exist. After merge, an administrator creates a trainee whose first credential is a one-time reset code through the existing, tested reset mechanism (no new secret paths), and anyone holding
assign_trainingenrolls them in a published version. The database itself refuses enrollment in a draft, and the milestone exit is now a passing test.Changes
Server
0005_enrollments.sql:enrollment(trainee, pinnedprogram_version, enrolled_at/by), UNIQUE per (user, version) — the honest minimal contract until Milestone 3 models lifecycle history — plus two triggers: enrollment in an unpublished version is refused outright, and repointing an enrollment's version is refused because version changes are explicit modeled events (Milestone 3), never silent UPDATEs.src/enrollments.rs:enrollandlist_for_version, both gated onassign_training(enrollment is personnel-adjacent, so reads take the same capability), auditing each enrollment with the actor, the trainee (subject_user_id), and the enrollment row (subject_kind/subject_id).src/users.rs:UserSummary/listfor rosters andcreate_with_reset_code— the account starts with the hash of a random secret nobody sees, then a standard administrator-origin reset code is issued so first sign-in flows through the existing reset path.src/audit.rsgainsuser_created/enrollment_createdkinds, anEnrollmentsubject, andrecord_for_subjectnow also carries a user subject.GET/POST /api/users(manage_usersto create;manage_usersorassign_trainingto read the roster) andGET/POST /api/program-versions/{id}/enrollments, with stable codesusername_invalid,username_taken,not_published,already_enrolledjoining the existing vocabulary.tests/enrollments.rs: five tests — the created-user-signs-in-through-reset flow end to end, creation refusals and roster gates, service+raw-SQL draft refusal with audit attribution, refusal codes and the repoint trigger, andmilestone_two_exit_publish_enroll_export_reproduce: a complete invented program (phases with a remediation loop, tasks, all three scale kinds, a modifier, forms, citations at every level) published, a trainee enrolled, the version exported, reproduced byte-identically on a clean installation, then published and enrolled there too.Interface
manage_userssection, presenting the one-time first-sign-in code the same way reset codes are presented (its label change required oneexact: truelocator fix in the shell e2e).assign_trainingholders — current enrollees and a roster picker that excludes the already-enrolled.Scope
Verification
Review And Merge Notes
users::create_with_reset_code(unusable random hash + standard reset issuance, nothing new invented), and the two enrollment triggers in0005_enrollments.sql.assign_trainingholders gain enrollment on published versions. Existing installations migrate additively on next start. This completes Milestone 2.Generated by Claude Code