Updates search to use user slugs

This commit is contained in:
Dan Brown 2021-03-10 22:51:18 +00:00
parent 124c4d0778
commit da929d5edc
2 changed files with 9 additions and 15 deletions

View File

@ -1,6 +1,7 @@
<?php namespace BookStack\Entities\Tools; <?php namespace BookStack\Entities\Tools;
use BookStack\Auth\Permissions\PermissionService; use BookStack\Auth\Permissions\PermissionService;
use BookStack\Auth\User;
use BookStack\Entities\EntityProvider; use BookStack\Entities\EntityProvider;
use BookStack\Entities\Models\Entity; use BookStack\Entities\Models\Entity;
use Illuminate\Database\Connection; use Illuminate\Database\Connection;
@ -270,24 +271,20 @@ class SearchRunner
protected function filterCreatedBy(EloquentBuilder $query, Entity $model, $input) protected function filterCreatedBy(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('created_by', '=', $user->id);
} }
if ($input === 'me') {
$input = user()->id;
}
$query->where('created_by', '=', $input);
} }
protected function filterUpdatedBy(EloquentBuilder $query, Entity $model, $input) protected function filterUpdatedBy(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('updated_by', '=', $user->id);
} }
if ($input === 'me') {
$input = user()->id;
}
$query->where('updated_by', '=', $input);
} }
protected function filterInName(EloquentBuilder $query, Entity $model, $input) protected function filterInName(EloquentBuilder $query, Entity $model, $input)

View File

@ -1,9 +1,6 @@
<?php namespace BookStack\Http\Controllers; <?php namespace BookStack\Http\Controllers;
use BookStack\Actions\ViewService; use BookStack\Actions\ViewService;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Tools\SearchRunner; use BookStack\Entities\Tools\SearchRunner;
use BookStack\Entities\Tools\ShelfContext; use BookStack\Entities\Tools\ShelfContext;
use BookStack\Entities\Tools\SearchOptions; use BookStack\Entities\Tools\SearchOptions;