Add support for filtering servers in client list-all endpoint

closes #1608
This commit is contained in:
Dane Everitt 2019-08-03 12:44:15 -07:00
parent 47c12929c4
commit fe9d86b66b
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 23 additions and 1 deletions

View File

@ -16,6 +16,9 @@ error encountered during creation or update.
### Added ### Added
* Server listing view now displays the total used disk space for each server. * Server listing view now displays the total used disk space for each server.
* Client API endpoint to list all servers now supports an additional `?filter=subuser-of|all|admin|owner` parameter to
return different groupings of servers. The default value is `subuser-of` which will include all of the user's servers
that they are the owner of, as well as all servers they're a subuser of.
### Changed ### Changed
* Updated Paper egg to not download `server.properties` each time. [parkervcp/eggs#260](https://github.com/parkervcp/eggs/issues/260) * Updated Paper egg to not download `server.properties` each time. [parkervcp/eggs#260](https://github.com/parkervcp/eggs/issues/260)

View File

@ -35,7 +35,26 @@ class ClientController extends ClientApiController
*/ */
public function index(GetServersRequest $request): array public function index(GetServersRequest $request): array
{ {
$servers = $this->repository->filterUserAccessServers($request->user(), User::FILTER_LEVEL_SUBUSER, config('pterodactyl.paginate.frontend.servers')); // Check for the filter parameter on the request.
switch ($request->input('filter')) {
case 'all':
$filter = User::FILTER_LEVEL_ALL;
break;
case 'admin':
$filter = User::FILTER_LEVEL_ADMIN;
break;
case 'owner':
$filter = User::FILTER_LEVEL_OWNER;
break;
case 'subuser-of':
default:
$filter = User::FILTER_LEVEL_SUBUSER;
break;
}
$servers = $this->repository->filterUserAccessServers(
$request->user(), $filter, config('pterodactyl.paginate.frontend.servers')
);
return $this->fractal->collection($servers) return $this->fractal->collection($servers)
->transformWith($this->getTransformer(ServerTransformer::class)) ->transformWith($this->getTransformer(ServerTransformer::class))