Skip to content

enrollments(pin): enrollment pinning and minimal user creation - #20

Merged
TusanHomichi merged 1 commit into
mainfrom
claude/status-check-wwwfh6
Aug 28, 2026
Merged

TusanHomichi merged 1 commit into
mainfrom
claude/status-check-wwwfh6

Conversation

@TusanHomichi

Copy link
Copy Markdown
Member

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_training enrolls them in a published version. The database itself refuses enrollment in a draft, and the milestone exit is now a passing test.

Changes

Server

  • Migration 0005_enrollments.sql: enrollment (trainee, pinned program_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: enroll and list_for_version, both gated on assign_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/list for rosters and create_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.rs gains user_created/enrollment_created kinds, an Enrollment subject, and record_for_subject now also carries a user subject.
  • API: GET/POST /api/users (manage_users to create; manage_users or assign_training to read the roster) and GET/POST /api/program-versions/{id}/enrollments, with stable codes username_invalid, username_taken, not_published, already_enrolled joining 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, and milestone_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

  • Status page: a "Create a user" card in the existing manage_users section, presenting the one-time first-sign-in code the same way reset codes are presented (its label change required one exact: true locator fix in the shell e2e).
  • Published version pages: an Enrollments panel for assign_training holders — current enrollees and a roster picker that excludes the already-enrolled.
  • The programs e2e now creates a trainee from the status page and enrolls them in the published version through the panel.

Scope

  • In scope: enrollment pinning, minimal user creation, their API, interface, and tests.
  • Out of scope: enrollment lifecycle (phase history, version changes with reason, withdrawal, concurrency policy) and user administration beyond creation — Milestone 3.

Verification

  • Listed the exact verification commands run below
  • Added or updated tests when behavior changed
  • Added or updated an ADR when a durable decision changed (none changed; implements ADR 0007's enrollment rule)
  • All fixtures and examples are invented; no real agency data
web/: npm run check                                      # 0 errors, 0 warnings
web/: npm run build                                      # clean
web/: CONSOLEBOOK_E2E_CHROMIUM=… npm run e2e             # 2 passed (shell + programs w/ enrollment)
cargo fmt --check                                        # clean
cargo clippy --workspace --all-targets -- -D warnings    # clean (pedantic)
cargo test --workspace                                   # 11 suites, 62 tests, 0 failed

Review And Merge Notes

  • Review focus: the credential story in users::create_with_reset_code (unusable random hash + standard reset issuance, nothing new invented), and the two enrollment triggers in 0005_enrollments.sql.
  • User or operator impact: administrators gain user creation; assign_training holders gain enrollment on published versions. Existing installations migrate additively on next start. This completes Milestone 2.

Generated by Claude Code

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-08-28T22:07:12.325850Z f38eb0c PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@TusanHomichi
TusanHomichi merged commit 756ca16 into main Aug 28, 2026
1 check passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +177 to +179
tx.commit().await?;

let issued = issue_reset_code(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +168 to +169
let mut tx = pool.begin().await?;
let user_id = create(&mut tx, username, display_name, &password_hash).await?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +153 to +156
loadEnrollment().catch(() => {
enrollees = [];
roster = [];
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

Milestone 2 slice 3: enrollment pinning and minimal user creation Milestone 2 design: versioned program configuration schema (owner decisions needed)

2 participants