feat(person): admin account-level endpoint (#33)#147
Merged
Conversation
POST /api/people/:slug/account-level — administrator-only, the sole path
for changing accountLevel (never via the generic PATCH), so the privilege
change is explicit and audit-logged.
- Write service setAccountLevel: requireAuth('administrator'); idempotent
no-op when unchanged; last-administrator guard (refuse to demote the only
administrator → 422, prevents lock-out).
- Route sets Action: account-level.change + Previous-Account-Level /
New-Account-Level audit trailers; returns the updated person (200).
- Spec promoted from a deferred stub to a full section. Corrected the
bad-body error to 422 (this app maps Fastify schema-validation errors to
422, not 400) — caught by the test.
Tests (10): authz matrix, invalid level, promote/demote, idempotent no-op,
last-admin 422, demote-with-second-admin, and the audit-trail trailers.
type-check + lint clean; people suites 24/24.
Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Implements #33 —
POST /api/people/:slug/account-level(administrator-only), the sibling admin verb to the deactivate/reactivate/purge work.What
accountLevel— a dedicated, audit-logged endpoint, not a field on the genericPATCH— so privilege changes are explicit.Action: account-level.change+Previous-Account-Level/New-Account-Leveltrailers.Spec
specs/api/people.md— promoted from a deferred stub to a full section (request/response/audit/guard/errors). Corrected the bad-body error from400to422to match this app's schema-validation mapping (the test caught it).Tests (10)
authz matrix (401/403×2/200), invalid level → 422, promote/demote reflected, idempotent no-op, last-admin self-demotion → 422, demote-with-second-admin → 200, and the audit-trail trailers (asserted against the bare repo's HEAD commit). type-check + lint clean; people suites 24/24.
Closes #33
🤖 Generated with Claude Code