diff --git a/app/Http/Controllers/AuditLogController.php b/app/Http/Controllers/AuditLogController.php index 11efbfc23..ec3f36975 100644 --- a/app/Http/Controllers/AuditLogController.php +++ b/app/Http/Controllers/AuditLogController.php @@ -20,6 +20,7 @@ class AuditLogController extends Controller 'date_from' => $request->get('date_from', ''), 'date_to' => $request->get('date_to', ''), 'user' => $request->get('user', ''), + 'ip' => $request->get('ip', ''), ]; $query = Activity::query() @@ -44,6 +45,9 @@ class AuditLogController extends Controller if ($listDetails['date_to']) { $query->where('created_at', '<=', $listDetails['date_to']); } + if ($listDetails['ip']) { + $query->where('ip', 'like', $listDetails['ip'] . '%'); + } $activities = $query->paginate(100); $activities->appends($listDetails); diff --git a/database/migrations/2021_11_26_070438_add_index_for_user_ip.php b/database/migrations/2021_11_26_070438_add_index_for_user_ip.php new file mode 100644 index 000000000..eebab7958 --- /dev/null +++ b/database/migrations/2021_11_26_070438_add_index_for_user_ip.php @@ -0,0 +1,32 @@ +index('ip', 'activities_ip_index'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('activities', function (Blueprint $table) { + $table->dropIndex('activities_ip_index'); + }); + } +} diff --git a/resources/views/settings/audit.blade.php b/resources/views/settings/audit.blade.php index 84f180f3b..d7c31b0dd 100644 --- a/resources/views/settings/audit.blade.php +++ b/resources/views/settings/audit.blade.php @@ -41,12 +41,19 @@ @endforeach -
Updated content
', + ], [ + 'X-Forwarded-For' => '192.123.45.1', + ])->assertRedirect($page->refresh()->getUrl()); + + $resp = $this->asAdmin()->get('/settings/audit?&ip=192.123'); + $resp->assertSee('192.123.45.1'); + } + public function test_ip_address_not_logged_in_demo_mode() { config()->set('app.proxies', '*');