Amended owned by search filter to use slugs

This commit is contained in:
Dan Brown 2021-03-15 18:27:03 +00:00
parent c8564b7792
commit 71ccb90ef4
2 changed files with 5 additions and 7 deletions

View file

@ -289,13 +289,11 @@ class SearchRunner
protected function filterOwnedBy(EloquentBuilder $query, Entity $model, $input) protected function filterOwnedBy(EloquentBuilder $query, Entity $model, $input)
{ {
if (!is_numeric($input) && $input !== 'me') { $userSlug = $input === 'me' ? user()->slug : trim($input);
return; $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) protected function filterInName(EloquentBuilder $query, Entity $model, $input)

View file

@ -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 {created_by:me}'))->assertDontSee($page->name);
$this->get('/search?term=' . urlencode('danzorbhsing {updated_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 {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->created_by = $editorId;
$page->save(); $page->save();
$this->get('/search?term=' . urlencode('danzorbhsing {created_by:me}'))->assertSee($page->name); $this->get('/search?term=' . urlencode('danzorbhsing {created_by:me}'))->assertSee($page->name);