From 88ac1ce1fd34b5dc27a5413a2705fbd4952a647b Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Fri, 1 Jan 2021 15:55:30 -0700 Subject: [PATCH] Cleanup code, add basic functionality for Nests --- app/Http/Controllers/Admin/ApiController.php | 2 +- .../Controllers/Admin/MountController.php | 4 +- .../Controllers/Admin/NodesController.php | 6 +- .../Controllers/Admin/ServersController.php | 4 +- .../Admin/Settings/MailController.php | 4 +- .../Application/ApplicationApiController.php | 2 + .../Locations/LocationController.php | 29 ++++--- .../Api/Application/Nests/EggController.php | 14 +++- .../Api/Application/Nests/NestController.php | 9 ++- .../Nodes/AllocationController.php | 2 + .../Nodes/NodeConfigurationController.php | 2 +- .../Api/Application/Nodes/NodeController.php | 9 ++- .../Api/Application/Roles/RoleController.php | 12 ++- .../Servers/DatabaseController.php | 23 ++++-- .../Servers/ExternalServerController.php | 2 + .../Application/Servers/ServerController.php | 21 +++-- .../Servers/ServerDetailsController.php | 15 ++-- .../Servers/ServerManagementController.php | 7 +- .../Application/Servers/StartupController.php | 12 ++- .../Users/ExternalUserController.php | 2 + .../Api/Application/Users/UserController.php | 12 ++- .../Users/GetExternalUserRequest.php | 1 + .../Api/Application/AdminRoleTransformer.php | 10 +-- .../Api/Application/AllocationTransformer.php | 21 +++-- .../Api/Application/BaseTransformer.php | 5 ++ .../Application/DatabaseHostTransformer.php | 2 + .../Api/Application/EggTransformer.php | 9 +++ .../Api/Application/LocationTransformer.php | 14 ++-- .../Api/Application/NodeTransformer.php | 19 +++-- .../Api/Application/ServerTransformer.php | 77 ++++++++++++------- .../components/admin/AdminCheckbox.tsx | 10 ++- .../components/admin/AdminContentBlock.tsx | 40 +++++----- .../components/admin/nests/NestsContainer.tsx | 62 +++++++++++---- resources/scripts/routers/AdminRouter.tsx | 2 +- resources/scripts/state/admin/index.ts | 1 + resources/scripts/state/admin/nests.ts | 23 ++++++ resources/scripts/state/admin/roles.ts | 1 + 37 files changed, 331 insertions(+), 159 deletions(-) diff --git a/app/Http/Controllers/Admin/ApiController.php b/app/Http/Controllers/Admin/ApiController.php index 6067b423c..155b20cd7 100644 --- a/app/Http/Controllers/Admin/ApiController.php +++ b/app/Http/Controllers/Admin/ApiController.php @@ -113,6 +113,6 @@ class ApiController extends Controller { $this->repository->deleteApplicationKey($request->user(), $identifier); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } } diff --git a/app/Http/Controllers/Admin/MountController.php b/app/Http/Controllers/Admin/MountController.php index 79c729976..5ff73e153 100644 --- a/app/Http/Controllers/Admin/MountController.php +++ b/app/Http/Controllers/Admin/MountController.php @@ -205,7 +205,7 @@ class MountController extends Controller { $mount->eggs()->detach($egg_id); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } /** @@ -219,6 +219,6 @@ class MountController extends Controller { $mount->nodes()->detach($node_id); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } } diff --git a/app/Http/Controllers/Admin/NodesController.php b/app/Http/Controllers/Admin/NodesController.php index d482c47ae..56858511a 100644 --- a/app/Http/Controllers/Admin/NodesController.php +++ b/app/Http/Controllers/Admin/NodesController.php @@ -201,7 +201,7 @@ class NodesController extends Controller { $this->allocationDeletionService->handle($allocation); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } /** @@ -222,7 +222,7 @@ class NodesController extends Controller $this->allocationRemoveSingle($node, $allocation); } - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } /** @@ -261,7 +261,7 @@ class NodesController extends Controller 'ip_alias' => (empty($request->input('alias'))) ? null : $request->input('alias'), ]); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } /** diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index bec5ac4aa..11ac4f399 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -395,7 +395,7 @@ class ServersController extends Controller $this->databasePasswordService->handle($database); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } /** @@ -417,7 +417,7 @@ class ServersController extends Controller $this->databaseManagementService->delete($database); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } /** diff --git a/app/Http/Controllers/Admin/Settings/MailController.php b/app/Http/Controllers/Admin/Settings/MailController.php index ccd84fa5c..4d8c4915f 100644 --- a/app/Http/Controllers/Admin/Settings/MailController.php +++ b/app/Http/Controllers/Admin/Settings/MailController.php @@ -112,7 +112,7 @@ class MailController extends Controller $this->kernel->call('queue:restart'); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } /** @@ -130,6 +130,6 @@ class MailController extends Controller return response($exception->getMessage(), 500); } - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } } diff --git a/app/Http/Controllers/Api/Application/ApplicationApiController.php b/app/Http/Controllers/Api/Application/ApplicationApiController.php index 903edeb65..70d2bcfe2 100644 --- a/app/Http/Controllers/Api/Application/ApplicationApiController.php +++ b/app/Http/Controllers/Api/Application/ApplicationApiController.php @@ -59,7 +59,9 @@ abstract class ApplicationApiController extends Controller * Return an instance of an application transformer. * * @param string $abstract + * * @return \Pterodactyl\Transformers\Api\Application\BaseTransformer + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function getTransformer(string $abstract) { diff --git a/app/Http/Controllers/Api/Application/Locations/LocationController.php b/app/Http/Controllers/Api/Application/Locations/LocationController.php index 62ab4ea45..766f873de 100644 --- a/app/Http/Controllers/Api/Application/Locations/LocationController.php +++ b/app/Http/Controllers/Api/Application/Locations/LocationController.php @@ -2,7 +2,6 @@ namespace Pterodactyl\Http\Controllers\Api\Application\Locations; -use Illuminate\Http\Response; use Pterodactyl\Models\Location; use Illuminate\Http\JsonResponse; use Spatie\QueryBuilder\QueryBuilder; @@ -66,7 +65,9 @@ class LocationController extends ApplicationApiController * Return all of the locations currently registered on the Panel. * * @param \Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationsRequest $request + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetLocationsRequest $request): array { @@ -84,11 +85,14 @@ class LocationController extends ApplicationApiController * Return a single location. * * @param \Pterodactyl\Http\Requests\Api\Application\Locations\GetLocationRequest $request + * @param \Pterodactyl\Models\Location $location + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function view(GetLocationRequest $request): array + public function view(GetLocationRequest $request, Location $location): array { - return $this->fractal->item($request->getModel(Location::class)) + return $this->fractal->item($location) ->transformWith($this->getTransformer(LocationTransformer::class)) ->toArray(); } @@ -98,9 +102,11 @@ class LocationController extends ApplicationApiController * new location attached. * * @param \Pterodactyl\Http\Requests\Api\Application\Locations\StoreLocationRequest $request + * * @return \Illuminate\Http\JsonResponse * * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function store(StoreLocationRequest $request): JsonResponse { @@ -120,14 +126,17 @@ class LocationController extends ApplicationApiController * Update a location on the Panel and return the updated record to the user. * * @param \Pterodactyl\Http\Requests\Api\Application\Locations\UpdateLocationRequest $request + * @param \Pterodactyl\Models\Location $location + * * @return array * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function update(UpdateLocationRequest $request): array + public function update(UpdateLocationRequest $request, Location $location): array { - $location = $this->updateService->handle($request->getModel(Location::class), $request->validated()); + $location = $this->updateService->handle($location, $request->validated()); return $this->fractal->item($location) ->transformWith($this->getTransformer(LocationTransformer::class)) @@ -138,14 +147,16 @@ class LocationController extends ApplicationApiController * Delete a location from the Panel. * * @param \Pterodactyl\Http\Requests\Api\Application\Locations\DeleteLocationRequest $request - * @return \Illuminate\Http\Response + * @param \Pterodactyl\Models\Location $location + * + * @return \Illuminate\Http\JsonResponse * * @throws \Pterodactyl\Exceptions\Service\Location\HasActiveNodesException */ - public function delete(DeleteLocationRequest $request): Response + public function delete(DeleteLocationRequest $request, Location $location): JsonResponse { - $this->deletionService->handle($request->getModel(Location::class)); + $this->deletionService->handle($location); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } } diff --git a/app/Http/Controllers/Api/Application/Nests/EggController.php b/app/Http/Controllers/Api/Application/Nests/EggController.php index 21ce4ec9f..f475afbf6 100644 --- a/app/Http/Controllers/Api/Application/Nests/EggController.php +++ b/app/Http/Controllers/Api/Application/Nests/EggController.php @@ -33,12 +33,15 @@ class EggController extends ApplicationApiController * Return all eggs that exist for a given nest. * * @param \Pterodactyl\Http\Requests\Api\Application\Nests\Eggs\GetEggsRequest $request + * @param \Pterodactyl\Models\Nest $nest + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function index(GetEggsRequest $request): array + public function index(GetEggsRequest $request, Nest $nest): array { $eggs = $this->repository->findWhere([ - ['nest_id', '=', $request->getModel(Nest::class)->id], + ['nest_id', '=', $nest->id], ]); return $this->fractal->collection($eggs) @@ -50,11 +53,14 @@ class EggController extends ApplicationApiController * Return a single egg that exists on the specified nest. * * @param \Pterodactyl\Http\Requests\Api\Application\Nests\Eggs\GetEggRequest $request + * @param \Pterodactyl\Models\Egg $egg + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function view(GetEggRequest $request): array + public function view(GetEggRequest $request, Egg $egg): array { - return $this->fractal->item($request->getModel(Egg::class)) + return $this->fractal->item($egg) ->transformWith($this->getTransformer(EggTransformer::class)) ->toArray(); } diff --git a/app/Http/Controllers/Api/Application/Nests/NestController.php b/app/Http/Controllers/Api/Application/Nests/NestController.php index adeacc56c..42c0511a6 100644 --- a/app/Http/Controllers/Api/Application/Nests/NestController.php +++ b/app/Http/Controllers/Api/Application/Nests/NestController.php @@ -31,7 +31,9 @@ class NestController extends ApplicationApiController * Return all Nests that exist on the Panel. * * @param \Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest $request + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetNestsRequest $request): array { @@ -46,11 +48,14 @@ class NestController extends ApplicationApiController * Return information about a single Nest model. * * @param \Pterodactyl\Http\Requests\Api\Application\Nests\GetNestsRequest $request + * @param \Pterodactyl\Models\Nest $nest + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function view(GetNestsRequest $request): array + public function view(GetNestsRequest $request, Nest $nest): array { - return $this->fractal->item($request->getModel(Nest::class)) + return $this->fractal->item($nest) ->transformWith($this->getTransformer(NestTransformer::class)) ->toArray(); } diff --git a/app/Http/Controllers/Api/Application/Nodes/AllocationController.php b/app/Http/Controllers/Api/Application/Nodes/AllocationController.php index 01ec37fe1..8a22b8914 100644 --- a/app/Http/Controllers/Api/Application/Nodes/AllocationController.php +++ b/app/Http/Controllers/Api/Application/Nodes/AllocationController.php @@ -46,7 +46,9 @@ class AllocationController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Allocations\GetAllocationsRequest $request * @param \Pterodactyl\Models\Node $node + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetAllocationsRequest $request, Node $node): array { diff --git a/app/Http/Controllers/Api/Application/Nodes/NodeConfigurationController.php b/app/Http/Controllers/Api/Application/Nodes/NodeConfigurationController.php index fc0c35f75..cb172140b 100644 --- a/app/Http/Controllers/Api/Application/Nodes/NodeConfigurationController.php +++ b/app/Http/Controllers/Api/Application/Nodes/NodeConfigurationController.php @@ -20,6 +20,6 @@ class NodeConfigurationController extends ApplicationApiController */ public function __invoke(GetNodeRequest $request, Node $node) { - return JsonResponse::create($node->getConfiguration()); + return new JsonResponse($node->getConfiguration()); } } diff --git a/app/Http/Controllers/Api/Application/Nodes/NodeController.php b/app/Http/Controllers/Api/Application/Nodes/NodeController.php index 7198611ba..fc8f7f8f5 100644 --- a/app/Http/Controllers/Api/Application/Nodes/NodeController.php +++ b/app/Http/Controllers/Api/Application/Nodes/NodeController.php @@ -65,7 +65,9 @@ class NodeController extends ApplicationApiController * Return all of the nodes currently available on the Panel. * * @param \Pterodactyl\Http\Requests\Api\Application\Nodes\GetNodesRequest $request + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetNodesRequest $request): array { @@ -84,7 +86,9 @@ class NodeController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Nodes\GetNodeRequest $request * @param \Pterodactyl\Models\Node $node + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function view(GetNodeRequest $request, Node $node): array { @@ -98,9 +102,10 @@ class NodeController extends ApplicationApiController * status response on success. * * @param \Pterodactyl\Http\Requests\Api\Application\Nodes\StoreNodeRequest $request + * * @return \Illuminate\Http\JsonResponse * - * @throws \Pterodactyl\Exceptions\Model\DataValidationException + * @throws \Pterodactyl\Exceptions\Model\DataValidationException*@throws \Illuminate\Contracts\Container\BindingResolutionException */ public function store(StoreNodeRequest $request): JsonResponse { @@ -121,6 +126,7 @@ class NodeController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Nodes\UpdateNodeRequest $request * @param \Pterodactyl\Models\Node $node + * * @return array * * @throws \Throwable @@ -142,6 +148,7 @@ class NodeController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Nodes\DeleteNodeRequest $request * @param \Pterodactyl\Models\Node $node + * * @return \Illuminate\Http\JsonResponse * * @throws \Pterodactyl\Exceptions\Service\HasActiveServersException diff --git a/app/Http/Controllers/Api/Application/Roles/RoleController.php b/app/Http/Controllers/Api/Application/Roles/RoleController.php index dced9d7a6..bc7363994 100644 --- a/app/Http/Controllers/Api/Application/Roles/RoleController.php +++ b/app/Http/Controllers/Api/Application/Roles/RoleController.php @@ -37,8 +37,9 @@ class RoleController extends ApplicationApiController * @param \Pterodactyl\Http\Requests\Api\Application\Roles\GetRolesRequest $request * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function index(GetRolesRequest $request) + public function index(GetRolesRequest $request): array { return $this->fractal->collection(AdminRole::all()) ->transformWith($this->getTransformer(AdminRoleTransformer::class)) @@ -52,6 +53,7 @@ class RoleController extends ApplicationApiController * @param \Pterodactyl\Models\AdminRole $role * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function view(GetRolesRequest $request, AdminRole $role): array { @@ -66,8 +68,9 @@ class RoleController extends ApplicationApiController * @param \Pterodactyl\Http\Requests\Api\Application\Roles\StoreRoleRequest $request * * @return \Illuminate\Http\JsonResponse + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function store(StoreRoleRequest $request) + public function store(StoreRoleRequest $request): JsonResponse { $role = AdminRole::query()->create($request->validated()); @@ -83,8 +86,9 @@ class RoleController extends ApplicationApiController * @param \Pterodactyl\Models\AdminRole $role * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function update(UpdateRoleRequest $request, AdminRole $role) + public function update(UpdateRoleRequest $request, AdminRole $role): array { $role->update($request->validated()); @@ -101,7 +105,7 @@ class RoleController extends ApplicationApiController * * @return \Illuminate\Http\JsonResponse */ - public function delete(DeleteRoleRequest $request, AdminRole $role) + public function delete(DeleteRoleRequest $request, AdminRole $role): JsonResponse { $this->repository->delete($role->id); diff --git a/app/Http/Controllers/Api/Application/Servers/DatabaseController.php b/app/Http/Controllers/Api/Application/Servers/DatabaseController.php index 829a6ca5d..566bd98fd 100644 --- a/app/Http/Controllers/Api/Application/Servers/DatabaseController.php +++ b/app/Http/Controllers/Api/Application/Servers/DatabaseController.php @@ -44,7 +44,8 @@ class DatabaseController extends ApplicationApiController DatabaseManagementService $databaseManagementService, DatabasePasswordService $databasePasswordService, DatabaseRepositoryInterface $repository - ) { + ) + { parent::__construct(); $this->databaseManagementService = $databaseManagementService; @@ -58,7 +59,9 @@ class DatabaseController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\GetServerDatabasesRequest $request * @param \Pterodactyl\Models\Server $server + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetServerDatabasesRequest $request, Server $server): array { @@ -73,7 +76,9 @@ class DatabaseController extends ApplicationApiController * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\GetServerDatabaseRequest $request * @param \Pterodactyl\Models\Server $server * @param \Pterodactyl\Models\Database $database + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function view(GetServerDatabaseRequest $request, Server $server, Database $database): array { @@ -88,6 +93,7 @@ class DatabaseController extends ApplicationApiController * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\ServerDatabaseWriteRequest $request * @param \Pterodactyl\Models\Server $server * @param \Pterodactyl\Models\Database $database + * * @return \Illuminate\Http\JsonResponse * * @throws \Throwable @@ -96,7 +102,7 @@ class DatabaseController extends ApplicationApiController { $this->databasePasswordService->handle($database); - return JsonResponse::create([], JsonResponse::HTTP_NO_CONTENT); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } /** @@ -104,6 +110,7 @@ class DatabaseController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\StoreServerDatabaseRequest $request * @param \Pterodactyl\Models\Server $server + * * @return \Illuminate\Http\JsonResponse * * @throws \Throwable @@ -129,14 +136,16 @@ class DatabaseController extends ApplicationApiController * Handle a request to delete a specific server database from the Panel. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\Databases\ServerDatabaseWriteRequest $request - * @return \Illuminate\Http\Response + * @param \Pterodactyl\Models\Database $database * - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @return \Illuminate\Http\JsonResponse + * + * @throws \Exception */ - public function delete(ServerDatabaseWriteRequest $request): Response + public function delete(ServerDatabaseWriteRequest $request, Database $database): JsonResponse { - $this->databaseManagementService->delete($request->getModel(Database::class)); + $this->databaseManagementService->delete($database); - return response('', 204); + return new JsonResponse([], JsonResponse::HTTP_NO_CONTENT); } } diff --git a/app/Http/Controllers/Api/Application/Servers/ExternalServerController.php b/app/Http/Controllers/Api/Application/Servers/ExternalServerController.php index 391c5645c..45c0243cc 100644 --- a/app/Http/Controllers/Api/Application/Servers/ExternalServerController.php +++ b/app/Http/Controllers/Api/Application/Servers/ExternalServerController.php @@ -12,7 +12,9 @@ class ExternalServerController extends ApplicationApiController * Retrieve a specific server from the database using its external ID. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetExternalServerRequest $request + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetExternalServerRequest $request): array { diff --git a/app/Http/Controllers/Api/Application/Servers/ServerController.php b/app/Http/Controllers/Api/Application/Servers/ServerController.php index 126c91921..e43364bcf 100644 --- a/app/Http/Controllers/Api/Application/Servers/ServerController.php +++ b/app/Http/Controllers/Api/Application/Servers/ServerController.php @@ -22,12 +22,10 @@ class ServerController extends ApplicationApiController * @var \Pterodactyl\Services\Servers\ServerCreationService */ private $creationService; - /** * @var \Pterodactyl\Services\Servers\ServerDeletionService */ private $deletionService; - /** * @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface */ @@ -44,7 +42,8 @@ class ServerController extends ApplicationApiController ServerCreationService $creationService, ServerDeletionService $deletionService, ServerRepositoryInterface $repository - ) { + ) + { parent::__construct(); $this->creationService = $creationService; @@ -56,7 +55,9 @@ class ServerController extends ApplicationApiController * Return all of the servers that currently exist on the Panel. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServersRequest $request + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetServersRequest $request): array { @@ -74,12 +75,12 @@ class ServerController extends ApplicationApiController * Create a new server on the system. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\StoreServerRequest $request + * * @return \Illuminate\Http\JsonResponse * * @throws \Throwable * @throws \Illuminate\Validation\ValidationException * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableAllocationException * @throws \Pterodactyl\Exceptions\Service\Deployment\NoViableNodeException @@ -97,22 +98,28 @@ class ServerController extends ApplicationApiController * Show a single server transformed for the application API. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\GetServerRequest $request + * @param \Pterodactyl\Models\Server $server + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ - public function view(GetServerRequest $request): array + public function view(GetServerRequest $request, Server $server): array { - return $this->fractal->item($request->getModel(Server::class)) + return $this->fractal->item($server) ->transformWith($this->getTransformer(ServerTransformer::class)) ->toArray(); } /** + * Deletes a server. + * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request * @param \Pterodactyl\Models\Server $server * @param string $force + * * @return \Illuminate\Http\Response * - * @throws \Pterodactyl\Exceptions\DisplayException + * @throws \Throwable */ public function delete(ServerWriteRequest $request, Server $server, string $force = ''): Response { diff --git a/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php b/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php index c2c3fa1cf..4cd9bc3d2 100644 --- a/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php +++ b/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php @@ -42,16 +42,17 @@ class ServerDetailsController extends ApplicationApiController * Update the details for a specific server. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerDetailsRequest $request + * @param \Pterodactyl\Models\Server $server + * * @return array * - * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Illuminate\Contracts\Container\BindingResolutionException + * @throws \Throwable */ - public function details(UpdateServerDetailsRequest $request): array + public function details(UpdateServerDetailsRequest $request, Server $server): array { $server = $this->detailsModificationService->returnUpdatedModel()->handle( - $request->getModel(Server::class), $request->validated() + $server, $request->validated() ); return $this->fractal->item($server) @@ -64,11 +65,11 @@ class ServerDetailsController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest $request * @param \Pterodactyl\Models\Server $server + * * @return array * + * @throws \Throwable * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array { diff --git a/app/Http/Controllers/Api/Application/Servers/ServerManagementController.php b/app/Http/Controllers/Api/Application/Servers/ServerManagementController.php index 5052c884e..f1b78aca3 100644 --- a/app/Http/Controllers/Api/Application/Servers/ServerManagementController.php +++ b/app/Http/Controllers/Api/Application/Servers/ServerManagementController.php @@ -42,6 +42,7 @@ class ServerManagementController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request * @param \Pterodactyl\Models\Server $server + * * @return \Illuminate\Http\Response * * @throws \Throwable @@ -58,6 +59,7 @@ class ServerManagementController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request * @param \Pterodactyl\Models\Server $server + * * @return \Illuminate\Http\Response * * @throws \Throwable @@ -74,11 +76,10 @@ class ServerManagementController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request * @param \Pterodactyl\Models\Server $server + * * @return \Illuminate\Http\Response * - * @throws \Pterodactyl\Exceptions\DisplayException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Throwable */ public function reinstall(ServerWriteRequest $request, Server $server): Response { diff --git a/app/Http/Controllers/Api/Application/Servers/StartupController.php b/app/Http/Controllers/Api/Application/Servers/StartupController.php index 0265af464..f114132b2 100644 --- a/app/Http/Controllers/Api/Application/Servers/StartupController.php +++ b/app/Http/Controllers/Api/Application/Servers/StartupController.php @@ -32,18 +32,16 @@ class StartupController extends ApplicationApiController * Update the startup and environment settings for a specific server. * * @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerStartupRequest $request - * @return array + * @param \Pterodactyl\Models\Server $server * - * @throws \Illuminate\Validation\ValidationException - * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException - * @throws \Pterodactyl\Exceptions\Model\DataValidationException - * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @return array + * @throws \Throwable */ - public function index(UpdateServerStartupRequest $request): array + public function index(UpdateServerStartupRequest $request, Server $server): array { $server = $this->modificationService ->setUserLevel(User::USER_LEVEL_ADMIN) - ->handle($request->getModel(Server::class), $request->validated()); + ->handle($server, $request->validated()); return $this->fractal->item($server) ->transformWith($this->getTransformer(ServerTransformer::class)) diff --git a/app/Http/Controllers/Api/Application/Users/ExternalUserController.php b/app/Http/Controllers/Api/Application/Users/ExternalUserController.php index f58138173..02d435f27 100644 --- a/app/Http/Controllers/Api/Application/Users/ExternalUserController.php +++ b/app/Http/Controllers/Api/Application/Users/ExternalUserController.php @@ -12,7 +12,9 @@ class ExternalUserController extends ApplicationApiController * Retrieve a specific user from the database using their external ID. * * @param \Pterodactyl\Http\Requests\Api\Application\Users\GetExternalUserRequest $request + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetExternalUserRequest $request): array { diff --git a/app/Http/Controllers/Api/Application/Users/UserController.php b/app/Http/Controllers/Api/Application/Users/UserController.php index c8b309d85..495d92fd3 100644 --- a/app/Http/Controllers/Api/Application/Users/UserController.php +++ b/app/Http/Controllers/Api/Application/Users/UserController.php @@ -3,7 +3,6 @@ namespace Pterodactyl\Http\Controllers\Api\Application\Users; use Pterodactyl\Models\User; -use Illuminate\Http\Response; use Illuminate\Http\JsonResponse; use Spatie\QueryBuilder\QueryBuilder; use Pterodactyl\Services\Users\UserUpdateService; @@ -52,7 +51,8 @@ class UserController extends ApplicationApiController UserCreationService $creationService, UserDeletionService $deletionService, UserUpdateService $updateService - ) { + ) + { parent::__construct(); $this->creationService = $creationService; @@ -67,7 +67,9 @@ class UserController extends ApplicationApiController * the request. * * @param \Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest $request + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function index(GetUsersRequest $request): array { @@ -87,7 +89,9 @@ class UserController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Users\GetUsersRequest $request * @param \Pterodactyl\Models\User $user + * * @return array + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function view(GetUsersRequest $request, User $user): array { @@ -106,10 +110,12 @@ class UserController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Users\UpdateUserRequest $request * @param \Pterodactyl\Models\User $user + * * @return array * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function update(UpdateUserRequest $request, User $user): array { @@ -127,6 +133,7 @@ class UserController extends ApplicationApiController * header on successful creation. * * @param \Pterodactyl\Http\Requests\Api\Application\Users\StoreUserRequest $request + * * @return \Illuminate\Http\JsonResponse * * @throws \Exception @@ -152,6 +159,7 @@ class UserController extends ApplicationApiController * * @param \Pterodactyl\Http\Requests\Api\Application\Users\DeleteUserRequest $request * @param \Pterodactyl\Models\User $user + * * @return \Illuminate\Http\JsonResponse * * @throws \Pterodactyl\Exceptions\DisplayException diff --git a/app/Http/Requests/Api/Application/Users/GetExternalUserRequest.php b/app/Http/Requests/Api/Application/Users/GetExternalUserRequest.php index 4ad98c0fc..acad394a2 100644 --- a/app/Http/Requests/Api/Application/Users/GetExternalUserRequest.php +++ b/app/Http/Requests/Api/Application/Users/GetExternalUserRequest.php @@ -29,6 +29,7 @@ class GetExternalUserRequest extends ApplicationApiRequest * Determine if the requested external user exists. * * @return bool + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function resourceExists(): bool { diff --git a/app/Transformers/Api/Application/AdminRoleTransformer.php b/app/Transformers/Api/Application/AdminRoleTransformer.php index de3ebded2..5061185f3 100644 --- a/app/Transformers/Api/Application/AdminRoleTransformer.php +++ b/app/Transformers/Api/Application/AdminRoleTransformer.php @@ -19,15 +19,15 @@ class AdminRoleTransformer extends BaseTransformer /** * Return a transformed User model that can be consumed by external services. * - * @param \Pterodactyl\Models\AdminRole $role + * @param \Pterodactyl\Models\AdminRole $model * @return array */ - public function transform(AdminRole $role): array + public function transform(AdminRole $model): array { return [ - 'id' => $role->id, - 'name' => $role->name, - 'description' => $role->description, + 'id' => $model->id, + 'name' => $model->name, + 'description' => $model->description, ]; } } diff --git a/app/Transformers/Api/Application/AllocationTransformer.php b/app/Transformers/Api/Application/AllocationTransformer.php index d0c71e634..82621c42f 100644 --- a/app/Transformers/Api/Application/AllocationTransformer.php +++ b/app/Transformers/Api/Application/AllocationTransformer.php @@ -29,18 +29,19 @@ class AllocationTransformer extends BaseTransformer /** * Return a generic transformed allocation array. * - * @param \Pterodactyl\Models\Allocation $allocation + * @param \Pterodactyl\Models\Allocation $model + * * @return array */ - public function transform(Allocation $allocation) + public function transform(Allocation $model) { return [ - 'id' => $allocation->id, - 'ip' => $allocation->ip, - 'alias' => $allocation->ip_alias, - 'port' => $allocation->port, - 'notes' => $allocation->notes, - 'assigned' => ! is_null($allocation->server_id), + 'id' => $model->id, + 'ip' => $model->ip, + 'alias' => $model->ip_alias, + 'port' => $model->port, + 'notes' => $model->notes, + 'assigned' => ! is_null($model->server_id), ]; } @@ -48,8 +49,10 @@ class AllocationTransformer extends BaseTransformer * Load the node relationship onto a given transformation. * * @param \Pterodactyl\Models\Allocation $allocation + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeNode(Allocation $allocation) { @@ -66,8 +69,10 @@ class AllocationTransformer extends BaseTransformer * Load the server relationship onto a given transformation. * * @param \Pterodactyl\Models\Allocation $allocation + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeServer(Allocation $allocation) { diff --git a/app/Transformers/Api/Application/BaseTransformer.php b/app/Transformers/Api/Application/BaseTransformer.php index 563dd086c..3bdd0ad91 100644 --- a/app/Transformers/Api/Application/BaseTransformer.php +++ b/app/Transformers/Api/Application/BaseTransformer.php @@ -44,6 +44,7 @@ abstract class BaseTransformer extends TransformerAbstract * Set the HTTP request class being used for this request. * * @param \Pterodactyl\Models\ApiKey $key + * * @return $this */ public function setKey(ApiKey $key) @@ -69,6 +70,7 @@ abstract class BaseTransformer extends TransformerAbstract * models on a transformation request. * * @param string $resource + * * @return bool */ protected function authorize(string $resource): bool @@ -82,8 +84,10 @@ abstract class BaseTransformer extends TransformerAbstract * * @param string $abstract * @param array $parameters + * * @return \Pterodactyl\Transformers\Api\Application\BaseTransformer * + * @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException */ protected function makeTransformer(string $abstract, array $parameters = []) @@ -103,6 +107,7 @@ abstract class BaseTransformer extends TransformerAbstract * Return an ISO-8601 formatted timestamp to use in the API response. * * @param string $timestamp + * * @return string */ protected function formatTimestamp(string $timestamp): string diff --git a/app/Transformers/Api/Application/DatabaseHostTransformer.php b/app/Transformers/Api/Application/DatabaseHostTransformer.php index 3ef10e8ad..1505e5b6d 100644 --- a/app/Transformers/Api/Application/DatabaseHostTransformer.php +++ b/app/Transformers/Api/Application/DatabaseHostTransformer.php @@ -30,6 +30,7 @@ class DatabaseHostTransformer extends BaseTransformer * Transform database host into a representation for the application API. * * @param \Pterodactyl\Models\DatabaseHost $model + * * @return array */ public function transform(DatabaseHost $model) @@ -54,6 +55,7 @@ class DatabaseHostTransformer extends BaseTransformer * Include the databases associated with this host. * * @param \Pterodactyl\Models\DatabaseHost $model + * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException */ diff --git a/app/Transformers/Api/Application/EggTransformer.php b/app/Transformers/Api/Application/EggTransformer.php index 96a0abfb9..cbfe21e56 100644 --- a/app/Transformers/Api/Application/EggTransformer.php +++ b/app/Transformers/Api/Application/EggTransformer.php @@ -34,6 +34,7 @@ class EggTransformer extends BaseTransformer * the application api. * * @param \Pterodactyl\Models\Egg $model + * * @return array */ public function transform(Egg $model) @@ -74,8 +75,10 @@ class EggTransformer extends BaseTransformer * Include the Nest relationship for the given Egg in the transformation. * * @param \Pterodactyl\Models\Egg $model + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeNest(Egg $model) { @@ -92,8 +95,10 @@ class EggTransformer extends BaseTransformer * Include the Servers relationship for the given Egg in the transformation. * * @param \Pterodactyl\Models\Egg $model + * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeServers(Egg $model) { @@ -111,6 +116,7 @@ class EggTransformer extends BaseTransformer * extending another. * * @param \Pterodactyl\Models\Egg $model + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource */ public function includeConfig(Egg $model) @@ -136,6 +142,7 @@ class EggTransformer extends BaseTransformer * Egg is extending another. * * @param \Pterodactyl\Models\Egg $model + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource */ public function includeScript(Egg $model) @@ -160,8 +167,10 @@ class EggTransformer extends BaseTransformer * Include the variables that are defined for this Egg. * * @param \Pterodactyl\Models\Egg $model + * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeVariables(Egg $model) { diff --git a/app/Transformers/Api/Application/LocationTransformer.php b/app/Transformers/Api/Application/LocationTransformer.php index 7d24cc974..bd12916dc 100644 --- a/app/Transformers/Api/Application/LocationTransformer.php +++ b/app/Transformers/Api/Application/LocationTransformer.php @@ -27,17 +27,17 @@ class LocationTransformer extends BaseTransformer /** * Return a generic transformed location array. * - * @param \Pterodactyl\Models\Location $location + * @param \Pterodactyl\Models\Location $model * @return array */ - public function transform(Location $location): array + public function transform(Location $model): array { return [ - 'id' => $location->id, - 'short' => $location->short, - 'long' => $location->long, - $location->getUpdatedAtColumn() => $this->formatTimestamp($location->updated_at), - $location->getCreatedAtColumn() => $this->formatTimestamp($location->created_at), + 'id' => $model->id, + 'short' => $model->short, + 'long' => $model->long, + $model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at), + $model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at), ]; } diff --git a/app/Transformers/Api/Application/NodeTransformer.php b/app/Transformers/Api/Application/NodeTransformer.php index c26d67cef..7fcea2b13 100644 --- a/app/Transformers/Api/Application/NodeTransformer.php +++ b/app/Transformers/Api/Application/NodeTransformer.php @@ -28,12 +28,13 @@ class NodeTransformer extends BaseTransformer * Return a node transformed into a format that can be consumed by the * external administrative API. * - * @param \Pterodactyl\Models\Node $node + * @param \Pterodactyl\Models\Node $model + * * @return array */ - public function transform(Node $node): array + public function transform(Node $model): array { - $response = collect($node->toArray())->mapWithKeys(function ($value, $key) { + $response = collect($model->toArray())->mapWithKeys(function ($value, $key) { // I messed up early in 2016 when I named this column as poorly // as I did. This is the tragic result of my mistakes. $key = ($key === 'daemonSFTP') ? 'daemonSftp' : $key; @@ -41,10 +42,10 @@ class NodeTransformer extends BaseTransformer return [snake_case($key) => $value]; })->toArray(); - $response[$node->getUpdatedAtColumn()] = $this->formatTimestamp($node->updated_at); - $response[$node->getCreatedAtColumn()] = $this->formatTimestamp($node->created_at); + $response[$model->getUpdatedAtColumn()] = $this->formatTimestamp($model->updated_at); + $response[$model->getCreatedAtColumn()] = $this->formatTimestamp($model->created_at); - $resources = $node->servers()->select(['memory', 'disk'])->get(); + $resources = $model->servers()->select(['memory', 'disk'])->get(); $response['allocated_resources'] = [ 'memory' => $resources->sum('memory'), @@ -58,8 +59,10 @@ class NodeTransformer extends BaseTransformer * Return the nodes associated with this location. * * @param \Pterodactyl\Models\Node $node + * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeAllocations(Node $node) { @@ -78,8 +81,10 @@ class NodeTransformer extends BaseTransformer * Return the nodes associated with this location. * * @param \Pterodactyl\Models\Node $node + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeLocation(Node $node) { @@ -98,8 +103,10 @@ class NodeTransformer extends BaseTransformer * Return the nodes associated with this location. * * @param \Pterodactyl\Models\Node $node + * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeServers(Node $node) { diff --git a/app/Transformers/Api/Application/ServerTransformer.php b/app/Transformers/Api/Application/ServerTransformer.php index 10c343d8c..e58152bb0 100644 --- a/app/Transformers/Api/Application/ServerTransformer.php +++ b/app/Transformers/Api/Application/ServerTransformer.php @@ -54,45 +54,46 @@ class ServerTransformer extends BaseTransformer /** * Return a generic transformed server array. * - * @param \Pterodactyl\Models\Server $server + * @param \Pterodactyl\Models\Server $model + * * @return array */ - public function transform(Server $server): array + public function transform(Server $model): array { return [ - 'id' => $server->getKey(), - 'external_id' => $server->external_id, - 'uuid' => $server->uuid, - 'identifier' => $server->uuidShort, - 'name' => $server->name, - 'description' => $server->description, - 'suspended' => (bool) $server->suspended, + 'id' => $model->getKey(), + 'external_id' => $model->external_id, + 'uuid' => $model->uuid, + 'identifier' => $model->uuidShort, + 'name' => $model->name, + 'description' => $model->description, + 'suspended' => (bool) $model->suspended, 'limits' => [ - 'memory' => $server->memory, - 'swap' => $server->swap, - 'disk' => $server->disk, - 'io' => $server->io, - 'cpu' => $server->cpu, - 'threads' => $server->threads, + 'memory' => $model->memory, + 'swap' => $model->swap, + 'disk' => $model->disk, + 'io' => $model->io, + 'cpu' => $model->cpu, + 'threads' => $model->threads, ], 'feature_limits' => [ - 'databases' => $server->database_limit, - 'allocations' => $server->allocation_limit, - 'backups' => $server->backup_limit, + 'databases' => $model->database_limit, + 'allocations' => $model->allocation_limit, + 'backups' => $model->backup_limit, ], - 'user' => $server->owner_id, - 'node' => $server->node_id, - 'allocation' => $server->allocation_id, - 'nest' => $server->nest_id, - 'egg' => $server->egg_id, + 'user' => $model->owner_id, + 'node' => $model->node_id, + 'allocation' => $model->allocation_id, + 'nest' => $model->nest_id, + 'egg' => $model->egg_id, 'container' => [ - 'startup_command' => $server->startup, - 'image' => $server->image, - 'installed' => (int) $server->installed === 1, - 'environment' => $this->environmentService->handle($server), + 'startup_command' => $model->startup, + 'image' => $model->image, + 'installed' => (int) $model->installed === 1, + 'environment' => $this->environmentService->handle($model), ], - $server->getUpdatedAtColumn() => $this->formatTimestamp($server->updated_at), - $server->getCreatedAtColumn() => $this->formatTimestamp($server->created_at), + $model->getUpdatedAtColumn() => $this->formatTimestamp($model->updated_at), + $model->getCreatedAtColumn() => $this->formatTimestamp($model->created_at), ]; } @@ -100,9 +101,11 @@ class ServerTransformer extends BaseTransformer * Return a generic array of allocations for this server. * * @param \Pterodactyl\Models\Server $server + * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeAllocations(Server $server) { @@ -119,9 +122,11 @@ class ServerTransformer extends BaseTransformer * Return a generic array of data about subusers for this server. * * @param \Pterodactyl\Models\Server $server + * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeSubusers(Server $server) { @@ -138,9 +143,11 @@ class ServerTransformer extends BaseTransformer * Return a generic array of data about subusers for this server. * * @param \Pterodactyl\Models\Server $server + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeUser(Server $server) { @@ -157,9 +164,11 @@ class ServerTransformer extends BaseTransformer * Return a generic array with nest information for this server. * * @param \Pterodactyl\Models\Server $server + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeNest(Server $server) { @@ -176,9 +185,11 @@ class ServerTransformer extends BaseTransformer * Return a generic array with egg information for this server. * * @param \Pterodactyl\Models\Server $server + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeEgg(Server $server) { @@ -195,9 +206,11 @@ class ServerTransformer extends BaseTransformer * Return a generic array of data about subusers for this server. * * @param \Pterodactyl\Models\Server $server + * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeVariables(Server $server) { @@ -214,9 +227,11 @@ class ServerTransformer extends BaseTransformer * Return a generic array with location information for this server. * * @param \Pterodactyl\Models\Server $server + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeLocation(Server $server) { @@ -233,9 +248,11 @@ class ServerTransformer extends BaseTransformer * Return a generic array with node information for this server. * * @param \Pterodactyl\Models\Server $server + * * @return \League\Fractal\Resource\Item|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeNode(Server $server) { @@ -252,9 +269,11 @@ class ServerTransformer extends BaseTransformer * Return a generic array with database information for this server. * * @param \Pterodactyl\Models\Server $server + * * @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource * * @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function includeDatabases(Server $server) { diff --git a/resources/scripts/components/admin/AdminCheckbox.tsx b/resources/scripts/components/admin/AdminCheckbox.tsx index 6d1ed5b5d..3acdf2bee 100644 --- a/resources/scripts/components/admin/AdminCheckbox.tsx +++ b/resources/scripts/components/admin/AdminCheckbox.tsx @@ -3,7 +3,7 @@ import React from 'react'; import styled from 'styled-components/macro'; import tw from 'twin.macro'; -const Checkbox = styled(Input)` +export const TableCheckbox = styled(Input)` && { ${tw`border-neutral-500 bg-transparent`}; @@ -13,12 +13,14 @@ const Checkbox = styled(Input)` } `; -export default ({ name }: { name: string }) => { +export default ({ name, checked, onChange }: { name: string, checked: boolean, onChange(e: React.ChangeEvent): void }) => { return ( - ); }; diff --git a/resources/scripts/components/admin/AdminContentBlock.tsx b/resources/scripts/components/admin/AdminContentBlock.tsx index 28873a71b..6be209af1 100644 --- a/resources/scripts/components/admin/AdminContentBlock.tsx +++ b/resources/scripts/components/admin/AdminContentBlock.tsx @@ -1,29 +1,29 @@ import React from 'react'; -import { CSSTransition } from 'react-transition-group'; +// import { CSSTransition } from 'react-transition-group'; import tw from 'twin.macro'; import FlashMessageRender from '@/components/FlashMessageRender'; const PageContentBlock: React.FC<{ showFlashKey?: string; className?: string }> = ({ children, showFlashKey }) => ( - - <> - {showFlashKey && - - } - {children} + // + <> + {showFlashKey && + + } + {children} - {/*

- © 2015 - 2020  - - Pterodactyl Software - -

*/} - -
+ {/*

+ © 2015 - 2021  + + Pterodactyl Software + +

*/} + + //
); export default PageContentBlock; diff --git a/resources/scripts/components/admin/nests/NestsContainer.tsx b/resources/scripts/components/admin/nests/NestsContainer.tsx index 352e4bc9d..9ae2f96ce 100644 --- a/resources/scripts/components/admin/nests/NestsContainer.tsx +++ b/resources/scripts/components/admin/nests/NestsContainer.tsx @@ -1,4 +1,3 @@ -import AdminCheckbox from '@/components/admin/AdminCheckbox'; import React, { useEffect, useState } from 'react'; import getNests from '@/api/admin/nests/getNests'; import { httpErrorToHuman } from '@/api/http'; @@ -11,6 +10,27 @@ import { AdminContext } from '@/state/admin'; import { NavLink, useRouteMatch } from 'react-router-dom'; import tw from 'twin.macro'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; +import AdminCheckbox, { TableCheckbox } from '@/components/admin/AdminCheckbox'; + +const RowCheckbox = ({ id }: { id: number}) => { + const isChecked = AdminContext.useStoreState(state => state.nests.selectedNests.indexOf(id) >= 0); + const appendSelectedNest = AdminContext.useStoreActions(actions => actions.nests.appendSelectedNest); + const removeSelectedNest = AdminContext.useStoreActions(actions => actions.nests.removeSelectedNest); + + return ( + ) => { + if (e.currentTarget.checked) { + appendSelectedNest(name); + } else { + removeSelectedNest(name); + } + }} + /> + ); +}; export default () => { const match = useRouteMatch(); @@ -21,6 +41,9 @@ export default () => { const nests = useDeepMemoize(AdminContext.useStoreState(state => state.nests.data)); const setNests = AdminContext.useStoreActions(state => state.nests.setNests); + const setSelectedNests = AdminContext.useStoreActions(actions => actions.nests.setSelectedNests); + const selectedNestsLength = AdminContext.useStoreState(state => state.nests.selectedNests.length); + useEffect(() => { setLoading(!nests.length); clearFlashes('nests'); @@ -34,6 +57,10 @@ export default () => { .then(() => setLoading(false)); }, []); + const onSelectAllClick = (e: React.ChangeEvent) => { + setSelectedNests(e.currentTarget.checked ? (nests?.map(nest => nest.id) || []) : []); + }; + return (
@@ -47,8 +74,8 @@ export default () => { -
-
+
+
{ loading ?
@@ -66,7 +93,12 @@ export default () => { <>
- + @@ -138,16 +170,16 @@ export default () => { nests.map(nest => (
- + - {nest.id} + {nest.id} {nest.name} - {nest.description} + {nest.description}
)) } @@ -168,35 +200,35 @@ export default () => {
- + 1 - + 2 - - + ... - - + 8 - + 9 - + diff --git a/resources/scripts/routers/AdminRouter.tsx b/resources/scripts/routers/AdminRouter.tsx index 4cc91d434..ee153f744 100644 --- a/resources/scripts/routers/AdminRouter.tsx +++ b/resources/scripts/routers/AdminRouter.tsx @@ -165,7 +165,7 @@ const AdminRouter = ({ location, match }: RouteComponentProps) => {
-
+
{/* */} diff --git a/resources/scripts/state/admin/index.ts b/resources/scripts/state/admin/index.ts index 1483b6b12..7d435e6db 100644 --- a/resources/scripts/state/admin/index.ts +++ b/resources/scripts/state/admin/index.ts @@ -1,5 +1,6 @@ import { createContextStore } from 'easy-peasy'; import { composeWithDevTools } from 'redux-devtools-extension'; + import nests, { AdminNestStore } from '@/state/admin/nests'; import roles, { AdminRoleStore } from '@/state/admin/roles'; diff --git a/resources/scripts/state/admin/nests.ts b/resources/scripts/state/admin/nests.ts index bf1d8d2cf..3002c6d2c 100644 --- a/resources/scripts/state/admin/nests.ts +++ b/resources/scripts/state/admin/nests.ts @@ -3,13 +3,20 @@ import { Nest } from '@/api/admin/nests/getNests'; export interface AdminNestStore { data: Nest[]; + selectedNests: number[]; + setNests: Action; appendNest: Action; removeNest: Action; + + setSelectedNests: Action; + appendSelectedNest: Action; + removeSelectedNest: Action; } const nests: AdminNestStore = { data: [], + selectedNests: [], setNests: action((state, payload) => { state.data = payload; @@ -26,6 +33,22 @@ const nests: AdminNestStore = { removeNest: action((state, payload) => { state.data = [ ...state.data.filter(nest => nest.id !== payload) ]; }), + + setSelectedNests: action((state, payload) => { + state.selectedNests = payload; + }), + + appendSelectedNest: action((state, payload) => { + if (state.selectedNests.find(id => id === payload)) { + state.selectedNests = state.selectedNests.map(id => id === payload ? payload : id); + } else { + state.selectedNests = [ ...state.selectedNests, payload ]; + } + }), + + removeSelectedNest: action((state, payload) => { + state.selectedNests = [ ...state.selectedNests.filter(id => id !== payload) ]; + }), }; export default nests; diff --git a/resources/scripts/state/admin/roles.ts b/resources/scripts/state/admin/roles.ts index bf6bf418c..c05d797ce 100644 --- a/resources/scripts/state/admin/roles.ts +++ b/resources/scripts/state/admin/roles.ts @@ -3,6 +3,7 @@ import { Role } from '@/api/admin/roles/getRoles'; export interface AdminRoleStore { data: Role[]; + setRoles: Action; appendRole: Action; removeRole: Action;