Merge branch 'search-by-ip' of https://github.com/johnroyer/BookStack into johnroyer-search-by-ip

This commit is contained in:
Dan Brown 2021-12-18 10:58:07 +00:00
commit 5c04f25c86
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
4 changed files with 62 additions and 1 deletions

View file

@ -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);

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddIndexForUserIp extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('activities', function (Blueprint $table) {
$table->index('ip', 'activities_ip_index');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('activities', function (Blueprint $table) {
$table->dropIndex('activities_ip_index');
});
}
}

View file

@ -41,12 +41,19 @@
</div>
@endforeach
<div class="form-group ml-auto"
<div class="form-group ml-auto mr-m"
component="submit-on-change"
option:submit-on-change:filter='[name="user"]'>
<label for="owner">{{ trans('settings.audit_table_user') }}</label>
@include('form.user-select', ['user' => $listDetails['user'] ? \BookStack\Auth\User::query()->find($listDetails['user']) : null, 'name' => 'user', 'compact' => true])
</div>
<div class="form-group ml-auto">
<label for="ip">{{ trans('settings.audit_table_ip') }}</label>
@include('form.text', ['name' => 'ip', 'model' => (object) $listDetails])
<input type="submit" style="display: none">
</div>
</form>
</div>

View file

@ -166,6 +166,24 @@ class AuditLogTest extends TestCase
$resp->assertSee('192.123.45.1');
}
public function test_ip_address_is_searchable()
{
config()->set('app.proxies', '*');
$editor = $this->getEditor();
/** @var Page $page */
$page = Page::query()->first();
$this->actingAs($editor)->put($page->getUrl(), [
'name' => 'Updated page',
'html' => '<p>Updated content</p>',
], [
'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', '*');