From a787af7a060d009fe3c56ed78dbd1777f60b7516 Mon Sep 17 00:00:00 2001 From: notCharles Date: Wed, 13 Nov 2024 16:21:27 -0500 Subject: [PATCH] Prevent Select All Prevent Select all on allocations, prevent people from trying to delete 30,000 ports at once .... --- .../AllocationsRelationManager.php | 25 ++++++--------- .../AllocationsRelationManager.php | 31 ++++++++++--------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php b/app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php index 5cdf2b172..e0ef8a064 100644 --- a/app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php +++ b/app/Filament/Resources/NodeResource/RelationManagers/AllocationsRelationManager.php @@ -46,8 +46,9 @@ class AllocationsRelationManager extends RelationManager // ->checkIfRecordIsSelectableUsing(fn (Allocation $allocation) => $allocation->id !== $allocation->server?->allocation_id) // All assigned allocations - ->checkIfRecordIsSelectableUsing(fn (Allocation $allocation) => $allocation->server_id === null) + ->checkIfRecordIsSelectableUsing(fn(Allocation $allocation) => $allocation->server_id === null) ->searchable() + ->selectCurrentPageOnly() //Prevent people from trying to nuke 30,000 ports at once.... -,- ->columns([ TextColumn::make('id'), TextColumn::make('port') @@ -57,7 +58,7 @@ class AllocationsRelationManager extends RelationManager ->label('Server') ->icon('tabler-brand-docker') ->searchable() - ->url(fn (Allocation $allocation): string => $allocation->server ? route('filament.admin.resources.servers.edit', ['record' => $allocation->server]) : ''), + ->url(fn(Allocation $allocation): string => $allocation->server ? route('filament.admin.resources.servers.edit', ['record' => $allocation->server]) : ''), TextInputColumn::make('ip_alias') ->searchable() ->label('Alias'), @@ -65,15 +66,9 @@ class AllocationsRelationManager extends RelationManager ->searchable() ->label('IP'), ]) - ->filters([ - // - ]) - ->actions([ - // - ]) ->headerActions([ Tables\Actions\Action::make('create new allocation')->label('Create Allocations') - ->form(fn () => [ + ->form(fn() => [ TextInput::make('allocation_ip') ->datalist($this->getOwnerRecord()->ipAddresses()) ->label('IP Address') @@ -103,7 +98,7 @@ class AllocationsRelationManager extends RelationManager foreach ($state as $portEntry) { if (!str_contains($portEntry, '-')) { if (is_numeric($portEntry)) { - $ports->push((int) $portEntry); + $ports->push((int)$portEntry); continue; } @@ -120,8 +115,8 @@ class AllocationsRelationManager extends RelationManager continue; } - $start = max((int) $start, 0); - $end = min((int) $end, 2 ** 16 - 1); + $start = max((int)$start, 0); + $end = min((int)$end, 2 ** 16 - 1); foreach (range($start, $end) as $i) { $ports->push($i); } @@ -139,7 +134,7 @@ class AllocationsRelationManager extends RelationManager $ports = $sortedPorts; } - $ports = $ports->filter(fn ($port) => $port > 1024 && $port < 65535)->values(); + $ports = $ports->filter(fn($port) => $port > 1024 && $port < 65535)->values(); if ($update) { $set('allocation_ports', $ports->all()); @@ -148,12 +143,12 @@ class AllocationsRelationManager extends RelationManager ->splitKeys(['Tab', ' ', ',']) ->required(), ]) - ->action(fn (array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord(), $data)), + ->action(fn(array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord(), $data)), ]) ->bulkActions([ BulkActionGroup::make([ DeleteBulkAction::make() - ->authorize(fn () => auth()->user()->can('delete allocation')), + ->authorize(fn() => auth()->user()->can('delete allocation')), ]), ]); } diff --git a/app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php b/app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php index 99bc6bb48..c6f1daf7f 100644 --- a/app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php +++ b/app/Filament/Resources/ServerResource/RelationManagers/AllocationsRelationManager.php @@ -40,36 +40,37 @@ class AllocationsRelationManager extends RelationManager public function table(Table $table): Table { return $table + ->selectCurrentPageOnly() ->recordTitleAttribute('ip') - ->recordTitle(fn (Allocation $allocation) => "$allocation->ip:$allocation->port") - ->checkIfRecordIsSelectableUsing(fn (Allocation $record) => $record->id !== $this->getOwnerRecord()->allocation_id) + ->recordTitle(fn(Allocation $allocation) => "$allocation->ip:$allocation->port") + ->checkIfRecordIsSelectableUsing(fn(Allocation $record) => $record->id !== $this->getOwnerRecord()->allocation_id) ->inverseRelationship('server') ->columns([ TextColumn::make('ip')->label('IP'), TextColumn::make('port')->label('Port'), TextInputColumn::make('ip_alias')->label('Alias'), IconColumn::make('primary') - ->icon(fn ($state) => match ($state) { + ->icon(fn($state) => match ($state) { true => 'tabler-star-filled', default => 'tabler-star', }) - ->color(fn ($state) => match ($state) { + ->color(fn($state) => match ($state) { true => 'warning', default => 'gray', }) - ->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords()) - ->default(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id) + ->action(fn(Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords()) + ->default(fn(Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id) ->label('Primary'), ]) ->actions([ Action::make('make-primary') - ->action(fn (Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords()) - ->label(fn (Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id ? '' : 'Make Primary'), + ->action(fn(Allocation $allocation) => $this->getOwnerRecord()->update(['allocation_id' => $allocation->id]) && $this->deselectAllTableRecords()) + ->label(fn(Allocation $allocation) => $allocation->id === $this->getOwnerRecord()->allocation_id ? '' : 'Make Primary'), ]) ->headerActions([ CreateAction::make()->label('Create Allocation') ->createAnother(false) - ->form(fn () => [ + ->form(fn() => [ TextInput::make('allocation_ip') ->datalist($this->getOwnerRecord()->node->ipAddresses()) ->label('IP Address') @@ -99,7 +100,7 @@ class AllocationsRelationManager extends RelationManager foreach ($state as $portEntry) { if (!str_contains($portEntry, '-')) { if (is_numeric($portEntry)) { - $ports->push((int) $portEntry); + $ports->push((int)$portEntry); continue; } @@ -116,8 +117,8 @@ class AllocationsRelationManager extends RelationManager continue; } - $start = max((int) $start, 0); - $end = min((int) $end, 2 ** 16 - 1); + $start = max((int)$start, 0); + $end = min((int)$end, 2 ** 16 - 1); foreach (range($start, $end) as $i) { $ports->push($i); } @@ -135,7 +136,7 @@ class AllocationsRelationManager extends RelationManager $ports = $sortedPorts; } - $ports = $ports->filter(fn ($port) => $port > 1024 && $port < 65535)->values(); + $ports = $ports->filter(fn($port) => $port > 1024 && $port < 65535)->values(); if ($update) { $set('allocation_ports', $ports->all()); @@ -144,12 +145,12 @@ class AllocationsRelationManager extends RelationManager ->splitKeys(['Tab', ' ', ',']) ->required(), ]) - ->action(fn (array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord()->node, $data, $this->getOwnerRecord())), + ->action(fn(array $data, AssignmentService $service) => $service->handle($this->getOwnerRecord()->node, $data, $this->getOwnerRecord())), AssociateAction::make() ->multiple() ->associateAnother(false) ->preloadRecordSelect() - ->recordSelectOptionsQuery(fn ($query) => $query->whereBelongsTo($this->getOwnerRecord()->node)->whereNull('server_id')) + ->recordSelectOptionsQuery(fn($query) => $query->whereBelongsTo($this->getOwnerRecord()->node)->whereNull('server_id')) ->label('Add Allocation'), ]) ->bulkActions([