diff --git a/README.md b/README.md index b92ea8a..f61c2be 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ ISPs elsewhere can use it too. - **Search:** menu Add-ons, then "Session records" (on ISPGrid 0.1.0, in the main menu). Search by an IP at a date and time (who had it then, sessions still online included), or by username, device MAC or NAS over a date range. Results show the customer's current name, mobile and address, or "Deleted customer". Export the results as CSV. -- **Accountability:** every search and export asks for a reference number and a reason, and is written to the - Activity log. +- **Accountability:** every search and export is written to the Activity log, with the reference number and reason + when staff give them. Searches by username, MAC or NAS start on the last 7 days. - **Permissions:** "Search session records" and "Session records settings" on the Roles screen (Admin has both; roles that had "App settings" get "Session records settings" when the add-on is updated). - English and Hindi. diff --git a/lang/hi.json b/lang/hi.json index a61d105..62a3cfa 100644 --- a/lang/hi.json +++ b/lang/hi.json @@ -6,7 +6,6 @@ "Device MAC": "डिवाइस MAC", "Download (bytes)": "डाउनलोड (बाइट)", "End": "समाप्त", - "Every session is kept for :days days. Each search is recorded in the Activity log with its reference and reason.": "हर सत्र :days दिन रखा जाता है। हर खोज संदर्भ और कारण के साथ गतिविधि लॉग में दर्ज होती है।", "Export CSV": "CSV निर्यात करें", "IP": "IP", "IP address at a time": "किसी समय पर IP पता", @@ -23,5 +22,6 @@ "Session records settings": "सत्र रिकॉर्ड की सेटिंग", "Start": "शुरू", "The number on the request you are answering.": "जिस अनुरोध का उत्तर दे रहे हैं उसकी संख्या।", - "Upload (bytes)": "अपलोड (बाइट)" + "Upload (bytes)": "अपलोड (बाइट)", + "Every session is kept for :days days. Each search is recorded in the Activity log, with the reference and reason when given.": "हर सेशन :days दिन तक रखा जाता है। हर खोज एक्टिविटी लॉग में दर्ज होती है, रेफ़रेंस और कारण दिए हों तो उनके साथ।" } diff --git a/resources/views/livewire/session-records/session-records.blade.php b/resources/views/livewire/session-records/session-records.blade.php index 2b1e309..e885b22 100644 --- a/resources/views/livewire/session-records/session-records.blade.php +++ b/resources/views/livewire/session-records/session-records.blade.php @@ -1,7 +1,7 @@
{{ __('Session records') }} - {{ __('Every session is kept for :days days. Each search is recorded in the Activity log with its reference and reason.', ['days' => $this->keepDays]) }} + {{ __('Every session is kept for :days days. Each search is recorded in the Activity log, with the reference and reason when given.', ['days' => $this->keepDays]) }}
diff --git a/resources/views/livewire/session-records/session-records.php b/resources/views/livewire/session-records/session-records.php index 75ea6a5..972cce3 100644 --- a/resources/views/livewire/session-records/session-records.php +++ b/resources/views/livewire/session-records/session-records.php @@ -40,9 +40,14 @@ */ public bool $searched = false; + /** + * Searches by username, MAC or NAS start on the last 7 days, still editable. + */ public function mount(): void { $this->authorize('search-session-records'); + $this->from = now()->subDays(7)->format('Y-m-d\TH:i'); + $this->to = now()->format('Y-m-d\TH:i'); } /** @@ -103,8 +108,8 @@ protected function rules(): array 'at' => [Rule::requiredIf(! $range), 'nullable', 'date'], 'from' => [Rule::requiredIf($range), 'nullable', 'date'], 'to' => [Rule::requiredIf($range), 'nullable', 'date', 'after_or_equal:from'], - 'reference' => ['required', 'string', 'max:100'], - 'reason' => ['required', 'string', 'max:255'], + 'reference' => ['nullable', 'string', 'max:100'], + 'reason' => ['nullable', 'string', 'max:255'], ]; } @@ -172,9 +177,10 @@ private function log(string $event, int $results): void { activity() ->event($event) - ->withChanges(['attributes' => [ - 'reference' => $this->reference, - 'reason' => $this->reason, + ->withChanges(['attributes' => array_filter([ + 'reference' => trim($this->reference), + 'reason' => trim($this->reason), + ], fn (string $value): bool => $value !== '') + [ 'search' => $this->query()->describe(), 'results' => $results, ]]) diff --git a/resources/views/livewire/settings/settings.blade.php b/resources/views/livewire/settings/settings.blade.php index 590a416..bad8bcc 100644 --- a/resources/views/livewire/settings/settings.blade.php +++ b/resources/views/livewire/settings/settings.blade.php @@ -1,4 +1,4 @@ - {{ __('Save') }} + {{ __('Save') }} diff --git a/tests/Feature/SearchPageTest.php b/tests/Feature/SearchPageTest.php index e9a7074..c5fe5db 100644 --- a/tests/Feature/SearchPageTest.php +++ b/tests/Feature/SearchPageTest.php @@ -41,13 +41,30 @@ function closedSessionWithIp(string $username): void $page->set('value', '100.64.10.7')->assertForbidden(); }); -it('needs a reference and a reason before it searches', function () { +it('searches and logs without a reference or a reason', function () { $this->actingAs(User::factory()->create()); + closedSessionWithIp('asha'); Livewire::test('ipdr::session-records') ->set('by', 'ip')->set('value', '100.64.10.7')->set('at', '2026-10-15T10:00') ->call('search') - ->assertHasErrors(['reference' => 'required', 'reason' => 'required']); + ->assertHasNoErrors(); + + $log = Activity::query()->where('event', 'session-records-searched')->sole()->attribute_changes['attributes']; + expect($log)->not->toHaveKeys(['reference', 'reason']) + ->and($log['results'])->toBe(1); +}); + +it('starts a range search on the last 7 days', function () { + $this->travelTo('2026-10-24 13:45:00'); + $this->actingAs(User::factory()->create()); + + Livewire::test('ipdr::session-records') + ->assertSet('from', '2026-10-17T13:45') + ->assertSet('to', '2026-10-24T13:45') + ->set('by', 'username')->set('value', 'asha') + ->call('search') + ->assertHasNoErrors(); }); it('shows who had the IP, with their details, and logs the search', function () {