From d61ea6d5aec73fc356613e9d099e840debc41e80 Mon Sep 17 00:00:00 2001 From: Eric Wang <37554696+ericwang401@users.noreply.github.com> Date: Wed, 29 Nov 2023 19:28:44 -0600 Subject: [PATCH] Rename base API controller --- .../Admin/AddressPools/AddressController.php | 67 ++++++++------ .../AddressPools/AddressPoolController.php | 58 ++++++++----- .../Controllers/Admin/CotermController.php | 4 +- .../Controllers/Admin/LocationController.php | 26 +++--- .../Controllers/Admin/Nodes/IsoController.php | 49 ++++++----- .../Admin/Nodes/NodeController.php | 48 +++++----- .../Admin/Nodes/TemplateController.php | 44 ++++++---- .../Admin/Nodes/TemplateGroupController.php | 46 +++++----- .../Controllers/Admin/ServerController.php | 68 +++++++++------ .../Controllers/Admin/TokenController.php | 18 ++-- app/Http/Controllers/Admin/UserController.php | 40 +++++---- ...ionApiController.php => ApiController.php} | 2 +- .../Controllers/Client/IndexController.php | 20 +++-- .../Client/Servers/BackupController.php | 16 ++-- .../Client/Servers/ServerController.php | 24 ++--- .../Client/Servers/SettingsController.php | 87 +++++++++++-------- .../Client/Servers/SnapshotController.php | 18 ++-- 17 files changed, 372 insertions(+), 263 deletions(-) rename app/Http/Controllers/{ApplicationApiController.php => ApiController.php} (81%) diff --git a/app/Http/Controllers/Admin/AddressPools/AddressController.php b/app/Http/Controllers/Admin/AddressPools/AddressController.php index cdb3364d19a..b84ba1ce2db 100644 --- a/app/Http/Controllers/Admin/AddressPools/AddressController.php +++ b/app/Http/Controllers/Admin/AddressPools/AddressController.php @@ -2,45 +2,53 @@ namespace Convoy\Http\Controllers\Admin\AddressPools; +use Convoy\Enums\Network\AddressType; +use Convoy\Exceptions\Repository\Proxmox\ProxmoxConnectionException; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Admin\AddressPools\Addresses\StoreAddressRequest; +use Convoy\Http\Requests\Admin\AddressPools\Addresses\UpdateAddressRequest; +use Convoy\Jobs\Server\SyncNetworkSettings; use Convoy\Models\Address; -use Illuminate\Http\Request; use Convoy\Models\AddressPool; -use Convoy\Enums\Network\AddressType; -use Spatie\QueryBuilder\QueryBuilder; -use Spatie\QueryBuilder\AllowedFilter; +use Convoy\Models\Filters\AllowedNullableFilter; use Convoy\Models\Filters\FiltersAddress; +use Convoy\Repositories\Eloquent\AddressRepository; use Convoy\Services\Servers\NetworkService; -use Convoy\Jobs\Server\SyncNetworkSettings; -use Illuminate\Database\ConnectionInterface; -use Convoy\Models\Filters\AllowedNullableFilter; use Convoy\Transformers\Admin\AddressTransformer; -use Convoy\Repositories\Eloquent\AddressRepository; -use Convoy\Http\Controllers\ApplicationApiController; -use Convoy\Exceptions\Repository\Proxmox\ProxmoxConnectionException; -use Convoy\Http\Requests\Admin\AddressPools\Addresses\StoreAddressRequest; +use Illuminate\Database\ConnectionInterface; +use Illuminate\Http\Request; +use Spatie\QueryBuilder\AllowedFilter; +use Spatie\QueryBuilder\QueryBuilder; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; -use Convoy\Http\Requests\Admin\AddressPools\Addresses\UpdateAddressRequest; -class AddressController extends ApplicationApiController +class AddressController extends ApiController { - public function __construct(private NetworkService $networkService, private AddressRepository $repository, private ConnectionInterface $connection) + public function __construct( + private NetworkService $networkService, private AddressRepository $repository, + private ConnectionInterface $connection, + ) { } public function index(Request $request, AddressPool $addressPool) { $addresses = QueryBuilder::for($addressPool->addresses()) - ->with('server') - ->defaultSort('-id') - ->allowedFilters( - [AllowedFilter::exact('address'), AllowedFilter::exact('type'), AllowedFilter::custom( - '*', - new FiltersAddress, - ), AllowedNullableFilter::exact('server_id')], - ) - ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); - - return fractal($addresses, new AddressTransformer)->parseIncludes($request->include)->respond(); + ->with('server') + ->defaultSort('-id') + ->allowedFilters( + [AllowedFilter::exact('address'), AllowedFilter::exact( + 'type', + ), AllowedFilter::custom( + '*', + new FiltersAddress(), + ), AllowedNullableFilter::exact('server_id')], + ) + ->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); + + return fractal($addresses, new AddressTransformer())->parseIncludes($request->include) + ->respond(); } public function store(StoreAddressRequest $request, AddressPool $addressPool) @@ -63,7 +71,8 @@ public function store(StoreAddressRequest $request, AddressPool $addressPool) return $address; }); - return fractal($address, new AddressTransformer)->parseIncludes($request->include)->respond(); + return fractal($address, new AddressTransformer())->parseIncludes($request->include) + ->respond(); } if ($request->boolean('is_bulk_action')) { @@ -99,7 +108,8 @@ public function store(StoreAddressRequest $request, AddressPool $addressPool) } } - public function update(UpdateAddressRequest $request, AddressPool $addressPool, Address $address) + public function update(UpdateAddressRequest $request, AddressPool $addressPool, Address $address, + ) { $address = $this->connection->transaction(function () use ($request, $address) { $oldLinkedServer = $address->server; @@ -135,7 +145,8 @@ public function update(UpdateAddressRequest $request, AddressPool $addressPool, return $address; }); - return fractal($address, new AddressTransformer)->parseIncludes($request->include)->respond(); + return fractal($address, new AddressTransformer())->parseIncludes($request->include) + ->respond(); } public function destroy(AddressPool $addressPool, Address $address) diff --git a/app/Http/Controllers/Admin/AddressPools/AddressPoolController.php b/app/Http/Controllers/Admin/AddressPools/AddressPoolController.php index b5c85ae3572..87272ab3f18 100644 --- a/app/Http/Controllers/Admin/AddressPools/AddressPoolController.php +++ b/app/Http/Controllers/Admin/AddressPools/AddressPoolController.php @@ -2,45 +2,57 @@ namespace Convoy\Http\Controllers\Admin\AddressPools; -use Illuminate\Http\Request; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Admin\AddressPools\StoreAddressPoolRequest; +use Convoy\Http\Requests\Admin\AddressPools\UpdateAddressPoolRequest; use Convoy\Models\AddressPool; -use Spatie\QueryBuilder\QueryBuilder; -use Convoy\Models\Filters\FiltersNode; -use Spatie\QueryBuilder\AllowedFilter; use Convoy\Models\Filters\FiltersAddressPool; -use Convoy\Transformers\Admin\NodeTransformer; -use Convoy\Http\Controllers\ApplicationApiController; +use Convoy\Models\Filters\FiltersNode; use Convoy\Transformers\Admin\AddressPoolTransformer; -use Convoy\Http\Requests\Admin\AddressPools\StoreAddressPoolRequest; -use Convoy\Http\Requests\Admin\AddressPools\UpdateAddressPoolRequest; +use Convoy\Transformers\Admin\NodeTransformer; +use Illuminate\Http\Request; +use Spatie\QueryBuilder\AllowedFilter; +use Spatie\QueryBuilder\QueryBuilder; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; -class AddressPoolController extends ApplicationApiController +class AddressPoolController extends ApiController { public function index(Request $request) { $addressPools = QueryBuilder::for(AddressPool::query()) - ->withCount(['addresses', 'nodes']) - ->defaultSort('-id') - ->allowedFilters(['name', AllowedFilter::custom('*', new FiltersAddressPool)]) - ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); - - return fractal($addressPools, new AddressPoolTransformer)->respond(); + ->withCount(['addresses', 'nodes']) + ->defaultSort('-id') + ->allowedFilters( + ['name', AllowedFilter::custom( + '*', new FiltersAddressPool(), + )], + ) + ->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); + + return fractal($addressPools, new AddressPoolTransformer())->respond(); } public function show(AddressPool $addressPool) { $addressPool->loadCount(['addresses', 'nodes']); - return fractal($addressPool, new AddressPoolTransformer)->respond(); + return fractal($addressPool, new AddressPoolTransformer())->respond(); } public function getAttachedNodes(Request $request, AddressPool $addressPool) { $nodes = QueryBuilder::for($addressPool->nodes()) - ->withCount('servers') - ->allowedFilters(['name', 'fqdn', AllowedFilter::exact('location_id'), AllowedFilter::custom('*', new FiltersNode)]) - ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); + ->withCount('servers') + ->allowedFilters( + ['name', 'fqdn', AllowedFilter::exact( + 'location_id', + ), AllowedFilter::custom('*', new FiltersNode())], + ) + ->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); return fractal($nodes, new NodeTransformer())->respond(); } @@ -51,7 +63,7 @@ public function store(StoreAddressPoolRequest $request) $pool->nodes()->attach($request->node_ids); $pool->loadCount(['addresses', 'nodes']); - return fractal($pool, new AddressPoolTransformer)->respond(); + return fractal($pool, new AddressPoolTransformer())->respond(); } public function update(UpdateAddressPoolRequest $request, AddressPool $addressPool) @@ -60,7 +72,7 @@ public function update(UpdateAddressPoolRequest $request, AddressPool $addressPo $addressPool->nodes()->sync($request->node_ids); $addressPool->loadCount(['addresses', 'nodes']); - return fractal($addressPool, new AddressPoolTransformer)->respond(); + return fractal($addressPool, new AddressPoolTransformer())->respond(); } public function destroy(AddressPool $addressPool) @@ -68,7 +80,9 @@ public function destroy(AddressPool $addressPool) $addressPool->loadCount('nodes'); if ($addressPool->nodes_count > 0) { - throw new AccessDeniedHttpException('This address pool cannot be deleted while still allocated to nodes.'); + throw new AccessDeniedHttpException( + 'This address pool cannot be deleted while still allocated to nodes.', + ); } $addressPool->delete(); diff --git a/app/Http/Controllers/Admin/CotermController.php b/app/Http/Controllers/Admin/CotermController.php index fd2fb657dba..306894d4a3a 100644 --- a/app/Http/Controllers/Admin/CotermController.php +++ b/app/Http/Controllers/Admin/CotermController.php @@ -2,7 +2,7 @@ namespace Convoy\Http\Controllers\Admin; -use Convoy\Http\Controllers\ApplicationApiController; +use Convoy\Http\Controllers\ApiController; use Convoy\Http\Requests\Admin\Coterms\StoreCotermRequest; use Convoy\Http\Requests\Admin\Coterms\UpdateAttachedNodesRequest; use Convoy\Http\Requests\Admin\Coterms\UpdateCotermRequest; @@ -16,7 +16,7 @@ use Spatie\QueryBuilder\AllowedFilter; use Spatie\QueryBuilder\QueryBuilder; -class CotermController extends ApplicationApiController +class CotermController extends ApiController { public function __construct(private CotermTokenCreationService $cotermTokenCreator) { diff --git a/app/Http/Controllers/Admin/LocationController.php b/app/Http/Controllers/Admin/LocationController.php index fe2d13b0097..e6755c69eed 100644 --- a/app/Http/Controllers/Admin/LocationController.php +++ b/app/Http/Controllers/Admin/LocationController.php @@ -2,25 +2,29 @@ namespace Convoy\Http\Controllers\Admin; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Admin\LocationFormRequest; +use Convoy\Models\Filters\FiltersLocation; use Convoy\Models\Location; +use Convoy\Transformers\Admin\LocationTransformer; use Illuminate\Http\Request; -use Spatie\QueryBuilder\QueryBuilder; use Spatie\QueryBuilder\AllowedFilter; -use Convoy\Models\Filters\FiltersLocation; -use Convoy\Transformers\Admin\LocationTransformer; -use Convoy\Http\Requests\Admin\LocationFormRequest; -use Convoy\Http\Controllers\ApplicationApiController; +use Spatie\QueryBuilder\QueryBuilder; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -class LocationController extends ApplicationApiController +class LocationController extends ApiController { public function index(Request $request) { $locations = QueryBuilder::for(Location::query()) - ->withCount(['nodes', 'servers']) + ->withCount(['nodes', 'servers']) // @phpstan-ignore-next-line - ->allowedFilters(['short_code', AllowedFilter::custom('*', new FiltersLocation)]) - ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); + ->allowedFilters( + ['short_code', AllowedFilter::custom('*', new FiltersLocation())], + ) + ->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); return fractal($locations, new LocationTransformer())->respond(); } @@ -45,7 +49,9 @@ public function destroy(Location $location) // @phpstan-ignore-next-line if ($location->nodes_count > 0) { - throw new BadRequestHttpException('The location cannot be deleted with nodes still associated.'); + throw new BadRequestHttpException( + 'The location cannot be deleted with nodes still associated.', + ); } $location->delete(); diff --git a/app/Http/Controllers/Admin/Nodes/IsoController.php b/app/Http/Controllers/Admin/Nodes/IsoController.php index d969bf31da5..c4336d47994 100644 --- a/app/Http/Controllers/Admin/Nodes/IsoController.php +++ b/app/Http/Controllers/Admin/Nodes/IsoController.php @@ -2,48 +2,55 @@ namespace Convoy\Http\Controllers\Admin\Nodes; -use Convoy\Models\ISO; -use Convoy\Models\Node; -use Illuminate\Http\Request; use Convoy\Data\Helpers\ChecksumData; -use Spatie\QueryBuilder\QueryBuilder; -use Illuminate\Support\Facades\Validator; -use Convoy\Services\Nodes\Isos\IsoService; use Convoy\Enums\Helpers\ChecksumAlgorithm; -use Convoy\Transformers\Admin\IsoTransformer; -use Convoy\Http\Controllers\ApplicationApiController; -use Convoy\Transformers\Admin\FileMetadataTransformer; +use Convoy\Http\Controllers\ApiController; use Convoy\Http\Requests\Admin\Nodes\Isos\StoreIsoRequest; use Convoy\Http\Requests\Admin\Nodes\Isos\UpdateIsoRequest; +use Convoy\Models\ISO; +use Convoy\Models\Node; use Convoy\Repositories\Proxmox\Node\ProxmoxStorageRepository; +use Convoy\Services\Nodes\Isos\IsoService; +use Convoy\Transformers\Admin\FileMetadataTransformer; +use Convoy\Transformers\Admin\IsoTransformer; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Validator; +use Spatie\QueryBuilder\QueryBuilder; -class IsoController extends ApplicationApiController +class IsoController extends ApiController { - public function __construct(private IsoService $isoService, private ProxmoxStorageRepository $repository) + public function __construct( + private IsoService $isoService, private ProxmoxStorageRepository $repository, + ) { } public function index(Node $node, Request $request) { $isos = QueryBuilder::for(ISO::query()) - ->where('iso_library.node_id', $node->id) - ->allowedFilters(['name']) - ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); + ->where('iso_library.node_id', $node->id) + ->allowedFilters(['name']) + ->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); - return fractal($isos, new IsoTransformer)->respond(); + return fractal($isos, new IsoTransformer())->respond(); } public function store(StoreIsoRequest $request, Node $node) { $shouldDownload = $request->boolean('should_download'); - if($shouldDownload) { - $checksumData = (bool) $request->checksum_algorithum ? ChecksumData::from([ + if ($shouldDownload) { + $checksumData = (bool)$request->checksum_algorithum ? ChecksumData::from([ 'algorithm' => ChecksumAlgorithm::from($request->checksum_algorithum), 'checksum' => $request->checksum, ]) : null; - $iso = $this->isoService->download($node, $request->name, $request->file_name, $request->link, $checksumData, $request->hidden); + $iso = $this->isoService->download( + $node, $request->name, $request->file_name, $request->link, $checksumData, + $request->hidden, + ); } else { $isoFromProxmox = $this->isoService->getIso($node, $request->file_name); @@ -57,14 +64,14 @@ public function store(StoreIsoRequest $request, Node $node) ]); } - return fractal($iso, new IsoTransformer)->respond(); + return fractal($iso, new IsoTransformer())->respond(); } public function update(UpdateIsoRequest $request, Node $node, ISO $iso) { $iso->update($request->validated()); - return fractal($iso, new IsoTransformer)->respond(); + return fractal($iso, new IsoTransformer())->respond(); } public function destroy(Node $node, ISO $iso) @@ -84,6 +91,6 @@ public function queryLink(Request $request, Node $node) $metadata = $this->repository->setNode($node)->getFileMetadata($request->link); - return fractal($metadata, new FileMetadataTransformer)->respond(); + return fractal($metadata, new FileMetadataTransformer())->respond(); } } diff --git a/app/Http/Controllers/Admin/Nodes/NodeController.php b/app/Http/Controllers/Admin/Nodes/NodeController.php index 121303b5329..55bc2a4f1f1 100644 --- a/app/Http/Controllers/Admin/Nodes/NodeController.php +++ b/app/Http/Controllers/Admin/Nodes/NodeController.php @@ -2,21 +2,21 @@ namespace Convoy\Http\Controllers\Admin\Nodes; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Admin\Nodes\Settings\UpdateCotermRequest; +use Convoy\Http\Requests\Admin\Nodes\StoreNodeRequest; +use Convoy\Http\Requests\Admin\Nodes\UpdateNodeRequest; +use Convoy\Models\Filters\FiltersNode; use Convoy\Models\Node; -use Illuminate\Http\Request; +use Convoy\Services\Coterm\CotermTokenCreationService; +use Convoy\Transformers\Admin\NodeTransformer; use Illuminate\Http\JsonResponse; -use Spatie\QueryBuilder\QueryBuilder; -use Convoy\Models\Filters\FiltersNode; +use Illuminate\Http\Request; use Spatie\QueryBuilder\AllowedFilter; -use Convoy\Transformers\Admin\NodeTransformer; -use Convoy\Http\Controllers\ApplicationApiController; -use Convoy\Http\Requests\Admin\Nodes\StoreNodeRequest; -use Convoy\Services\Coterm\CotermTokenCreationService; -use Convoy\Http\Requests\Admin\Nodes\UpdateNodeRequest; -use Convoy\Http\Requests\Admin\Nodes\Settings\UpdateCotermRequest; +use Spatie\QueryBuilder\QueryBuilder; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; -class NodeController extends ApplicationApiController +class NodeController extends ApiController { public function __construct(private CotermTokenCreationService $cotermTokenCreator) { @@ -25,14 +25,18 @@ public function __construct(private CotermTokenCreationService $cotermTokenCreat public function index(Request $request) { $nodes = QueryBuilder::for(Node::query()) - ->withCount(['servers']) - ->allowedFilters( - [AllowedFilter::exact('id'), 'name', 'fqdn', AllowedFilter::exact('location_id'), AllowedFilter::custom( - '*', - new FiltersNode, - )], - ) - ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); + ->withCount(['servers']) + ->allowedFilters( + [AllowedFilter::exact('id'), 'name', 'fqdn', AllowedFilter::exact( + 'location_id', + ), AllowedFilter::custom( + '*', + new FiltersNode(), + )], + ) + ->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); return fractal($nodes, new NodeTransformer())->respond(); } @@ -50,14 +54,14 @@ public function store(StoreNodeRequest $request) { $node = Node::create($request->validated()); - return fractal($node, new NodeTransformer)->respond(); + return fractal($node, new NodeTransformer())->respond(); } public function update(UpdateNodeRequest $request, Node $node) { $node->update($request->validated()); - return fractal($node, new NodeTransformer)->respond(); + return fractal($node, new NodeTransformer())->respond(); } public function updateCoterm(UpdateCotermRequest $request, Node $node) @@ -109,7 +113,9 @@ public function destroy(Node $node) $node->loadCount('servers'); if ($node->servers_count > 0) { - throw new AccessDeniedHttpException('This node cannot be deleted with servers still associated.'); + throw new AccessDeniedHttpException( + 'This node cannot be deleted with servers still associated.', + ); } $node->delete(); diff --git a/app/Http/Controllers/Admin/Nodes/TemplateController.php b/app/Http/Controllers/Admin/Nodes/TemplateController.php index 38ea2477ab5..595fe6c586d 100644 --- a/app/Http/Controllers/Admin/Nodes/TemplateController.php +++ b/app/Http/Controllers/Admin/Nodes/TemplateController.php @@ -2,42 +2,46 @@ namespace Convoy\Http\Controllers\Admin\Nodes; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Admin\Nodes\Templates\TemplateRequest; +use Convoy\Http\Requests\Admin\Nodes\Templates\UpdateTemplateOrderRequest; use Convoy\Models\Node; use Convoy\Models\Template; use Convoy\Models\TemplateGroup; -use Spatie\QueryBuilder\QueryBuilder; use Convoy\Transformers\Admin\TemplateTransformer; -use Convoy\Http\Controllers\ApplicationApiController; -use Convoy\Http\Requests\Admin\Nodes\Templates\TemplateRequest; -use Convoy\Http\Requests\Admin\Nodes\Templates\UpdateTemplateOrderRequest; +use Spatie\QueryBuilder\QueryBuilder; -class TemplateController extends ApplicationApiController +class TemplateController extends ApiController { public function index(Node $node, TemplateGroup $templateGroup) { $templates = QueryBuilder::for(Template::query()) - ->where('templates.template_group_id', $templateGroup->id) - ->defaultSort('order_column') - ->get(); + ->where('templates.template_group_id', $templateGroup->id) + ->defaultSort('order_column') + ->get(); - return fractal($templates, new TemplateTransformer)->respond(); + return fractal($templates, new TemplateTransformer())->respond(); } public function store(TemplateRequest $request, Node $node, TemplateGroup $templateGroup) { - $template = Template::create(array_merge($request->validated(), [ - 'node_id' => $node->id, - 'template_group_id' => $templateGroup->id, - ])); + $template = Template::create( + array_merge($request->validated(), [ + 'node_id' => $node->id, + 'template_group_id' => $templateGroup->id, + ]), + ); - return fractal($template, new TemplateTransformer)->respond(); + return fractal($template, new TemplateTransformer())->respond(); } - public function update(TemplateRequest $request, Node $node, TemplateGroup $templateGroup, Template $template) + public function update( + TemplateRequest $request, Node $node, TemplateGroup $templateGroup, Template $template, + ) { $template->update($request->validated()); - return fractal($template, new TemplateTransformer)->respond(); + return fractal($template, new TemplateTransformer())->respond(); } public function destroy(Node $node, TemplateGroup $templateGroup, Template $template) @@ -47,10 +51,14 @@ public function destroy(Node $node, TemplateGroup $templateGroup, Template $temp return $this->returnNoContent(); } - public function updateOrder(UpdateTemplateOrderRequest $request, Node $node, TemplateGroup $templateGroup) + public function updateOrder( + UpdateTemplateOrderRequest $request, Node $node, TemplateGroup $templateGroup, + ) { Template::setNewOrder($request->order); - return fractal($templateGroup->templates()->ordered()->get(), new TemplateTransformer)->respond(); + return fractal( + $templateGroup->templates()->ordered()->get(), new TemplateTransformer(), + )->respond(); } } diff --git a/app/Http/Controllers/Admin/Nodes/TemplateGroupController.php b/app/Http/Controllers/Admin/Nodes/TemplateGroupController.php index 46bd9573be6..25a78c00147 100644 --- a/app/Http/Controllers/Admin/Nodes/TemplateGroupController.php +++ b/app/Http/Controllers/Admin/Nodes/TemplateGroupController.php @@ -2,51 +2,57 @@ namespace Convoy\Http\Controllers\Admin\Nodes; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Admin\Nodes\TemplateGroups\TemplateGroupRequest; +use Convoy\Http\Requests\Admin\Nodes\TemplateGroups\UpdateGroupOrderRequest; use Convoy\Models\Node; use Convoy\Models\TemplateGroup; -use Spatie\QueryBuilder\QueryBuilder; -use Convoy\Http\Controllers\ApplicationApiController; use Convoy\Transformers\Admin\TemplateGroupTransformer; -use Convoy\Http\Requests\Admin\Nodes\TemplateGroups\TemplateGroupRequest; -use Convoy\Http\Requests\Admin\Nodes\TemplateGroups\UpdateGroupOrderRequest; +use Spatie\QueryBuilder\QueryBuilder; -class TemplateGroupController extends ApplicationApiController +class TemplateGroupController extends ApiController { public function index(Node $node) { $templateGroups = QueryBuilder::for(TemplateGroup::query()) - ->where('template_groups.node_id', $node->id) - ->defaultSort('order_column') - ->with(['templates' => function ($query) { - $query->orderBy('order_column'); - }]) - ->allowedFilters(['name']) - ->get(); - - return fractal($templateGroups, new TemplateGroupTransformer)->parseIncludes(['templates'])->respond(); + ->where('template_groups.node_id', $node->id) + ->defaultSort('order_column') + ->with(['templates' => function ($query) { + $query->orderBy('order_column'); + }]) + ->allowedFilters(['name']) + ->get(); + + return fractal($templateGroups, new TemplateGroupTransformer())->parseIncludes(['templates'], + )->respond(); } public function updateOrder(UpdateGroupOrderRequest $request, Node $node) { TemplateGroup::setNewOrder($request->order); - return fractal($node->templateGroups()->with('templates')->ordered()->get(), new TemplateGroupTransformer)->parseIncludes(['templates'])->respond(); + return fractal( + $node->templateGroups()->with('templates')->ordered()->get(), + new TemplateGroupTransformer(), + )->parseIncludes(['templates'])->respond(); } public function store(TemplateGroupRequest $request, Node $node) { - $templateGroup = TemplateGroup::create(array_merge($request->validated(), [ - 'node_id' => $node->id, - ])); + $templateGroup = TemplateGroup::create( + array_merge($request->validated(), [ + 'node_id' => $node->id, + ]), + ); - return fractal($templateGroup, new TemplateGroupTransformer)->respond(); + return fractal($templateGroup, new TemplateGroupTransformer())->respond(); } public function update(TemplateGroupRequest $request, Node $node, TemplateGroup $templateGroup) { $templateGroup->update($request->validated()); - return fractal($templateGroup, new TemplateGroupTransformer)->respond(); + return fractal($templateGroup, new TemplateGroupTransformer())->respond(); } public function destroy(Node $node, TemplateGroup $templateGroup) diff --git a/app/Http/Controllers/Admin/ServerController.php b/app/Http/Controllers/Admin/ServerController.php index 37992d66ea5..807f5f07782 100644 --- a/app/Http/Controllers/Admin/ServerController.php +++ b/app/Http/Controllers/Admin/ServerController.php @@ -2,49 +2,64 @@ namespace Convoy\Http\Controllers\Admin; -use Convoy\Models\Server; -use Illuminate\Http\Request; use Convoy\Enums\Server\Status; -use Spatie\QueryBuilder\QueryBuilder; -use Spatie\QueryBuilder\AllowedFilter; -use Convoy\Models\Filters\FiltersServer; use Convoy\Enums\Server\SuspensionAction; -use Convoy\Services\Servers\NetworkService; -use Illuminate\Database\ConnectionInterface; +use Convoy\Exceptions\Repository\Proxmox\ProxmoxConnectionException; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Admin\Servers\Settings\UpdateBuildRequest; +use Convoy\Http\Requests\Admin\Servers\Settings\UpdateGeneralInfoRequest; +use Convoy\Http\Requests\Admin\Servers\StoreServerRequest; +use Convoy\Models\Filters\FiltersServer; +use Convoy\Models\Server; use Convoy\Services\Servers\CloudinitService; -use Convoy\Services\Servers\SyncBuildService; +use Convoy\Services\Servers\NetworkService; use Convoy\Services\Servers\ServerCreationService; use Convoy\Services\Servers\ServerDeletionService; use Convoy\Services\Servers\ServerSuspensionService; -use Convoy\Http\Controllers\ApplicationApiController; +use Convoy\Services\Servers\SyncBuildService; use Convoy\Transformers\Admin\ServerBuildTransformer; -use Convoy\Http\Requests\Admin\Servers\StoreServerRequest; -use Convoy\Http\Requests\Admin\Servers\Settings\UpdateBuildRequest; -use Convoy\Exceptions\Repository\Proxmox\ProxmoxConnectionException; -use Convoy\Http\Requests\Admin\Servers\Settings\UpdateGeneralInfoRequest; +use Illuminate\Database\ConnectionInterface; +use Illuminate\Http\Request; +use Spatie\QueryBuilder\AllowedFilter; +use Spatie\QueryBuilder\QueryBuilder; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; -class ServerController extends ApplicationApiController +class ServerController extends ApiController { - public function __construct(private ConnectionInterface $connection, private ServerDeletionService $deletionService, private NetworkService $networkService, private ServerSuspensionService $suspensionService, private ServerCreationService $creationService, private CloudinitService $cloudinitService, private SyncBuildService $buildModificationService) + public function __construct( + private ConnectionInterface $connection, private ServerDeletionService $deletionService, + private NetworkService $networkService, private ServerSuspensionService $suspensionService, + private ServerCreationService $creationService, private CloudinitService $cloudinitService, + private SyncBuildService $buildModificationService, + ) { } public function index(Request $request) { $servers = QueryBuilder::for(Server::query()) - ->with(['addresses', 'user', 'node']) - ->allowedFilters([AllowedFilter::custom('*', new FiltersServer), AllowedFilter::exact('node_id'), AllowedFilter::exact('user_id'), 'name']) - ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); - - return fractal($servers, new ServerBuildTransformer())->parseIncludes($request->include)->respond(); + ->with(['addresses', 'user', 'node']) + ->allowedFilters( + [AllowedFilter::custom( + '*', new FiltersServer(), + ), AllowedFilter::exact('node_id'), AllowedFilter::exact( + 'user_id', + ), 'name'], + ) + ->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); + + return fractal($servers, new ServerBuildTransformer())->parseIncludes($request->include) + ->respond(); } public function show(Request $request, Server $server) { $server->load(['addresses', 'user', 'node']); - return fractal($server, new ServerBuildTransformer())->parseIncludes($request->include)->respond(); + return fractal($server, new ServerBuildTransformer())->parseIncludes($request->include) + ->respond(); } public function store(StoreServerRequest $request) @@ -53,7 +68,8 @@ public function store(StoreServerRequest $request) $server->load(['addresses', 'user', 'node']); - return fractal($server, new ServerBuildTransformer())->parseIncludes(['user', 'node'])->respond(); + return fractal($server, new ServerBuildTransformer())->parseIncludes(['user', 'node']) + ->respond(); } public function update(UpdateGeneralInfoRequest $request, Server $server) @@ -64,7 +80,7 @@ public function update(UpdateGeneralInfoRequest $request, Server $server) $this->cloudinitService->updateHostname($server, $request->hostname); } catch (ProxmoxConnectionException) { throw new ServiceUnavailableHttpException( - message: "Server {$server->uuid} failed to sync hostname." + message: "Server {$server->uuid} failed to sync hostname.", ); } } @@ -74,7 +90,8 @@ public function update(UpdateGeneralInfoRequest $request, Server $server) $server->load(['addresses', 'user', 'node']); - return fractal($server, new ServerBuildTransformer)->parseIncludes(['user', 'node'])->respond(); + return fractal($server, new ServerBuildTransformer())->parseIncludes(['user', 'node']) + ->respond(); } public function updateBuild(UpdateBuildRequest $request, Server $server) @@ -91,7 +108,8 @@ public function updateBuild(UpdateBuildRequest $request, Server $server) $server->load(['addresses', 'user', 'node']); - return fractal($server, new ServerBuildTransformer)->parseIncludes(['user', 'node'])->respond(); + return fractal($server, new ServerBuildTransformer())->parseIncludes(['user', 'node']) + ->respond(); } public function suspend(Server $server) diff --git a/app/Http/Controllers/Admin/TokenController.php b/app/Http/Controllers/Admin/TokenController.php index 66876ddcac9..32bcd8a860d 100644 --- a/app/Http/Controllers/Admin/TokenController.php +++ b/app/Http/Controllers/Admin/TokenController.php @@ -2,23 +2,25 @@ namespace Convoy\Http\Controllers\Admin; -use Illuminate\Http\Request; use Convoy\Enums\Api\ApiKeyType; -use Spatie\QueryBuilder\QueryBuilder; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Admin\Tokens\StoreTokenRequest; use Convoy\Models\PersonalAccessToken; use Convoy\Transformers\Admin\ApiKeyTransformer; use Convoy\Transformers\Admin\NewApiKeyTransformer; -use Convoy\Http\Controllers\ApplicationApiController; -use Convoy\Http\Requests\Admin\Tokens\StoreTokenRequest; +use Illuminate\Http\Request; +use Spatie\QueryBuilder\QueryBuilder; -class TokenController extends ApplicationApiController +class TokenController extends ApiController { public function index(Request $request) { $tokens = QueryBuilder::for(PersonalAccessToken::query()) - ->with('tokenable') - ->where('personal_access_tokens.type', ApiKeyType::APPLICATION->value) - ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); + ->with('tokenable') + ->where('personal_access_tokens.type', ApiKeyType::APPLICATION->value) + ->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); return fractal($tokens, new ApiKeyTransformer())->respond(); } diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 2b91d0b1cb2..d83a0993731 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -2,32 +2,40 @@ namespace Convoy\Http\Controllers\Admin; -use Convoy\Models\User; use Carbon\CarbonImmutable; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Admin\Users\StoreUserRequest; +use Convoy\Http\Requests\Admin\Users\UpdateUserRequest; +use Convoy\Models\Filters\FiltersUser; use Convoy\Models\SSOToken; -use Illuminate\Http\Request; +use Convoy\Models\User; use Convoy\Services\Api\JWTService; +use Convoy\Transformers\Admin\UserTransformer; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; -use Spatie\QueryBuilder\QueryBuilder; -use Convoy\Models\Filters\FiltersUser; use Spatie\QueryBuilder\AllowedFilter; -use Convoy\Transformers\Admin\UserTransformer; +use Spatie\QueryBuilder\QueryBuilder; use Symfony\Component\HttpFoundation\JsonResponse; -use Convoy\Http\Controllers\ApplicationApiController; -use Convoy\Http\Requests\Admin\Users\StoreUserRequest; -use Convoy\Http\Requests\Admin\Users\UpdateUserRequest; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -class UserController extends ApplicationApiController +class UserController extends ApiController { - public function __construct(private JWTService $JWTService) {} + public function __construct(private JWTService $JWTService) + { + } public function index(Request $request) { $users = QueryBuilder::for(User::query()) - ->withCount(['servers']) - ->allowedFilters([AllowedFilter::exact('id'), 'name', AllowedFilter::exact('email'), AllowedFilter::custom('*', new FiltersUser)]) - ->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); + ->withCount(['servers']) + ->allowedFilters( + [AllowedFilter::exact('id'), 'name', AllowedFilter::exact( + 'email', + ), AllowedFilter::custom('*', new FiltersUser())], + ) + ->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); return fractal($users, new UserTransformer())->respond(); } @@ -70,7 +78,9 @@ public function destroy(User $user) $user->loadCount('servers'); if ($user->servers_count > 0) { - throw new BadRequestHttpException('The user cannot be deleted with servers still associated.'); + throw new BadRequestHttpException( + 'The user cannot be deleted with servers still associated.', + ); } $user->tokens()->delete(); @@ -91,7 +101,7 @@ public function getSSOToken(User $user) 'data' => [ 'user_id' => $user->id, 'token' => $token->toString(), - ] + ], ]); } } diff --git a/app/Http/Controllers/ApplicationApiController.php b/app/Http/Controllers/ApiController.php similarity index 81% rename from app/Http/Controllers/ApplicationApiController.php rename to app/Http/Controllers/ApiController.php index a8ee24a60bc..d322d0b00d0 100644 --- a/app/Http/Controllers/ApplicationApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -4,7 +4,7 @@ use Illuminate\Http\JsonResponse; -class ApplicationApiController extends Controller +class ApiController extends Controller { protected function returnNoContent(): JsonResponse { diff --git a/app/Http/Controllers/Client/IndexController.php b/app/Http/Controllers/Client/IndexController.php index b3af4d81807..d5df0be13f4 100644 --- a/app/Http/Controllers/Client/IndexController.php +++ b/app/Http/Controllers/Client/IndexController.php @@ -2,14 +2,14 @@ namespace Convoy\Http\Controllers\Client; +use Convoy\Http\Controllers\ApiController; use Convoy\Models\Server; -use Illuminate\Http\Request; -use Spatie\QueryBuilder\QueryBuilder; use Convoy\Services\Servers\ServerDetailService; use Convoy\Transformers\Client\ServerTransformer; -use Convoy\Http\Controllers\ApplicationApiController; +use Illuminate\Http\Request; +use Spatie\QueryBuilder\QueryBuilder; -class IndexController extends ApplicationApiController +class IndexController extends ApiController { public function __construct(private ServerDetailService $service) { @@ -20,21 +20,23 @@ public function index(Request $request) $user = $request->user(); $builder = QueryBuilder::for(Server::query()) - ->with(['addresses']) - ->allowedFilters(['name']); + ->with(['addresses']) + ->allowedFilters(['name']); $type = $request->input('type'); if ($type === 'all') { - if (! $user->root_admin) { + if (!$user->root_admin) { $builder = $builder->whereRaw('1 = 2'); } } else { $builder = $builder->where('servers.user_id', $user->id); } - $servers = $builder->paginate(min($request->query('per_page', 50), 100))->appends($request->query()); + $servers = $builder->paginate(min($request->query('per_page', 50), 100))->appends( + $request->query(), + ); - return fractal($servers, new ServerTransformer)->respond(); + return fractal($servers, new ServerTransformer())->respond(); } } diff --git a/app/Http/Controllers/Client/Servers/BackupController.php b/app/Http/Controllers/Client/Servers/BackupController.php index 43fda8f076e..13ea956e01b 100644 --- a/app/Http/Controllers/Client/Servers/BackupController.php +++ b/app/Http/Controllers/Client/Servers/BackupController.php @@ -2,23 +2,23 @@ namespace Convoy\Http\Controllers\Client\Servers; +use Convoy\Enums\Server\BackupCompressionType; +use Convoy\Enums\Server\BackupMode; +use Convoy\Http\Controllers\ApiController; use Convoy\Http\Requests\Client\Servers\Backups\DeleteBackupRequest; use Convoy\Http\Requests\Client\Servers\Backups\RestoreBackupRequest; +use Convoy\Http\Requests\Client\Servers\Backups\StoreBackupRequest; use Convoy\Models\Backup; use Convoy\Models\Server; -use Illuminate\Http\Request; -use Convoy\Enums\Server\BackupMode; -use Spatie\QueryBuilder\QueryBuilder; -use Convoy\Enums\Server\BackupCompressionType; -use Convoy\Transformers\Client\BackupTransformer; use Convoy\Repositories\Eloquent\BackupRepository; -use Convoy\Http\Controllers\ApplicationApiController; use Convoy\Services\Servers\Backups\BackupCreationService; use Convoy\Services\Servers\Backups\BackupDeletionService; use Convoy\Services\Servers\Backups\RestoreFromBackupService; -use Convoy\Http\Requests\Client\Servers\Backups\StoreBackupRequest; +use Convoy\Transformers\Client\BackupTransformer; +use Illuminate\Http\Request; +use Spatie\QueryBuilder\QueryBuilder; -class BackupController extends ApplicationApiController +class BackupController extends ApiController { public function __construct( private BackupCreationService $backupCreationService, diff --git a/app/Http/Controllers/Client/Servers/ServerController.php b/app/Http/Controllers/Client/Servers/ServerController.php index 3c30f4b7437..1e5641c91f7 100644 --- a/app/Http/Controllers/Client/Servers/ServerController.php +++ b/app/Http/Controllers/Client/Servers/ServerController.php @@ -2,25 +2,25 @@ namespace Convoy\Http\Controllers\Client\Servers; -use Convoy\Models\Server; -use Illuminate\Http\JsonResponse; use Convoy\Enums\Server\ConsoleType; use Convoy\Enums\Server\PowerAction; -use Convoy\Services\Servers\VncService; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Client\Servers\CreateConsoleSessionRequest; +use Convoy\Http\Requests\Client\Servers\SendPowerCommandRequest; +use Convoy\Models\Server; +use Convoy\Repositories\Proxmox\Server\ProxmoxPowerRepository; +use Convoy\Repositories\Proxmox\Server\ProxmoxServerRepository; use Convoy\Services\Coterm\CotermJWTService; -use Convoy\Services\Servers\ServerDetailService; use Convoy\Services\Servers\ServerConsoleService; -use Convoy\Transformers\Client\ServerTransformer; -use Convoy\Http\Controllers\ApplicationApiController; -use Convoy\Transformers\Client\ServerStateTransformer; +use Convoy\Services\Servers\ServerDetailService; +use Convoy\Services\Servers\VncService; use Convoy\Transformers\Client\ServerDetailTransformer; +use Convoy\Transformers\Client\ServerStateTransformer; use Convoy\Transformers\Client\ServerTerminalTransformer; -use Convoy\Repositories\Proxmox\Server\ProxmoxPowerRepository; -use Convoy\Repositories\Proxmox\Server\ProxmoxServerRepository; -use Convoy\Http\Requests\Client\Servers\SendPowerCommandRequest; -use Convoy\Http\Requests\Client\Servers\CreateConsoleSessionRequest; +use Convoy\Transformers\Client\ServerTransformer; +use Illuminate\Http\JsonResponse; -class ServerController extends ApplicationApiController +class ServerController extends ApiController { public function __construct( private CotermJWTService $cotermJWTService, diff --git a/app/Http/Controllers/Client/Servers/SettingsController.php b/app/Http/Controllers/Client/Servers/SettingsController.php index 0116cd0d460..2248c65a97f 100644 --- a/app/Http/Controllers/Client/Servers/SettingsController.php +++ b/app/Http/Controllers/Client/Servers/SettingsController.php @@ -2,38 +2,43 @@ namespace Convoy\Http\Controllers\Client\Servers; +use Convoy\Data\Server\Deployments\ServerDeploymentData; +use Convoy\Data\Server\Proxmox\Config\DiskData; +use Convoy\Enums\Server\AuthenticationType; +use Convoy\Enums\Server\Status; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Client\Servers\Settings\MountMediaRequest; +use Convoy\Http\Requests\Client\Servers\Settings\ReinstallServerRequest; +use Convoy\Http\Requests\Client\Servers\Settings\RenameServerRequest; +use Convoy\Http\Requests\Client\Servers\Settings\UpdateAuthSettingsRequest; +use Convoy\Http\Requests\Client\Servers\Settings\UpdateBootOrderRequest; +use Convoy\Http\Requests\Client\Servers\Settings\UpdateNetworkRequest; use Convoy\Models\ISO; use Convoy\Models\Server; use Convoy\Models\Template; -use Illuminate\Http\Request; -use Convoy\Enums\Server\Status; use Convoy\Models\TemplateGroup; -use Spatie\QueryBuilder\QueryBuilder; -use Convoy\Enums\Server\AuthenticationType; -use Illuminate\Database\ConnectionInterface; -use Convoy\Services\Servers\CloudinitService; use Convoy\Services\Servers\AllocationService; +use Convoy\Services\Servers\CloudinitService; use Convoy\Services\Servers\ServerAuthService; -use Convoy\Data\Server\Proxmox\Config\DiskData; -use Convoy\Transformers\Client\MediaTransformer; -use Convoy\Http\Controllers\ApplicationApiController; use Convoy\Services\Servers\ServerBuildDispatchService; -use Convoy\Data\Server\Deployments\ServerDeploymentData; +use Convoy\Transformers\Client\MediaTransformer; use Convoy\Transformers\Client\RenamedServerTransformer; +use Convoy\Transformers\Client\ServerBootOrderTransformer; use Convoy\Transformers\Client\ServerNetworkTransformer; -use Convoy\Transformers\Client\TemplateGroupTransformer; use Convoy\Transformers\Client\ServerSecurityTransformer; -use Convoy\Transformers\Client\ServerBootOrderTransformer; -use Convoy\Http\Requests\Client\Servers\Settings\MountMediaRequest; -use Convoy\Http\Requests\Client\Servers\Settings\RenameServerRequest; -use Convoy\Http\Requests\Client\Servers\Settings\UpdateNetworkRequest; -use Convoy\Http\Requests\Client\Servers\Settings\UpdateAuthSettingsRequest; -use Convoy\Http\Requests\Client\Servers\Settings\ReinstallServerRequest; -use Convoy\Http\Requests\Client\Servers\Settings\UpdateBootOrderRequest; +use Convoy\Transformers\Client\TemplateGroupTransformer; +use Illuminate\Database\ConnectionInterface; +use Illuminate\Http\Request; +use Spatie\QueryBuilder\QueryBuilder; -class SettingsController extends ApplicationApiController +class SettingsController extends ApiController { - public function __construct(private ServerAuthService $authService, private ConnectionInterface $connection, private CloudinitService $cloudinitService, private ServerBuildDispatchService $buildDispatchService, private AllocationService $allocationService) + public function __construct( + private ServerAuthService $authService, private ConnectionInterface $connection, + private CloudinitService $cloudinitService, + private ServerBuildDispatchService $buildDispatchService, + private AllocationService $allocationService, + ) { } @@ -45,28 +50,34 @@ public function rename(RenameServerRequest $request, Server $server) $server->update($request->validated()); }); - return fractal($server, new RenamedServerTransformer)->respond(); + return fractal($server, new RenamedServerTransformer())->respond(); } public function getTemplateGroups(Request $request, Server $server) { $templateGroups = QueryBuilder::for(TemplateGroup::query()) - ->defaultSort('order_column') - ->allowedFilters(['name']); - - if (! $request->user()->root_admin) { - $templateGroups = $templateGroups->where([['template_groups.hidden', '=', false], ['template_groups.node_id', '=', $server->node->id]]) - ->with(['templates' => function ($query) { - $query->where('hidden', '=', false)->orderBy('order_column'); - }])->get(); + ->defaultSort('order_column') + ->allowedFilters(['name']); + + if (!$request->user()->root_admin) { + $templateGroups = $templateGroups->where( + [['template_groups.hidden', '=', false], ['template_groups.node_id', '=', $server->node->id]], + ) + ->with(['templates' => function ($query) { + $query->where('hidden', '=', false)->orderBy( + 'order_column', + ); + }])->get(); } else { - $templateGroups = $templateGroups->where('template_groups.node_id', '=', $server->node->id) - ->with(['templates' => function ($query) { - $query->orderBy('order_column'); - }])->get(); + $templateGroups = $templateGroups->where( + 'template_groups.node_id', '=', $server->node->id, + ) + ->with(['templates' => function ($query) { + $query->orderBy('order_column'); + }])->get(); } - return fractal($templateGroups, new TemplateGroupTransformer)->respond(); + return fractal($templateGroups, new TemplateGroupTransformer())->respond(); } public function reinstall(ReinstallServerRequest $request, Server $server) @@ -103,7 +114,7 @@ public function getBootOrder(Server $server) return fractal()->item([ 'unused_devices' => DiskData::collection($unconfiguredDevices), 'boot_order' => $configuredDevices, - ], new ServerBootOrderTransformer)->respond(); + ], new ServerBootOrderTransformer())->respond(); } public function updateBootOrder(UpdateBootOrderRequest $request, Server $server) @@ -119,7 +130,9 @@ public function getMedia(Request $request, Server $server) if ($request->user()->root_admin) { $media = $server->node->isos()->where('is_successful', '=', true)->get()->toArray(); } else { - $media = $server->node->isos()->where([['hidden', '=', false], ['is_successful', '=', true]])->get()->toArray(); + $media = $server->node->isos()->where( + [['hidden', '=', false], ['is_successful', '=', true]], + )->get()->toArray(); } $media = array_map(function ($iso) use ($disks) { @@ -173,7 +186,7 @@ public function getAuthSettings(Server $server) { return fractal()->item([ 'ssh_keys' => $this->authService->getSSHKeys($server), - ], new ServerSecurityTransformer)->respond(); + ], new ServerSecurityTransformer())->respond(); } public function updateAuthSettings(UpdateAuthSettingsRequest $request, Server $server) diff --git a/app/Http/Controllers/Client/Servers/SnapshotController.php b/app/Http/Controllers/Client/Servers/SnapshotController.php index 82f9f33cbf1..546f25f7ecd 100644 --- a/app/Http/Controllers/Client/Servers/SnapshotController.php +++ b/app/Http/Controllers/Client/Servers/SnapshotController.php @@ -2,16 +2,20 @@ namespace Convoy\Http\Controllers\Client\Servers; +use Convoy\Http\Controllers\ApiController; +use Convoy\Http\Requests\Client\Servers\Snapshots\SnapshotRequest; use Convoy\Models\Server; -use Convoy\Http\Controllers\ApplicationApiController; +use Convoy\Repositories\Proxmox\Server\ProxmoxSnapshotRepository; use Convoy\Services\Servers\Snapshots\SnapshotCreationService; use Convoy\Services\Servers\Snapshots\SnapshotDeletionService; -use Convoy\Repositories\Proxmox\Server\ProxmoxSnapshotRepository; -use Convoy\Http\Requests\Client\Servers\Snapshots\SnapshotRequest; -class SnapshotController extends ApplicationApiController +class SnapshotController extends ApiController { - public function __construct(protected ProxmoxSnapshotRepository $repository, protected SnapshotCreationService $creationService, protected SnapshotDeletionService $deletionService) + public function __construct( + protected ProxmoxSnapshotRepository $repository, + protected SnapshotCreationService $creationService, + protected SnapshotDeletionService $deletionService, + ) { } @@ -22,7 +26,9 @@ public function index(Server $server) return inertia('servers/snapshots/Index', [ 'server' => $server, 'snapshots' => $snapshots, - 'can_create' => isset($server->snapshot_limit) ? (count($snapshots) - 1) < $server->snapshot_limit : true, + 'can_create' => isset($server->snapshot_limit) ? (count( + $snapshots, + ) - 1) < $server->snapshot_limit : true, ]); }