feat: admin auth, users and roles (change 2) #3

Merged
ngqile merged 19 commits from add-admin-auth-users-roles into main 2026-11-26 14:40:32 +00:00
Owner

OpenSpec change add-admin-auth-users-roles.

What

  • mobile-api /api/admin/**: login, me, logout, first-login, forgot password; users (list, create, edit, deactivate, emailed reset); roles (list, create, rename, module grants). Enforced in AppAccessAspect: admin token only, logged-out and deactivated tokens refused, pending first login confined, @AdminModule checked against the caller's roles, super admin passes.
  • Self-escalation closed (from the branch review): a non-super admin cannot change their own roles or the grants of a role they hold; ROLE_ADMIN / ROLE_MEMBER cannot be assigned; no direct set-password endpoint, only the emailed reset.
  • services-auth: findUserByToken returns nothing for a logged-out token.
  • services-system: user.company_id, company table, Area.BO, roles saved without cascade, resetAdminPassword refuses disabled users.
  • api-gateway: /user/resetAdminPassword reachable without a user token (forgot password).
  • Admin portal: cut down to login, first login, forgot password, users, roles, role access, not-authorised.
  • SQL in the change folder (company, BO modules, rollback), mirrored in local/seed/; smoke check logs in through mobile-api.

Verification

  • mvn -T 1C -B -q verify: exit 0.
  • Portal: vitest 850/850, tsc --noEmit clean, lint 0 errors.
  • openspec validate add-admin-auth-users-roles --strict: valid.
  • Local stack: local/smoke.sh OK; browser check with screenshots in openspec/changes/add-admin-auth-users-roles/verification/; own-role, hidden-role and removed-endpoint rules checked live.

Known follow-ups

  • Forgot password has no rate limit and its timing differs on a match (accepted for phase 1).
  • User list loads in memory and is not company-scoped.
  • A refreshed-away token stays valid until it expires.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM

OpenSpec change `add-admin-auth-users-roles`. ## What - **mobile-api `/api/admin/**`**: login, me, logout, first-login, forgot password; users (list, create, edit, deactivate, emailed reset); roles (list, create, rename, module grants). Enforced in `AppAccessAspect`: admin token only, logged-out and deactivated tokens refused, pending first login confined, `@AdminModule` checked against the caller's roles, super admin passes. - **Self-escalation closed** (from the branch review): a non-super admin cannot change their own roles or the grants of a role they hold; `ROLE_ADMIN` / `ROLE_MEMBER` cannot be assigned; no direct set-password endpoint, only the emailed reset. - **services-auth**: `findUserByToken` returns nothing for a logged-out token. - **services-system**: `user.company_id`, `company` table, `Area.BO`, roles saved without cascade, `resetAdminPassword` refuses disabled users. - **api-gateway**: `/user/resetAdminPassword` reachable without a user token (forgot password). - **Admin portal**: cut down to login, first login, forgot password, users, roles, role access, not-authorised. - **SQL** in the change folder (company, BO modules, rollback), mirrored in `local/seed/`; smoke check logs in through mobile-api. ## Verification - `mvn -T 1C -B -q verify`: exit 0. - Portal: vitest 850/850, `tsc --noEmit` clean, lint 0 errors. - `openspec validate add-admin-auth-users-roles --strict`: valid. - Local stack: `local/smoke.sh` OK; browser check with screenshots in `openspec/changes/add-admin-auth-users-roles/verification/`; own-role, hidden-role and removed-endpoint rules checked live. ## Known follow-ups - Forgot password has no rate limit and its timing differs on a match (accepted for phase 1). - User list loads in memory and is not company-scoped. - A refreshed-away token stays valid until it expires. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
ngqile added 19 commits 2026-11-26 14:40:28 +00:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Change SQL in the OpenSpec change folder, mirrored into local/seed.
Local seed keeps only roles 1-3; dev admin no longer needs a first-login change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Ported from babyboo: @AdminModule, AdminModuleAccess, AdminSessionGuard and the
admin branch of AppAccessAspect. Adds the BO area, and services-auth findUserByToken
now returns no user for a logged-out token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Wrong, blank or failed logins all answer the same 401. A deactivated admin is
refused and the token services-auth issued is revoked. resetAdminPassword now
refuses deactivated users and users without an email.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
New users get a temporary password by email and the creating admin's company.
Self-deactivation and super-admin changes by non-super admins are refused.
services-system: saving a user no longer cascades into role rows.
Local seed: dev admin on the GLOBAL branch (id 0 does not exist).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Member and ROLE_ADMIN roles are hidden; super admin grants are not editable;
removing your own last BO_ROLES grant is refused. Renaming keeps child roles intact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Removes every other screen, API route, component, test and the dependencies only
they used. Cookie colite_admin, Co-Lite branding, BO_USERS/BO_ROLES modules only.
The user form no longer loads branches, events or country scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
/forgot-password always shows the same message; the route never forwards upstream
errors or a token. /api/admin/me now returns id and username so the user form can
lock the Active switch on your own account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Found in the browser check: forgot-password always failed with 401 at the gateway,
so no temporary password was ever sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
- Login copy describes the event CRM instead of orders and payouts.
- Role dialog has no parent field; the role routes require a trimmed name and forward only {name}.
- New-user banner says a temporary password was emailed; TEMP_PASSWORD_NOT_SENT shows a message and a link back to users.
- Username is read-only when editing.
- Password hint and an 8-character minimum match the backend admin password rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
A non-super admin cannot change their own roles or the grants of a role they hold,
hidden roles cannot be assigned, and the direct set-password endpoint goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
An admin could set a colleague's password to a value of their choosing. Only the
emailed temporary-password reset remains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
- A non-super admin cannot change the roles on their own account (403 OWN_ROLES).
- ROLE_ADMIN and ROLE_MEMBER cannot be assigned (400 UNKNOWN_ROLE, as if absent).
- A non-super admin cannot change the grants of a role they hold (403 OWN_ROLE);
  this replaces the BO_ROLES lock-out check, which it makes unreachable.
- POST /api/admin/users/{id}/changePassword is removed; the emailed reset stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
services-system writes a role already seen in a response as its bare id. The
module check missed it, so a role granted two modules was refused the second;
the super-admin target guard now reads it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
ngqile merged commit 5d63b2bbec into main 2026-11-26 14:40:32 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ngqile/co-lite#3