mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +02:00
Prevent Server
primary allocation
dissociation (#1197)
This commit is contained in:
parent
c0fa8c1cd8
commit
484a3b445a
@ -12,14 +12,16 @@ use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Support\Exceptions\Halt;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Actions\AssociateAction;
|
||||
use Filament\Tables\Actions\CreateAction;
|
||||
use Filament\Tables\Actions\DissociateBulkAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Columns\TextInputColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* @method Server getOwnerRecord()
|
||||
@ -96,10 +98,21 @@ class AllocationsRelationManager extends RelationManager
|
||||
->recordSelectSearchColumns(['ip', 'port'])
|
||||
->label(trans('admin/server.add_allocation')),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DissociateBulkAction::make(),
|
||||
]),
|
||||
->groupedBulkActions([
|
||||
DissociateBulkAction::make()
|
||||
->before(function (DissociateBulkAction $action, Collection $records) {
|
||||
$records = $records->filter(function ($allocation) {
|
||||
/** @var Allocation $allocation */
|
||||
return $allocation->id !== $this->getOwnerRecord()->allocation_id;
|
||||
});
|
||||
|
||||
if ($records->isEmpty()) {
|
||||
$action->failureNotificationTitle(trans('admin/server.notifications.dissociate_primary'))->failure();
|
||||
throw new Halt();
|
||||
}
|
||||
|
||||
return $records;
|
||||
}),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,20 @@ class Allocation extends Model
|
||||
static::deleting(function (self $allocation) {
|
||||
throw_if($allocation->server_id, new ServerUsingAllocationException(trans('exceptions.allocations.server_using')));
|
||||
});
|
||||
|
||||
static::updating(function ($allocation) {
|
||||
$originalServerId = $allocation->getOriginal('server_id');
|
||||
if (!$originalServerId) {
|
||||
return;
|
||||
}
|
||||
$server = Server::find($originalServerId);
|
||||
if (!$server) {
|
||||
return;
|
||||
}
|
||||
if ($allocation->isDirty('server_id') && is_null($allocation->server_id) && $allocation->id === $server->allocation_id) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
|
@ -120,6 +120,7 @@ return [
|
||||
'too_many_ports_body' => 'The current limit is :limit number of ports at one time.',
|
||||
'invalid_port' => 'Port not in valid range',
|
||||
'invalid_port_body' => ':i is not in the valid port range between :portFloor-:portCeil',
|
||||
'dissociate_primary' => 'Cannot dissociate primary allocation',
|
||||
'already_exists' => 'Port already in use',
|
||||
'already_exists_body' => ':i is already with an allocation',
|
||||
'error_connecting' => 'Error connecting to :node',
|
||||
|
Loading…
x
Reference in New Issue
Block a user