Give the machine console its own session with PIN sign-in, make counters cumulative

The console under console/ has its own session cookie and console guard
(UseConsoleSession), so signing out or changing user there leaves the
normal interface alone. Links open it in a new window through a one-time
handoff key; a signed-out console asks for a PIN code or password on its
own login page. Users set their 4-6 digit PIN on the profile's PIN page,
and the console's change user dialog takes it on a keypad; five wrong
PINs lock PIN sign-in for 15 minutes.

Machine counters are cumulative: users record how much a job used and it
is added to the latest reading. A maintenance record restarts the whole
counter interval from the reading at the record.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-29 09:58:11 +02:00
co-authored by Claude Sonnet 5.5
parent 87e38260dc
commit 32c33e2a64
55 changed files with 1660 additions and 194 deletions
@@ -10,13 +10,17 @@ use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineCounterModel
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MachineModel;
use App\Modules\Machines\Infrastructure\Persistence\Eloquent\MaintenanceItemModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->user = User::factory()->management()->create(['name' => 'Johtaja']);
$this->actingAs($this->user);
// The machine console has its own session and guard.
$this->actingAs($this->user, 'console');
$print = ServiceUnitModel::query()->where('name', 'Painotuotanto')->sole();
$print->update(['uses_stock' => true]);
@@ -115,3 +119,68 @@ it('refreshes the console on a tablet and keeps focus on the button', function (
->assertSee(__('machines.console.selected', ['title' => 'Banderolli']))
->assertNoAccessibilityIssues(level: 2);
});
it('changes user with a PIN code in a dialog on the console', function (string $device, string $colorScheme) {
User::factory()->employee()->create(['name' => 'Olli Operaattori', 'pin_hash' => Hash::make('2468')]);
$visit = visit(route('machines.console', $this->machine->id));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->click('#pin-switch-open')
->assertScript("document.getElementById('pin-switch-dialog').open", true)
->assertScript("document.getElementById('pin-switch-dialog').contains(document.activeElement)", true)
->assertSee('Olli Operaattori')
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('signs in with a PIN code typed on the keypad and stays on the console', function () {
User::factory()->employee()->create(['name' => 'Olli Operaattori', 'pin_hash' => Hash::make('2468')]);
visit(route('machines.console', $this->machine->id))
->click('#pin-switch-open')
->click('Olli Operaattori')
->click('2')->click('4')->click('6')->click('8')
->click(__('users.pin_switch.submit'))
->assertSee(__('machines.console.user', ['name' => 'Olli Operaattori']))
->assertNoJavaScriptErrors();
});
it('has no accessibility issues on the console\'s sign-in page', function (string $device, string $colorScheme) {
User::factory()->employee()->create(['name' => 'Olli Operaattori', 'pin_hash' => Hash::make('2468')]);
Auth::guard('console')->logout();
$visit = visit(route('console.login'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee(__('users.console_login.title'))
->assertSee('Olli Operaattori')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('has no accessibility issues on the PIN code page', function (string $device, string $colorScheme) {
$visit = visit(route('profile.pin'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee(__('users.pin.title'))
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);