# Tasks Babyboo source: `~/Projects/babyboo` (read only). All tasks run serially; most touch shared security code or build files. ## 1. Database - [x] 1.1 Write `sql/01-company.sql` (create `company`, add nullable `user.company_id`, insert company 1 'Co-Lite'), `sql/02-bo-modules.sql` (`40000000 BO_ROOT` R, `40700000 BO_USERS` `/users`, `40800000 BO_ROLES` `/roles`, area `BO`) and `sql/99-rollback.sql` in this change folder. Mirror them into `local/seed/` (`03-colite.sql` sets `company_id = 1` on the dev admin; `02-reference.sql` keeps only roles 1, 2, 3 and their `modules_roles` rows). Verify: `docker compose -f local/docker-compose.yml down -v && local/up.sh` exits 0, and a read-only SELECT shows the admin with company 1, the three BO modules and three roles. - Scope: `openspec/changes/add-admin-auth-users-roles/sql/**`, `local/seed/**` ## 2. services-system - [x] 2.1 Add `companyId` to `services-system` `User` (column `company_id`) and make `/user/save` keep it. Test first: saving a user with `companyId` 1 and reading it back returns 1; saving an existing user without `companyId` does not clear it. Verify: `mvn -T 1C -pl solvway-services-system -am verify`. - Scope: `solvway-services-system/src/**` ## 3. mobile-api admin guard - [ ] 3.1 Port `AdminModule`, `AdminModuleAccess`, `AdminSessionGuard` and the admin branch of babyboo's `AppAccessAspect` (admin-path detection, admin-token check via `/auth/findUserByToken/BO/{token}`, revocation, deactivated and pending-reset handling, `requireAdminModule` with super-admin bypass, fail closed) into Co-Lite's `AppAccessAspect`, without country scope or audit. Port babyboo's tests for these classes and add tests for every `admin-access` "Admin endpoint guard" and "Logout" scenario plus: deactivated token gives 401, pending reset gives 403 except first-login and logout, undeclared handler denied to non-super admin. Verify: `mvn -T 1C -pl solvway-mobile-api -am verify`. - Scope: `solvway-mobile-api/src/main/java/**/useraccess/**`, `solvway-mobile-api/src/test/java/**/useraccess/**`, `solvway-mobile-api/src/main/resources/application*.yml` ## 4. mobile-api admin auth - [ ] 4.1 Port babyboo's `AdminAuthController` and `AdminAuthenticationService` (login, first-login, logout, refresh, me) onto Co-Lite endpoints, and add `POST /api/admin/auth/forgot-password` calling `/user/resetAdminPassword`. Login answers 401 for an empty token, a deactivated user or a non-admin account; forgot-password always answers 200. Port babyboo's tests for these classes and add one per `admin-access` login, first-login and forgot-password scenario. Verify: `mvn -T 1C -pl solvway-mobile-api -am verify`. - Scope: `solvway-mobile-api/src/**/controller/admin/**`, `solvway-mobile-api/src/**/service/admin/**`, `solvway-mobile-api/src/**/dto/admin/**` (or babyboo's equivalent packages) ## 5. mobile-api users and roles - [ ] 5.1 Port `AdminUserController` and `AdminUserService`: admin-only list with search, filter and sort; create with temporary password, email and company from the logged-in admin; edit; deactivate with self-deactivation refused; admin-triggered reset via `/user/resetAdminPassword`. Tests first for each `admin-users` scenario. Verify: `mvn -T 1C -pl solvway-mobile-api -am verify`. - Scope: as 4.1 - [ ] 5.2 Port `AdminRoleController`, `AdminRoleService` and `AdminAclService` (role list hiding `ROLE_MEMBER`, create and rename with unique names, `GET/PUT /roles/{id}/modules` replacing grants, self lock-out refused, super admin grants not editable). Tests first for each `admin-roles` scenario. Verify: `mvn -T 1C -pl solvway-mobile-api -am verify`. - Scope: as 4.1 ## 6. Admin portal - [ ] 6.1 Cut the portal down to login, reset-password (first login), users, roles, roles access, not-authorised and the app shell: delete every other `app/` route, `app/api/` family, component folder, lib file and test, then remove `package.json` dependencies with no remaining import and their i18n keys. Cut `routeModules` and `FIXED_PROTECTED_MODULE_NAMES` to `BO_ROOT`, `BO_USERS`, `BO_ROLES`; default cookie `colite_admin`; replace babyboo branding text. Verify: in `solvway-admin-portal`, `npm ci && npm run lint && npm run build && npm test` all exit 0. - Scope: `solvway-admin-portal/**` - [ ] 6.2 Add the `/forgot-password` page (public, linked from login) and its route handler calling `/api/admin/auth/forgot-password`, showing the fixed message for any outcome; make the users form refuse self-deactivation and show duplicate-username and lock-out errors from the API. Tests first (vitest) for each portal-visible scenario in the specs. Verify: `npm run lint && npm run build && npm test` exit 0. - Scope: `solvway-admin-portal/**` ## 7. Local stack and end-to-end check - [ ] 7.1 Update `local/smoke.sh` to log in via `POST :8080/api/admin/auth/login` and call `/api/admin/me` and `/api/admin/users` (keep the counter read and the public call); add the portal to the README run steps (`npm run dev` with `MOBILE_API_BASE_URL=http://localhost:8080` and the app key). Verify: fresh `local/up.sh` then `local/smoke.sh` prints `smoke: OK`. - Scope: `local/smoke.sh`, `local/README.md`, `local/.env.example` - [ ] 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/**` ## Workflow follow-up - Code review, PR to `main`, merge, then archive this change.