diff --git a/openspec/changes/add-admin-auth-users-roles/design.md b/openspec/changes/add-admin-auth-users-roles/design.md index 4299fd6..88d5d05 100644 --- a/openspec/changes/add-admin-auth-users-roles/design.md +++ b/openspec/changes/add-admin-auth-users-roles/design.md @@ -47,7 +47,7 @@ The emailed password is plain text in the email body. That is Tastefully's exist ### 5. Company -`service-system` gets `company (id, name, created_at)` and `user.company_id BIGINT NULL` (nullable because member rows share the table). `services-system` `User` gains `companyId`. `AdminUserService.create` sets `companyId` from the logged-in admin, ignoring any value in the request. The seed sets company 1 on the dev admin. +`service-system` gets `company (id, name, create_date)` and `user.company_id BIGINT NULL` (nullable because member rows share the table). `services-system` `User` gains `companyId`. `AdminUserService.create` sets `companyId` from the logged-in admin, ignoring any value in the request. The seed sets company 1 on the dev admin. ### 6. Co-Lite back-office modules @@ -72,6 +72,8 @@ Delete by directory: every `app/` route, `app/api/` family, `app/components/` fo - [Deleting most of the portal breaks shared imports in ways tests miss] → `npm run build` and `npm run lint` must pass, not only `vitest`. - [Forgot-password takes longer when the details match (bcrypt plus an email), so timing can hint at a match] → Accepted for phase 1; the body is identical either way. - [services-auth issues a token to a deactivated admin] → The admin login checks `enabled` and revokes that token before answering 401; `/user/resetAdminPassword` now refuses deactivated users. +- [A non-super admin with `BO_USERS` or `BO_ROLES` could use one module to gain the other] → A non-super admin cannot change their own roles or the grants of a role they hold, and nobody can assign `ROLE_ADMIN` or `ROLE_MEMBER`. They can still give a colleague any visible role; a subset rule (assign only what you hold) is deferred. +- [The gateway token bypass for `/user/resetAdminPassword` returns the updated-row count (1 or 0) to anyone with a gateway api-key allowed on `/user/`] → Gateway keys stay internal (mobile-api only); the public endpoint in mobile-api always answers the same. - [Plain-text temporary password in email] → Forced change at next login; revisit with real SMTP in change 5. ## Migration Plan diff --git a/openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md b/openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md index 6749135..9c881fc 100644 --- a/openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md +++ b/openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md @@ -23,7 +23,7 @@ The system SHALL let an admin with `BO_ROLES` list, create and rename admin role ### Requirement: Role permissions -The system SHALL let an admin with `BO_ROLES` choose, for a role, which back-office modules it grants, shown as the module tree. Saving SHALL replace the role's module grants with the chosen set. The grants of the super admin role and of `ROLE_ADMIN` SHALL NOT be editable. +The system SHALL let an admin with `BO_ROLES` choose, for a role, which back-office modules it grants, shown as the module tree. Saving SHALL replace the role's module grants with the chosen set. The grants of the super admin role and of `ROLE_ADMIN` SHALL NOT be editable. An admin who is not super admin SHALL NOT change the grants of a role they hold. #### Scenario: Grant Users module @@ -32,11 +32,11 @@ The system SHALL let an admin with `BO_ROLES` choose, for a role, which back-off - **THEN** users with `ROLE_SALES` see Users in the sidebar after their next login or session refresh - **AND** `GET /api/admin/users` responds 200 for them -#### Scenario: Self lock-out +#### Scenario: Own role -- **GIVEN** the admin's only role that grants `BO_ROLES` is the role being edited -- **WHEN** they remove `BO_ROLES` from it and save -- **THEN** the save is refused with a message, so no admin loses access to role management by mistake +- **GIVEN** an admin who is not super admin and holds `ROLE_SALES` +- **WHEN** they change the module grants of `ROLE_SALES` and save +- **THEN** the save is refused with a message, so no admin can widen their own access or lock themselves out of role management ### Requirement: Back-office module set diff --git a/openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md b/openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md index e7556db..277f370 100644 --- a/openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md +++ b/openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md @@ -35,7 +35,7 @@ The system SHALL let an admin with `BO_USERS` create an admin user with name, us ### Requirement: Edit and deactivate user -The system SHALL let an admin with `BO_USERS` change a user's name, email, roles and active state. A deactivated user SHALL NOT be able to log in, and a session they already hold SHALL be refused on its next `/api/admin/**` call. An admin SHALL NOT be able to deactivate their own account. +The system SHALL let an admin with `BO_USERS` change a user's name, email, roles and active state. A deactivated user SHALL NOT be able to log in, and a session they already hold SHALL be refused on its next `/api/admin/**` call. An admin SHALL NOT be able to deactivate their own account. An admin who is not super admin SHALL NOT change the roles on their own account. No admin SHALL assign `ROLE_ADMIN` or `ROLE_MEMBER` when creating or editing a user. #### Scenario: Deactivate @@ -49,9 +49,20 @@ The system SHALL let an admin with `BO_USERS` change a user's name, email, roles - **WHEN** an admin tries to deactivate their own account - **THEN** the save is refused with a message +#### Scenario: Own roles + +- **GIVEN** an admin who is not super admin and holds `ROLE_SALES` +- **WHEN** they save their own account with a different set of roles +- **THEN** the save is refused with a message and their roles are unchanged + +#### Scenario: Hidden roles + +- **WHEN** an admin creates or edits a user with `ROLE_ADMIN` or `ROLE_MEMBER` in the roles +- **THEN** the save is refused with a message + ### Requirement: Admin-triggered password reset -The system SHALL let an admin with `BO_USERS` reset another user's password, which emails the user a temporary password and requires a change at next login. +The system SHALL let an admin with `BO_USERS` reset another user's password, which emails the user a temporary password and requires a change at next login. The system SHALL NOT let an admin set another user's password to a value the admin chooses. #### Scenario: Reset @@ -59,6 +70,11 @@ The system SHALL let an admin with `BO_USERS` reset another user's password, whi - **THEN** `sales1`'s old password stops working - **AND** a temporary password is emailed to `sales1`'s email address +#### Scenario: No direct password set + +- **WHEN** an admin calls `POST /api/admin/users/{id}/changePassword` +- **THEN** the endpoint does not exist and no password changes + ### Requirement: Company membership Every admin user SHALL belong to exactly one company. The company SHALL be set by the system from the creating admin, never from the request. diff --git a/openspec/changes/add-admin-auth-users-roles/tasks.md b/openspec/changes/add-admin-auth-users-roles/tasks.md index ac1ac97..08e485b 100644 --- a/openspec/changes/add-admin-auth-users-roles/tasks.md +++ b/openspec/changes/add-admin-auth-users-roles/tasks.md @@ -43,6 +43,13 @@ Babyboo source: `~/Projects/babyboo` (read only). All tasks run serially; most t - [x] 7.2 Drive the portal in a browser with Playwright against the local stack: login (correct and wrong password), first-login change for a new user, users list/create/edit/deactivate, roles create and grant `BO_USERS`, not-authorised page for a user without `BO_ROLES`, forgot-password message. Screenshots in the change folder's `verification/`. Only local dev data is created. Verify: each scenario observed as specified. - Scope: `openspec/changes/add-admin-auth-users-roles/verification/**` +## 8. Review follow-up: close self-escalation + +- [ ] 8.1 In `mobile-api`: delete `POST /api/admin/users/{id}/changePassword` and `AdminUserService.changePassword`; in `AdminUserService` refuse (403, `OWN_ROLES`) a non-super caller whose update changes the role set on their own account, and refuse (400, `UNKNOWN_ROLE`) `ROLE_ADMIN` or `ROLE_MEMBER` on create and update; in `AdminAclService.updateGrants` refuse (403, `OWN_ROLE`) a non-super caller editing a role they hold, and delete `requireNoLockout`, which that rule makes unreachable. Tests first for each new scenario. Verify: `mvn -T 1C -B -q -pl solvway-mobile-api -am verify` exits 0. + - Scope: `solvway-mobile-api/src/**/admin/**`, `solvway-mobile-api/src/**/service/Admin*` +- [ ] 8.2 In the portal: delete the change-password route, `ChangePasswordDialog`, `changeAdminUserPassword` and the button on the edit-user page; the emailed reset stays. Verify: `npm run lint && npx tsc --noEmit && npx vitest run` exit 0. + - Scope: `solvway-admin-portal/**` + ## Workflow follow-up - Code review, PR to `main`, merge, then archive this change.