diff --git a/CHANGELOG.md b/CHANGELOG.md index 811743cb8..ec553efb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. ### Changed * Deleting a server safely now continues even if the daemon reports a `HTTP/404` missing server error (requires `Daemon@0.4.0-beta.2.1`) +* Changed behavior when modifying server allocation information. You can now remove the default allocation assuming you assing a new allocation at the same time. Reduces the number of steps to change the default allocation for a server. ### Added * Server listing and view in Admin CP now shows the SFTP username/Docker container name. diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 67d4468bd..674afa670 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -518,23 +518,7 @@ class ServerRepository } $newPorts = false; - // Remove Assignments - if (isset($data['remove_allocations'])) { - foreach ($data['remove_allocations'] as $allocation) { - // Can't remove the assigned IP/Port combo - if ((int) $allocation === $server->allocation_id) { - continue; - } - - $newPorts = true; - Models\Allocation::where('id', $allocation)->where('server_id', $server->id)->update([ - 'server_id' => null, - ]); - } - - $server->load('allocations'); - } - + $firstNewAllocation = null; // Add Assignments if (isset($data['add_allocations'])) { foreach ($data['add_allocations'] as $allocation) { @@ -544,6 +528,7 @@ class ServerRepository } $newPorts = true; + $firstNewAllocation = (is_null($firstNewAllocation)) ? $model->id : $firstNewAllocation; $model->update([ 'server_id' => $server->id, ]); @@ -552,6 +537,29 @@ class ServerRepository $server->load('allocations'); } + // Remove Assignments + if (isset($data['remove_allocations'])) { + foreach ($data['remove_allocations'] as $allocation) { + // Can't remove the assigned IP/Port combo + if ((int) $allocation === $server->allocation_id) { + // No New Allocation + if (is_null($firstNewAllocation)) { + continue; + } + + // New Allocation, set as the default. + $server->allocation_id = $firstNewAllocation; + } + + $newPorts = true; + Models\Allocation::where('id', $allocation)->where('server_id', $server->id)->update([ + 'server_id' => null, + ]); + } + + $server->load('allocations'); + } + if ($newPorts) { $newBuild['ports|overwrite'] = $server->allocations->groupBy('ip')->map(function ($item) { return $item->pluck('port'); diff --git a/resources/themes/pterodactyl/admin/servers/view/build.blade.php b/resources/themes/pterodactyl/admin/servers/view/build.blade.php index fb037cb67..42057ccf2 100644 --- a/resources/themes/pterodactyl/admin/servers/view/build.blade.php +++ b/resources/themes/pterodactyl/admin/servers/view/build.blade.php @@ -130,7 +130,7 @@