Skip to content

NOW MANAGED ON CODEBERG

Updates search to use user slugs

Dan Brownda929d5edcb4
diff --git a/app/Entities/Tools/SearchRunner.php b/app/Entities/Tools/SearchRunner.php
index acfe8d956..dc2c04e3e 100644
--- a/app/Entities/Tools/SearchRunner.php
+++ b/app/Entities/Tools/SearchRunner.php
@@ -1,6 +1,7 @@
<?php namespace BookStack\Entities\Tools;
use BookStack\Auth\Permissions\PermissionService;
+use BookStack\Auth\User;
use BookStack\Entities\EntityProvider;
use BookStack\Entities\Models\Entity;
use Illuminate\Database\Connection;
@@ -270,24 +271,20 @@ class SearchRunner
protected function filterCreatedBy(EloquentBuilder $query, Entity $model, $input)
{
- if (!is_numeric($input) && $input !== 'me') {
- return;
- }
- if ($input === 'me') {
- $input = user()->id;
+ $userSlug = $input === 'me' ? user()->slug : trim($input);
+ $user = User::query()->where('slug', '=', $userSlug)->first(['id']);
+ if ($user) {
+ $query->where('created_by', '=', $user->id);
}
- $query->where('created_by', '=', $input);
}
protected function filterUpdatedBy(EloquentBuilder $query, Entity $model, $input)
{
- if (!is_numeric($input) && $input !== 'me') {
- return;
- }
- if ($input === 'me') {
- $input = user()->id;
+ $userSlug = $input === 'me' ? user()->slug : trim($input);
+ $user = User::query()->where('slug', '=', $userSlug)->first(['id']);
+ if ($user) {
+ $query->where('updated_by', '=', $user->id);
}
- $query->where('updated_by', '=', $input);
}
protected function filterInName(EloquentBuilder $query, Entity $model, $input)
diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php
index 21ebea378..bb824fd9b 100644
--- a/app/Http/Controllers/SearchController.php
+++ b/app/Http/Controllers/SearchController.php
@@ -1,9 +1,6 @@
<?php namespace BookStack\Http\Controllers;
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\ShelfContext;
use BookStack\Entities\Tools\SearchOptions;