From 06706a2d9c625cbe7d61df1aa8a71578cbea1684 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sun, 21 Mar 2021 15:04:32 +0000 Subject: [PATCH] Added user filter to audit log Included testing to cover. Closes #2472 --- app/Http/Controllers/AuditLogController.php | 4 +++ resources/js/components/user-select.js | 2 ++ resources/sass/_components.scss | 4 +-- resources/sass/_header.scss | 10 +++++- resources/sass/_variables.scss | 2 +- .../components/user-select-list.blade.php | 3 ++ .../views/components/user-select.blade.php | 6 ++-- .../views/form/entity-permissions.blade.php | 2 +- resources/views/settings/audit.blade.php | 36 +++++++++++-------- resources/views/users/delete.blade.php | 2 +- tests/AuditLogTest.php | 23 ++++++++++++ 11 files changed, 70 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/AuditLogController.php b/app/Http/Controllers/AuditLogController.php index eb6eecc94..f73ee4a20 100644 --- a/app/Http/Controllers/AuditLogController.php +++ b/app/Http/Controllers/AuditLogController.php @@ -20,6 +20,7 @@ class AuditLogController extends Controller 'sort' => $request->get('sort', 'created_at'), 'date_from' => $request->get('date_from', ''), 'date_to' => $request->get('date_to', ''), + 'user' => $request->get('user', ''), ]; $query = Activity::query() @@ -34,6 +35,9 @@ class AuditLogController extends Controller if ($listDetails['event']) { $query->where('type', '=', $listDetails['event']); } + if ($listDetails['user']) { + $query->where('user_id', '=', $listDetails['user']); + } if ($listDetails['date_from']) { $query->where('created_at', '>=', $listDetails['date_from']); diff --git a/resources/js/components/user-select.js b/resources/js/components/user-select.js index 477c11d6b..c2c1f97c3 100644 --- a/resources/js/components/user-select.js +++ b/resources/js/components/user-select.js @@ -13,9 +13,11 @@ class UserSelect { } selectUser(event, userEl) { + event.preventDefault(); const id = userEl.getAttribute('data-id'); this.input.value = id; this.userInfoContainer.innerHTML = userEl.innerHTML; + this.input.dispatchEvent(new Event('change', {bubbles: true})); this.hide(); } diff --git a/resources/sass/_components.scss b/resources/sass/_components.scss index ede26c51c..ad6304694 100644 --- a/resources/sass/_components.scss +++ b/resources/sass/_components.scss @@ -783,6 +783,6 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group { .custom-select-input { max-width: 280px; - border: 1px solid #DDD; - border-radius: 4px; + border: 1px solid #D4D4D4; + border-radius: 3px; } \ No newline at end of file diff --git a/resources/sass/_header.scss b/resources/sass/_header.scss index 3e8c676fd..f371e0410 100644 --- a/resources/sass/_header.scss +++ b/resources/sass/_header.scss @@ -269,7 +269,7 @@ header .search-box { .dropdown-search { position: relative; .dropdown-search-toggle { - padding: 6px; + padding: $-xs; border: 1px solid transparent; border-radius: 4px; &:hover { @@ -281,6 +281,14 @@ header .search-box { } } +.dropdown-search-toggle.compact { + padding: $-xxs $-xs; + .avatar { + height: 22px; + width: 22px; + } +} + .faded { a, button, span, span > div { color: #666; diff --git a/resources/sass/_variables.scss b/resources/sass/_variables.scss index d0d1f27d3..42207528b 100644 --- a/resources/sass/_variables.scss +++ b/resources/sass/_variables.scss @@ -28,7 +28,7 @@ $-xs: 6px; $-xxs: 3px; // List of our spacing sizes -$spacing: (('none', 0), ('xxs', $-xxs), ('xs', $-xs), ('s', $-s), ('m', $-m), ('l', $-l), ('xl', $-xl), ('xxl', $-xxl)); +$spacing: (('none', 0), ('xxs', $-xxs), ('xs', $-xs), ('s', $-s), ('m', $-m), ('l', $-l), ('xl', $-xl), ('xxl', $-xxl), ('auto', auto)); // Fonts $text: -apple-system, BlinkMacSystemFont, diff --git a/resources/views/components/user-select-list.blade.php b/resources/views/components/user-select-list.blade.php index 2c49e965d..0018d64bf 100644 --- a/resources/views/components/user-select-list.blade.php +++ b/resources/views/components/user-select-list.blade.php @@ -1,3 +1,6 @@ + + {{ trans('settings.users_none_selected') }} + @foreach($users as $user) {{ $user->name }} diff --git a/resources/views/components/user-select.blade.php b/resources/views/components/user-select.blade.php index 2a07f0bde..50c731efd 100644 --- a/resources/views/components/user-select.blade.php +++ b/resources/views/components/user-select.blade.php @@ -3,17 +3,17 @@ > diff --git a/resources/views/form/entity-permissions.blade.php b/resources/views/form/entity-permissions.blade.php index 35490bed9..6cf5ab8bd 100644 --- a/resources/views/form/entity-permissions.blade.php +++ b/resources/views/form/entity-permissions.blade.php @@ -15,7 +15,7 @@
- @include('components.user-select', ['user' => $model->ownedBy, 'name' => 'owned_by']) + @include('components.user-select', ['user' => $model->ownedBy, 'name' => 'owned_by', 'compact' => false])
diff --git a/resources/views/settings/audit.blade.php b/resources/views/settings/audit.blade.php index c52390f73..9fda39a31 100644 --- a/resources/views/settings/audit.blade.php +++ b/resources/views/settings/audit.blade.php @@ -25,21 +25,27 @@ - @foreach(['date_from', 'date_to'] as $filterKey) -
- @foreach($listDetails as $param => $val) - @if(!empty($val) && $param !== $filterKey) - - @endif - @endforeach - - -
- @endforeach +
+ @if(!empty($listDetails['event'])) + + @endif + + @foreach(['date_from', 'date_to'] as $filterKey) +
+ + +
+ @endforeach + +
+ + @include('components.user-select', ['user' => $listDetails['user'] ? \BookStack\Auth\User::query()->find($listDetails['user']) : null, 'name' => 'user', 'compact' => true]) +
+

