Skip to content

feat(admin): user management CRUD — pagination, search/filter, createUser, expanded updateUser - #51

Closed
voidvec wants to merge 3 commits into
feat/resource-scope-authorization-43from
feat/user-management-crud
Closed

voidvec wants to merge 3 commits into
feat/resource-scope-authorization-43from
feat/user-management-crud

Conversation

@voidvec

@voidvec voidvec commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Summary

A2 user-management补全 (全栈). Implements the highest-ROI IAM gap from next-phase-implementation-plan.md §A2.

Stacked on PR #49 (feat/resource-scope-authorization-43) — the #43 scope infrastructure (EndpointInfo.requiredScopes + AuthorizationFilter scope gate) is a hard dependency for the new endpoints' authorization. Rebase to master after #49 merges.

Backend

Change Detail
listUsers pagination Real pagination via Mapper::count + paginate().findBy. Query params: page, per_page (clamp 1-100), q (username/email LIKE), role (JOIN-free fan-out: Roles→UserRoles→userIds), locked (derived from locked_until vs current time). Response: {page, per_page, total, total_pages, users}
createUser (POST) PBKDF2-SHA256 password hash + default user role + audit log (user_create). Returns 201 with created user JSON. Duplicate username → VALIDATION_USERNAME_TAKEN
updateUser expanded Now accepts username, mfa_enabled, locked, org_id (was email + email_verified only). Audit on success (user_update)
AuthorizationFilter Persists userId/scope/clientId onto request attributes (was only done by OAuth2AuthFilter). Enables admin handlers to identify the actor for audit logging
OpenAPI Added POST /api/admin/users with request schema; added query params on GET list

Frontend

Change Detail
UsersPage.vue Pagination controls (prev/next + page indicator), search bar (q), role/locked filter dropdowns, "Create User" modal (username/password/email/roles)
UserDetailPage.vue Info tab expanded: username, mfa_enabled, locked, org_id now editable (was email + email_verified only)
mock-api.ts GET handler returns paginated envelope; POST handler with duplicate detection
e2e tests 5 new cases: create modal, create success, search filter, duplicate username error

Not in scope (Phase 2)

deleteUser (soft-delete) requires V024 migration + ORM model regen (/orm-gen, user-only skill). Documented as the immediate next step.

Verification

  • ✅ Backend compiles on Windows (MSVC Release, no warnings from new code)
  • ✅ Test binary compiles
  • ✅ api-diff: additive only (ratified baseline — no version bump)
  • ✅ arch-guard: PASS
  • ✅ migration-check: PASS (no new migrations)
  • ✅ Frontend: npm run build (tsc + vite) PASS
  • ✅ Frontend: npm run test:unit (vitest) PASS
  • ⏳ Backend integration tests: require PostgreSQL (CI Linux leg)

Dependencies on async/DB rules (.claude/rules/db-operations.md)

All new Mapper constructions (including nested ones in async callbacks) are wrapped in try/catch → (*cb)(errorResult), making the new code more compliant than the pre-existing admin code.

…User, expanded updateUser (#A2)

Backend:
- listUsers: real pagination (page/per_page, total count via Mapper::count),
  search (q on username/email), filters (role via JOIN-free fan-out,
  locked derived from locked_until)
- createUser (POST /api/admin/users): PBKDF2 hash + default role assignment +
  audit log (user_create); 201 Created response
- updateUser: expanded to username, mfa_enabled, locked, org_id
  (was email + email_verified only)
- AuthorizationFilter: persist userId/scope/clientId onto request attributes
  (was only done by OAuth2AuthFilter) so admin handlers can identify the actor
- OpenAPI: added POST /api/admin/users + query params on GET list

Frontend:
- UsersPage: pagination controls, search bar, role/locked filters,
  Create User modal (username/password/email/roles)
- UserDetailPage: Info tab expanded — username, mfa_enabled, locked,
  org_id now editable (was email + email_verified only)
- mock-api: paginated GET handler + POST create mock with duplicate detection
- e2e: create-user, search-filter, duplicate-username test cases

Tests:
- AdminUserApiHttpTest: 7 new cases (create success/dup/missing, pagination,
  search, expanded update, locked filter)

Stacked on PR #49 (feat/resource-scope-authorization-43); rebase to master
after #49 merges.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

…User/updateUser

Code review (PR #51): the previous generic 'unique'/'duplicate' substring
match always reported VALIDATION_USERNAME_TAKEN even for duplicate emails.
Now matches constraint names (users_username_key / idx_users_email_unique)
like AuthService and PostgresIdentityRepository already do.
…minUserId, unique suffix

- DuplicateUsername test: VALIDATION_USERNAME_TAKEN maps to HTTP 409 (not 400)
- findAdminUserId: use ?q=admin search to find admin user across pages (admin
  user is at id=513, not page 1 of default per_page=50)
- uniqueSuffix: use 9-digit modulo to avoid collisions across rapid re-runs
- mock-api: POST duplicate returns 409 to match backend

All 16 AdminUser tests pass with local PostgreSQL (7 new + 9 existing).
@voidvec

voidvec commented Aug 14, 2026

Copy link
Copy Markdown
Owner Author

Replaced by new PR rebased on latest master (feat/user-management-crud-v2)

@voidvec voidvec closed this Aug 14, 2026
voidvec added a commit that referenced this pull request Aug 14, 2026
…User/updateUser

Code review (PR #51): the previous generic 'unique'/'duplicate' substring
match always reported VALIDATION_USERNAME_TAKEN even for duplicate emails.
Now matches constraint names (users_username_key / idx_users_email_unique)
like AuthService and PostgresIdentityRepository already do.
@voidvec
voidvec deleted the feat/user-management-crud branch August 14, 2026 11:02
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.

1 participant