Allow both nodes for server requests when doing transfers (#1701)

This commit is contained in:
Boy132 2025-10-02 17:55:20 +02:00 committed by GitHub
parent 246997754e
commit 19103b16b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 17 deletions

View File

@ -16,6 +16,14 @@ class ServerRequest extends FormRequest
/** @var ?Server $server */ /** @var ?Server $server */
$server = $this->route()->parameter('server'); $server = $this->route()->parameter('server');
return $server && $server->node_id === $node->id; if ($server) {
if ($server->transfer) {
return $server->transfer->old_node === $node->id || $server->transfer->new_node === $node->id;
}
return $server->node_id === $node->id;
}
return false;
} }
} }

View File

@ -62,13 +62,15 @@ class TransferServerService
$server->validateTransferState(); $server->validateTransferState();
$this->connection->transaction(function () use ($server, $node_id, $allocation_id, $additional_allocations) { /** @var ServerTransfer $transfer */
$transfer = $this->connection->transaction(function () use ($server, $node_id, $allocation_id, $additional_allocations) {
// Create a new ServerTransfer entry. // Create a new ServerTransfer entry.
$transfer = new ServerTransfer(); $transfer = ServerTransfer::create([
'server_id' => $server->id,
'old_node' => $server->node_id,
'new_node' => $node_id,
]);
$transfer->server_id = $server->id;
$transfer->old_node = $server->node_id;
$transfer->new_node = $node_id;
if ($server->allocation_id) { if ($server->allocation_id) {
$transfer->old_allocation = $server->allocation_id; $transfer->old_allocation = $server->allocation_id;
$transfer->new_allocation = $allocation_id; $transfer->new_allocation = $allocation_id;
@ -81,18 +83,18 @@ class TransferServerService
$transfer->save(); $transfer->save();
// Generate a token for the destination node that the source node can use to authenticate with.
$token = $this->nodeJWTService
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
->setSubject($server->uuid)
->handle($transfer->newNode, $server->uuid, 'sha256');
// Notify the source node of the pending outgoing transfer.
$this->notify($transfer, $token);
return $transfer; return $transfer;
}); });
// Generate a token for the destination node that the source node can use to authenticate with.
$token = $this->nodeJWTService
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
->setSubject($server->uuid)
->handle($transfer->newNode, $server->uuid, 'sha256');
// Notify the source node of the pending outgoing transfer.
$this->notify($transfer, $token);
return true; return true;
} }
@ -106,7 +108,7 @@ class TransferServerService
$allocations = $additional_allocations; $allocations = $additional_allocations;
$allocations[] = $allocation_id; $allocations[] = $allocation_id;
$node = Node::query()->findOrFail($node_id); $node = Node::findOrFail($node_id);
$unassigned = $node->allocations() $unassigned = $node->allocations()
->whereNull('server_id') ->whereNull('server_id')
->pluck('id') ->pluck('id')
@ -122,7 +124,7 @@ class TransferServerService
} }
if (!empty($updateIds)) { if (!empty($updateIds)) {
Allocation::query()->whereIn('id', $updateIds)->update(['server_id' => $server->id]); Allocation::whereIn('id', $updateIds)->update(['server_id' => $server->id]);
} }
} }
} }