mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-05 13:55:44 -05:00
fix issue where assigning multiple allocations to a server would only assign the first selection
This commit is contained in:
@@ -79,12 +79,13 @@ final readonly class UpdateServerBuild implements UpdatesServerBuild
|
||||
|
||||
if (! empty($data['add_allocations'])) {
|
||||
// Assign only currently unassigned allocations on this server's node.
|
||||
$query = Allocation::query()->where('node_id', $server->node_id)
|
||||
->whereIn('id', $data['add_allocations'])->whereNull('server_id');
|
||||
$assignable = Allocation::query()->where('node_id', $server->node_id)
|
||||
->whereIn('id', $data['add_allocations'])->whereNull('server_id')
|
||||
->orderBy('id')->lockForUpdate()->get(['id']);
|
||||
Allocation::query()->whereKey($assignable->modelKeys())->update(['server_id' => $server->id, 'notes' => null]);
|
||||
// If the default allocation is removed below, use the first newly assigned
|
||||
// allocation as its replacement.
|
||||
$freshlyAllocated = $query->first(['id'])?->id;
|
||||
$query->update(['server_id' => $server->id, 'notes' => null]);
|
||||
$freshlyAllocated = $assignable->first()?->id;
|
||||
}
|
||||
|
||||
if (! empty($data['remove_allocations'])) {
|
||||
|
||||
@@ -99,6 +99,17 @@ test('no exception is thrown if only removing allocation', function () {
|
||||
$this->daemonServerRepository->assertSynced();
|
||||
$this->assertDatabaseHas('allocations', ['id' => $allocation->id, 'server_id' => null]);
|
||||
});
|
||||
test('multiple allocations can be added at once', function () {
|
||||
$server = $this->createServerModel();
|
||||
/** @var Allocation[] $allocations */
|
||||
$allocations = Allocation::factory()->times(3)->create(['node_id' => $server->node_id]);
|
||||
$response = getService()->update($server, ['add_allocations' => $allocations->pluck('id')->all()]);
|
||||
$this->daemonServerRepository->assertSynced();
|
||||
expect($response->allocations)->toHaveCount(4);
|
||||
foreach ($allocations as $allocation) {
|
||||
$this->assertDatabaseHas('allocations', ['id' => $allocation->id, 'server_id' => $server->id]);
|
||||
}
|
||||
});
|
||||
test('allocation in both add and remove is added', function () {
|
||||
$server = $this->createServerModel();
|
||||
/** @var Allocation $allocation */
|
||||
|
||||
Reference in New Issue
Block a user