From cbeecfe5e4a9dc673c3e745bca7386ec183a8f28 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 1 Apr 2017 13:14:49 -0400 Subject: [PATCH] Implement front-end server searching :candy: --- CHANGELOG.md | 1 + .../Controllers/API/User/InfoController.php | 2 +- app/Http/Controllers/Base/IndexController.php | 8 +++++++- app/Models/User.php | 18 ++++++++++++------ .../pterodactyl/admin/users/view.blade.php | 2 +- .../themes/pterodactyl/base/index.blade.php | 12 +++++++----- .../pterodactyl/layouts/master.blade.php | 2 +- 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20d862794..df602d2e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Added * Login attempts and pasword reset requests are now protected by invisible ReCaptcha. This feature can be disabled with a `.env` variable. +* Server listing for individual users is now searchable on the front-end. ### Changed * Subuser permissions are now stored in `Permission::list()` to make views way cleaner and make adding to views significantly cleaner. diff --git a/app/Http/Controllers/API/User/InfoController.php b/app/Http/Controllers/API/User/InfoController.php index a22d1e114..faf1be622 100644 --- a/app/Http/Controllers/API/User/InfoController.php +++ b/app/Http/Controllers/API/User/InfoController.php @@ -31,7 +31,7 @@ class InfoController extends BaseController { public function me(Request $request) { - return $request->user()->serverAccessCollection()->load('allocation', 'option')->map(function ($server) { + return $request->user()->access('service', 'node', 'allocation', 'option')->get()->map(function ($server) { return [ 'id' => $server->uuidShort, 'uuid' => $server->uuid, diff --git a/app/Http/Controllers/Base/IndexController.php b/app/Http/Controllers/Base/IndexController.php index 84b89e6aa..6911e6a8a 100644 --- a/app/Http/Controllers/Base/IndexController.php +++ b/app/Http/Controllers/Base/IndexController.php @@ -38,8 +38,14 @@ class IndexController extends Controller */ public function getIndex(Request $request) { + $servers = $request->user()->access(); + + if (! is_null($request->input('query'))) { + $servers->search($request->input('query')); + } + return view('base.index', [ - 'servers' => $request->user()->serverAccessCollection(config('pterodactyl.paginate.frontend.servers')), + 'servers' => $servers->paginate(config('pterodactyl.paginate.frontend.servers')), ]); } diff --git a/app/Models/User.php b/app/Models/User.php index 9ec5b229d..649af11a7 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -103,6 +103,8 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac ], ]; + protected $query; + /** * Enables or disables TOTP on an account if the token is valid. * @@ -200,18 +202,22 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac * Returns an array of all servers a user is able to access. * Note: does not account for user admin status. * - * @param int|null $paginate - * @param array $load - * @return \Illuminate\Pagination\LengthAwarePagination|\Illuiminate\Database\Eloquent\Collection + * @param array $load + * @return \Illuiminate\Database\Eloquent\Builder */ - public function serverAccessCollection($paginate = null, $load = ['service', 'node', 'allocation']) + public function access(...$load) { - $query = Server::with($load); + if (count($load) > 0 && is_null($load[0])) { + $query = Server::query(); + } else { + $query = Server::with(! empty($load) ? $load : ['service', 'node', 'allocation']); + } + if (! $this->isRootAdmin()) { $query->whereIn('id', $this->serverAccessArray()); } - return (is_numeric($paginate)) ? $query->paginate($paginate) : $query->get(); + return $query; } /** diff --git a/resources/themes/pterodactyl/admin/users/view.blade.php b/resources/themes/pterodactyl/admin/users/view.blade.php index ef1c383ff..6449f0dd7 100644 --- a/resources/themes/pterodactyl/admin/users/view.blade.php +++ b/resources/themes/pterodactyl/admin/users/view.blade.php @@ -129,7 +129,7 @@ - @foreach($user->serverAccessCollection() as $server) + @foreach($user->access()->get() as $server) {{ $server->uuidShort }} diff --git a/resources/themes/pterodactyl/base/index.blade.php b/resources/themes/pterodactyl/base/index.blade.php index b127926ff..878fc895c 100644 --- a/resources/themes/pterodactyl/base/index.blade.php +++ b/resources/themes/pterodactyl/base/index.blade.php @@ -38,12 +38,14 @@

@lang('base.index.list')

-
- -
- +
+
+ +
+ +
-
+
diff --git a/resources/themes/pterodactyl/layouts/master.blade.php b/resources/themes/pterodactyl/layouts/master.blade.php index ac074bb30..047a9ad2f 100644 --- a/resources/themes/pterodactyl/layouts/master.blade.php +++ b/resources/themes/pterodactyl/layouts/master.blade.php @@ -235,7 +235,7 @@