refactor(server): move the access handlers' SQL into repositories - #48
Merged
Merged
Conversation
fylorn
force-pushed
the
refactor/server-access-repositories
branch
from
September 24, 2026 09:13
dc0de4b to
363c9a6
Compare
The API key, auth, SSO, setup and OIDC/settings handlers no longer carry SQL. Their 48 statements move verbatim into services::api_key_repository, auth_repository, setup_repository and settings_repository; the key-rotation and account-deletion transactions move with them. Handlers keep permission checks, validation, audit, and session / cache work. admin_access.rs adds integration tests for what no test reached: key create / read / PATCH semantics and validation, list paging and the archived view, revoke / force-revoke, expiring keys, cost centers, the default-expiry setting, registration with a default role, /me roles and teams, TOTP status, and SSO sign-in against a mock identity provider (activation, provisioning, re-login, refused accounts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn
force-pushed
the
refactor/server-access-repositories
branch
from
September 24, 2026 09:41
363c9a6 to
d651ccf
Compare
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.
Next per-domain PR after #45 taking SQL out of
crates/server/src/handlers. This one covers access:api_keys.rs(18 statements),auth.rs(17),setup.rs(7),sso.rs(3),admin/oidc.rs(2),admin/settings.rs(1) — 48 in all. None of these handlers carries SQL any more.What moved
services::api_key_repository—api_keys: owner lookup, live lookup, the list (count + page, all users or one, live or revoke-archived), insert, the PATCH update, revoke / force-revoke, rotation (its transaction now lives here), expiring keys, cost centers; plus themcp_user_credentialscheck behindmcp_account_overrides.services::auth_repository— what login, registration,/me, password change, TOTP, account deletion and SSO read and write: user lookups (by email, id, OIDC identity), the recovery-code compare-and-swap, the registration insert (on the handler's transaction), the SSO insert, the default-role assignment (shared by registration and SSO; takes any executor), teams and role assignments for/me, and the account soft-delete transaction.services::setup_repository— the first-boot wizard: advisory lock, the DBsetup.initializedread, and the admin + key + settings writes, all on the handler's transaction (it still holds the lock across validation and hashing, as before).services::settings_repository— deleting the OIDC draft, and the role-exists check behindauth.default_role.Statements are carried over verbatim with the same binds and fetch kinds. The one textual difference: the default-role
INSERT … SELECTwas written twice (register, SSO) with different indentation and is now one function. Handlers keep permission checks, validation, audit, Redis / session / cache work and response shaping. No row types needed moving (the queries returnApiKey,Userand tuples);openapi.rsis unchanged.No behaviour change — checked
crates/test-support/tests/admin_access.rsadds integration tests for what no test reached:auth.default_rolevalidation, registration assigning the default role, duplicate registration,/merole assignments and teams order, TOTP status;jsonwebtokenadded as a test-support dev-dependency): wizard activation (draft dropped), first sign-in provisioning with normalised email and default role, re-sign-in to the same row, the placeholder email for an identity without one, deactivated / deleted accounts refused.They pass against the code before this change and after it. Login, refresh, password change, TOTP setup / disable / recovery, account deletion, setup and rotation were already covered (
auth.rs,totp_recovery.rs,setup_wizard_e2e.rs,api_key_rotation.rs,oidc_wizard.rs, …) and pass too.Checks
fmt, clippy (
--all-targets,--lib), 687 unit tests, full integration suite on own containers (293 passed).🤖 Generated with Claude Code