diff --git a/resources/views/users/delete.blade.php b/resources/views/users/delete.blade.php index aba6f5cc1..7b1d38d34 100644 --- a/resources/views/users/delete.blade.php +++ b/resources/views/users/delete.blade.php @@ -20,7 +20,7 @@

{{ trans('settings.users_migrate_ownership_desc') }}

- @include('components.user-select', ['name' => 'new_owner_id', 'user' => null]) + @include('components.user-select', ['name' => 'new_owner_id', 'user' => null, 'compact' => false])
diff --git a/tests/AuditLogTest.php b/tests/AuditLogTest.php index 3dc6fd7c2..55a458786 100644 --- a/tests/AuditLogTest.php +++ b/tests/AuditLogTest.php @@ -4,6 +4,7 @@ use BookStack\Actions\Activity; use BookStack\Actions\ActivityService; use BookStack\Actions\ActivityType; use BookStack\Auth\UserRepo; +use BookStack\Entities\Models\Chapter; use BookStack\Entities\Tools\TrashCan; use BookStack\Entities\Models\Page; use BookStack\Entities\Repos\PageRepo; @@ -117,4 +118,26 @@ class AuditLogTest extends TestCase $resp->assertDontSeeText($page->name); } + public function test_user_filter() + { + $admin = $this->getAdmin(); + $editor = $this->getEditor(); + $this->actingAs($admin); + $page = Page::query()->first(); + $this->activityService->addForEntity($page, ActivityType::PAGE_CREATE); + + $this->actingAs($editor); + $chapter = Chapter::query()->first(); + $this->activityService->addForEntity($chapter, ActivityType::CHAPTER_UPDATE); + + $resp = $this->actingAs($admin)->get('settings/audit?user=' . $admin->id); + $resp->assertSeeText($page->name); + $resp->assertDontSeeText($chapter->name); + + $resp = $this->actingAs($admin)->get('settings/audit?user=' . $editor->id); + $resp->assertSeeText($chapter->name); + $resp->assertDontSeeText($page->name); + + } + } \ No newline at end of file