From 71ccb90ef4c4b1271dac44a1b707e0e91af4830f Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 15 Mar 2021 18:27:03 +0000 Subject: [PATCH] Amended owned by search filter to use slugs --- app/Entities/Tools/SearchRunner.php | 10 ++++------ tests/Entity/EntitySearchTest.php | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Entities/Tools/SearchRunner.php b/app/Entities/Tools/SearchRunner.php index 99634184a..fc127f906 100644 --- a/app/Entities/Tools/SearchRunner.php +++ b/app/Entities/Tools/SearchRunner.php @@ -289,13 +289,11 @@ class SearchRunner protected function filterOwnedBy(EloquentBuilder $query, Entity $model, $input) { - if (!is_numeric($input) && $input !== 'me') { - return; + $userSlug = $input === 'me' ? user()->slug : trim($input); + $user = User::query()->where('slug', '=', $userSlug)->first(['id']); + if ($user) { + $query->where('owned_by', '=', $user->id); } - if ($input === 'me') { - $input = user()->id; - } - $query->where('owned_by', '=', $input); } protected function filterInName(EloquentBuilder $query, Entity $model, $input) diff --git a/tests/Entity/EntitySearchTest.php b/tests/Entity/EntitySearchTest.php index 9c963e105..6b53b2cb6 100644 --- a/tests/Entity/EntitySearchTest.php +++ b/tests/Entity/EntitySearchTest.php @@ -135,7 +135,7 @@ class EntitySearchTest extends TestCase $this->get('/search?term=' . urlencode('danzorbhsing {created_by:me}'))->assertDontSee($page->name); $this->get('/search?term=' . urlencode('danzorbhsing {updated_by:me}'))->assertDontSee($page->name); $this->get('/search?term=' . urlencode('danzorbhsing {owned_by:me}'))->assertDontSee($page->name); - $this->get('/search?term=' . urlencode('danzorbhsing {updated_by:'.$editorId.'}'))->assertDontSee($page->name); + $this->get('/search?term=' . urlencode('danzorbhsing {updated_by:'.$editorSlug.'}'))->assertDontSee($page->name); $page->created_by = $editorId; $page->save(); $this->get('/search?term=' . urlencode('danzorbhsing {created_by:me}'))->assertSee($page->name);