Files
pterodactyl-panel/app/Http/Controllers/Api/Admin/Nodes/DeleteAllocationBlockController.php
T

52 lines
2.1 KiB
PHP
Raw Normal View History

2026-10-05 18:10:18 -04:00
<?php
declare(strict_types=1);
namespace Pterodactyl\Http\Controllers\Api\Admin\Nodes;
use Illuminate\Http\Response;
2026-10-08 17:40:00 -04:00
use Illuminate\Support\Facades\DB;
2026-10-05 18:10:18 -04:00
use Knuckles\Scribe\Attributes\Endpoint;
use Knuckles\Scribe\Attributes\Group;
use Knuckles\Scribe\Attributes\Response as ScribeResponse;
use Knuckles\Scribe\Attributes\Subgroup;
2026-10-08 17:40:00 -04:00
use Pterodactyl\Contracts\Allocations\DeletesAllocations;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Facades\Activity;
use Pterodactyl\Http\Controllers\Api\Admin\AdminApiController;
use Pterodactyl\Http\Requests\Api\Admin\Nodes\Allocations\BlockDeleteAllocationRequest;
2026-10-08 17:40:00 -04:00
use Pterodactyl\Models\Allocation;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Node;
use Pterodactyl\Support\JsonValueGuard;
2026-10-08 17:40:00 -04:00
use Throwable;
2026-10-05 18:10:18 -04:00
#[Group('Admin API', 'Root administrator endpoints for managing panel configuration and resources.')]
#[Subgroup('Node Allocations', 'Create, update, retrieve, and delete node allocations.')]
class DeleteAllocationBlockController extends AdminApiController
{
/**
* Delete unassigned allocations for IP block.
2026-10-08 17:40:00 -04:00
*
* @throws Throwable
2026-10-05 18:10:18 -04:00
*/
#[Endpoint('Delete node allocation IP block', 'Deletes every unassigned allocation for an IP address on a node.')]
#[ScribeResponse(status: 204, description: 'Unassigned allocations for the IP were deleted.')]
2026-10-08 17:40:00 -04:00
public function __invoke(BlockDeleteAllocationRequest $request, DeletesAllocations $deleter, Node $node): Response
2026-10-05 18:10:18 -04:00
{
$ip = JsonValueGuard::string($request->validated('ip'));
2026-10-08 17:40:00 -04:00
// Delete through the action so extension wrappers see each allocation, while
// the transaction keeps the block delete all-or-nothing like the bulk query was.
DB::transaction(function () use ($deleter, $node, $ip): void {
$node->allocations()->unassigned()->where('ip', $ip)->lockForUpdate()->get()
->each(fn (Allocation $allocation) => $deleter->delete($allocation));
});
2026-10-05 18:10:18 -04:00
Activity::event('admin:node-allocation.delete-block')
->subject($node)
->property('address', $ip)
->log();
return $this->returnNoContent();
}
}