Files
co-lite/openspec/changes/add-admin-auth-users-roles/proposal.md
T

38 lines
3.6 KiB
Markdown

# Proposal
## Why
Lead capture (change 4) needs staff to log in to the admin portal and needs Sales users to exist. Today the copied admin portal is babyboo's full back office, and `mobile-api` has no `/api/admin/**` endpoints, so nobody can log in. This change gives Co-Lite a working staff login, user management and role permissions: the base every later admin screen builds on. See `docs/superpowers/specs/2026-11-26-co-lite-foundation-and-leads-design.md` (Admin portal, Access, Company id).
## What Changes
- **Admin portal cut down** to: login, first-login password change, forgot password, Users (list, create, edit, deactivate, assign roles, reset password), Roles (list, create, edit, edit permissions), the app shell with role-based menus, and the not-authorised page. Every other babyboo screen, API route, component and test is removed, along with dependencies only they used.
- **New forgot-password page** in the portal. It uses Tastefully's existing reset: username plus email, a temporary password is emailed, and the user must change it at next login.
- **`mobile-api` gains `/api/admin/**`**: auth (login, first-login, forgot password, logout, refresh), `me`, users, roles and role permissions. Ported from babyboo's AdminAuth, AdminUser and AdminRole controllers onto Co-Lite's existing `services-auth` and `services-system` endpoints.
- **Admin access enforcement** in `mobile-api`: on `/api/admin/**`, a non-admin token is rejected, a logged-out token is rejected, a pending first-login reset confines the token to the first-login endpoint, and each handler declares the modules it needs (`@AdminModule`), checked against the caller's roles. Super admin passes every module check.
- **Wrong-password login returns 401** at `/api/admin/auth/login` (today `services-auth` answers 200 with an empty body).
- **Company**: a `company` table and a `company_id` column on the admin `user` in `service-system`. New users get the creating admin's company.
- **Back-office modules**: Co-Lite's own BO module rows (root, Users, Roles) in `service-system`.`module`. SQL lives in this change folder and is mirrored in `local/seed/`.
Not in this change: login lockout, session-policy and login-security screens, the module-management screen, user groups, audit log, Google sign-in (all babyboo features Co-Lite drops in phase 1).
## Capabilities
### New Capabilities
- `admin-access`: staff login, first-login password change, forgot password, logout, session, menus, and the rules that guard every `/api/admin/**` endpoint and admin portal page.
- `admin-users`: managing staff users (list, search, create, edit, deactivate, assign roles, reset password) and the company they belong to.
- `admin-roles`: managing roles and the back-office modules each role grants.
### Modified Capabilities
None.
## Impact
- `solvway-admin-portal`: most of the tree is deleted; kept screens are adapted to Co-Lite (cookie name, module names, branding text).
- `solvway-mobile-api`: new admin controllers, services, `@AdminModule`, and admin checks in `AppAccessAspect`.
- `solvway-services-system`: `Company` entity, `User.companyId`, user save sets company. No new endpoints expected (the needed ones exist); any gap found is added in the task that needs it.
- `solvway-services-auth`: unchanged unless the admin token check needs it (see design).
- Database `service-system`: new table `company`, new column `user.company_id`, new `module` and `modules_roles` rows. Additive only.
- `local/seed/`: mirrors the SQL; `03-colite.sql` keeps creating the dev admin.
- `local/smoke.sh`: the admin login call moves to `/api/admin/auth/login` on mobile-api.