mirror of
https://github.com/pelican-dev/panel.git
synced 2025-10-29 22:36:51 +01:00
Allow both nodes for server requests when doing transfers (#1701)
This commit is contained in:
parent
246997754e
commit
19103b16b8
@ -16,6 +16,14 @@ class ServerRequest extends FormRequest
|
||||
/** @var ?Server $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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,13 +62,15 @@ class TransferServerService
|
||||
|
||||
$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.
|
||||
$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) {
|
||||
$transfer->old_allocation = $server->allocation_id;
|
||||
$transfer->new_allocation = $allocation_id;
|
||||
@ -81,6 +83,9 @@ class TransferServerService
|
||||
|
||||
$transfer->save();
|
||||
|
||||
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))
|
||||
@ -90,9 +95,6 @@ class TransferServerService
|
||||
// Notify the source node of the pending outgoing transfer.
|
||||
$this->notify($transfer, $token);
|
||||
|
||||
return $transfer;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -106,7 +108,7 @@ class TransferServerService
|
||||
$allocations = $additional_allocations;
|
||||
$allocations[] = $allocation_id;
|
||||
|
||||
$node = Node::query()->findOrFail($node_id);
|
||||
$node = Node::findOrFail($node_id);
|
||||
$unassigned = $node->allocations()
|
||||
->whereNull('server_id')
|
||||
->pluck('id')
|
||||
@ -122,7 +124,7 @@ class TransferServerService
|
||||
}
|
||||
|
||||
if (!empty($updateIds)) {
|
||||
Allocation::query()->whereIn('id', $updateIds)->update(['server_id' => $server->id]);
|
||||
Allocation::whereIn('id', $updateIds)->update(['server_id' => $server->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user