From c9a7f970ab28ccd1900cc020ae95caa32b31a525 Mon Sep 17 00:00:00 2001 From: Petri Saarinen Date: Sun, 22 Nov 2026 11:18:22 +0200 Subject: [PATCH] Fix review findings in login and user management - Load stored users without re-checking role rules, so an intern whose supervisor was deleted no longer gets a 500 on every request; the rules apply again on the next change. - Refuse to deactivate or demote a supervisor of active interns (SupervisorHasInterns). - Lock active admin rows in the last-admin check so concurrent changes cannot remove every admin. - Creating a user survives mail failures: the error is reported and the admin is asked to resend the link (CreatedUserAccount result). - Session-ended redirect passes the reason in the URL (/login?access=ended), so Livewire requests also show it. - Same login message for a wrong password and a disabled account. - Forgot-password sends links only to users who may sign in today (RequestPasswordReset), with the same neutral message. - Use the default callout instead of the low-contrast warning variant. - Document make:class/make:test for module files in CLAUDE.md. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 3 +- .../Contracts/PasswordLinkSender.php | 3 +- .../Application/DTOs/CreatedUserAccount.php | 17 ++++++ .../UseCases/CreateUserAccount.php | 9 ++-- .../UseCases/RequestPasswordReset.php | 35 ++++++++++++ .../UseCases/UpdateUserAccount.php | 11 ++++ .../Contracts/UserAccountRepository.php | 9 ++++ .../Users/Domain/Entities/UserAccount.php | 23 ++++++-- .../Exceptions/SupervisorHasInterns.php | 15 ++++++ .../Users/Domain/Services/SupervisorRule.php | 3 +- .../Auth/LaravelPasswordLinkSender.php | 11 +++- .../EloquentUserAccountRepository.php | 25 ++++++++- .../Console/CreateAdminCommand.php | 8 ++- .../Http/Middleware/EnsureAccountIsUsable.php | 4 +- .../Presentation/Livewire/Forms/UserForm.php | 2 + .../Livewire/⚡forgot-password.blade.php | 12 +++-- .../Presentation/Livewire/⚡form.blade.php | 7 ++- .../Presentation/Livewire/⚡login.blade.php | 31 +++++++---- docs/architecture.md | 8 +-- lang/fi/auth.php | 2 +- lang/fi/users.php | 4 +- tests/Browser/UsersAccessibilityTest.php | 18 ++++++- tests/Fakes/InMemoryUserAccountRepository.php | 19 +++++++ tests/Feature/Modules/Users/LoginTest.php | 15 +++--- .../Feature/Modules/Users/MailFailureTest.php | 53 +++++++++++++++++++ .../Modules/Users/PasswordResetTest.php | 16 ++++++ .../Modules/Users/StoredUserAccountTest.php | 30 +++++++++++ .../Modules/Users/UserManagementTest.php | 14 +++++ .../Application/UserAccountUseCasesTest.php | 25 +++++++-- 29 files changed, 379 insertions(+), 53 deletions(-) create mode 100644 app/Modules/Users/Application/DTOs/CreatedUserAccount.php create mode 100644 app/Modules/Users/Application/UseCases/RequestPasswordReset.php create mode 100644 app/Modules/Users/Domain/Exceptions/SupervisorHasInterns.php create mode 100644 tests/Feature/Modules/Users/MailFailureTest.php create mode 100644 tests/Feature/Modules/Users/StoredUserAccountTest.php diff --git a/CLAUDE.md b/CLAUDE.md index 5632507..cf9c7fb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -25,6 +25,7 @@ Read `docs/architecture.md` (Finnish) before adding or changing domain code. `ap - **Authorization:** define abilities with `Gate::define` in the owning module's provider (`users.manage`, `customers.use`). Protect routes with `can:` and also call `$this->authorize()` in each Livewire page's `mount()` and in every action. Mark record ids on Livewire pages `#[Locked]`. - **Login** is the `Users` module: `Auth::attemptWhen` with `CheckLoginAllowed` (active, intern's last day not passed), and the `EnsureAccountIsUsable` web middleware ends sessions of users who are no longer allowed in. Nobody handles passwords: new users and "forgot password" get the same emailed set-password link. - `tests/Unit/ArchitectureTest.php` enforces these rules for every module. Domain and Application files declare `strict_types=1`. Test domain rules and use cases in `tests/Unit` without Laravel (fakes in `tests/Fakes`), and repositories and pages in `tests/Feature`. +- Generate module files with Artisan, then edit them: `php artisan make:class Modules////` for classes, `make:test --pest [--unit] Modules//Test` for tests, `make:migration` for migrations. Add `declare(strict_types=1);` to Domain and Application files. - When writing PHP through a bash heredoc, `\\` can collapse to `\`, and `"App\Modules\{$x}"` then stops interpolating. Write PHP files with the Write tool. ## Accessibility (WCAG 2.2 AA, EN 301 549) @@ -38,7 +39,7 @@ Accessibility is a contractual acceptance criterion. It covers the whole UI: nav - The layout (`resources/views/layouts/app.blade.php`) provides a skip link and a `
` landmark. Keep them, and add `