Add structured specification and show set-password links to admins
The customer answered the open questions in määrittely.txt. Collect the answers into docs/maarittely.md: roles and permission table, money visibility, customer job fields and enum keys, Kanban, tasks, time entries, expenses, pricing, Fennoa billing export, data model, revised phases with phase 1 in detail, and remaining open questions. CLAUDE.md now points to it. Apply the answers that change the Users module: - Passwords need 12+ characters with mixed case, a number and a symbol, with a Finnish message for each rule. - When an admin creates a user or asks for a new link, the set-password link is emailed and also shown to the admin to copy, even if the email fails. The link lives only in the page state. users:create-admin prints it too. Self-service "forgot password" stays as it was. - The copy field uses x-input + x-button with a status message, because x-clipboard has an unlabelled input and a changing button name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -5,6 +5,8 @@ use App\Modules\Users\Domain\Enums\Role;
|
||||
use Illuminate\Auth\Notifications\ResetPassword;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException;
|
||||
use Livewire\Livewire;
|
||||
|
||||
@@ -42,10 +44,10 @@ it('lists users with their role and status', function () {
|
||||
->assertSee('Ei käytössä');
|
||||
});
|
||||
|
||||
it('creates an intern and emails a set-password link', function () {
|
||||
it('creates an intern, emails a set-password link and shows it to copy', function () {
|
||||
$supervisor = User::factory()->create();
|
||||
|
||||
Livewire::actingAs($this->admin)
|
||||
$component = Livewire::actingAs($this->admin)
|
||||
->test('users::form')
|
||||
->set('form.name', 'Ida Harjoittelija')
|
||||
->set('form.email', '[email protected]')
|
||||
@@ -54,15 +56,21 @@ it('creates an intern and emails a set-password link', function () {
|
||||
->set('form.supervisor_id', (string) $supervisor->id)
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect(route('users.index'));
|
||||
->assertNoRedirect()
|
||||
->assertSee('Käyttäjä Ida Harjoittelija lisätty.')
|
||||
->assertSee('Salasanan asetuslinkki');
|
||||
|
||||
$intern = User::query()->where('email', '[email protected]')->sole();
|
||||
|
||||
expect($component->get('userId'))->toBe($intern->id);
|
||||
|
||||
expect($intern->role)->toBe(Role::Intern)
|
||||
->and($intern->employment_ends_on?->toDateString())->toBe('2027-05-31')
|
||||
->and($intern->supervisor_id)->toBe($supervisor->id);
|
||||
|
||||
Notification::assertSentTo($intern, ResetPassword::class);
|
||||
Notification::assertSentTo($intern, ResetPassword::class, function (ResetPassword $notification) use ($component) {
|
||||
return str_contains($component->get('setupLink'), '/reset-password/'.$notification->token);
|
||||
});
|
||||
});
|
||||
|
||||
it('requires an end date and a supervisor for an intern', function () {
|
||||
@@ -135,17 +143,27 @@ it('does not let the last admin deactivate themselves', function () {
|
||||
expect($this->admin->fresh()->is_active)->toBeTrue();
|
||||
});
|
||||
|
||||
it('sends a set-password link from the edit page', function () {
|
||||
it('makes a new set-password link on the edit page, also right after an earlier one', function () {
|
||||
$user = User::factory()->create(['email' => '[email protected]']);
|
||||
|
||||
Livewire::actingAs($this->admin)
|
||||
$component = Livewire::actingAs($this->admin)
|
||||
->test('users::form', ['user' => $user->id])
|
||||
->call('sendPasswordLink')
|
||||
->assertSee('Lähetimme linkin salasanan asettamiseen osoitteeseen [email protected].');
|
||||
->call('sendPasswordLink')
|
||||
->assertSee('Uusi linkki luotu ja lähetetty osoitteeseen [email protected].');
|
||||
|
||||
Notification::assertSentTo($user, ResetPassword::class);
|
||||
$token = Str::between($component->get('setupLink'), '/reset-password/', '?');
|
||||
|
||||
Notification::assertSentToTimes($user, ResetPassword::class, 2);
|
||||
expect(Password::tokenExists($user, $token))->toBeTrue();
|
||||
});
|
||||
|
||||
it('does not let the set-password link be changed in the browser', function () {
|
||||
Livewire::actingAs($this->admin)
|
||||
->test('users::form')
|
||||
->set('setupLink', 'https://evil.example/');
|
||||
})->throws(CannotUpdateLockedPropertyException::class);
|
||||
|
||||
it('does not let the user id be changed in the browser', function () {
|
||||
Livewire::actingAs($this->admin)
|
||||
->test('users::form')
|
||||
|
||||
Reference in New Issue
Block a user