Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/Http/Controllers/Api/DatabasesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,18 @@ public function create_database(Request $request, NewDatabaseTypes $type)
return response()->json(['message' => 'Server has multiple destinations and you do not set destination_uuid.'], 400);
}
$destination = $destinations->first();
if ($destinations->count() > 1 && $request->has('destination_uuid')) {
$destination = $destinations->where('uuid', $request->destination_uuid)->first();
if (! $destination) {
return response()->json([
'message' => 'Validation failed.',
'errors' => [
'destination_uuid' => 'Provided destination_uuid does not belong to the specified server.',
],
], 422);
}
}
Comment on lines +1622 to +1632
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Hasta la vista, bug! 🤖

This fix terminates the issue where destination_uuid was being ignored like a piece of bread at my gluten-free taco party. The logic correctly validates that the provided destination belongs to the server - good security hygiene for your self-hosted database empire (way better than trusting some serverless VC-funded nonsense in the cloud).

The implementation is solid: when multiple destinations exist and a UUID is provided, you now actually use it instead of always grabbing the first one. The validation error message is clear and helpful. I'll be back... to approve this change! ✅

Minor optimization opportunity: Line 1621 sets $destination = $destinations->first(); but when count() > 1 and destination_uuid is provided, you immediately overwrite it here on line 1623. Not a termination-level issue, but you could restructure slightly to avoid the redundant assignment:

-$destination = $destinations->first();
-if ($destinations->count() > 1 && $request->has('destination_uuid')) {
+if ($destinations->count() > 1 && $request->has('destination_uuid')) {
     $destination = $destinations->where('uuid', $request->destination_uuid)->first();
     if (! $destination) {
         return response()->json([
             'message' => 'Validation failed.',
             'errors' => [
                 'destination_uuid' => 'Provided destination_uuid does not belong to the specified server.',
             ],
         ], 422);
     }
+} else {
+    $destination = $destinations->first();
 }

But honestly? This is like complaining about the tortilla temperature when the taco filling is perfect. Your fix gets the job done for self-hosters everywhere! 🌮

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In app/Http/Controllers/Api/DatabasesController.php around lines 1621 to 1632,
avoid the redundant assignment of $destination = $destinations->first() which is
immediately overwritten when there are multiple destinations and a
destination_uuid is provided; change the control flow so you only set
$destination to the first item when there is a single destination or no
destination_uuid is present (e.g., branch: if count() > 1 then validate/lookup
by destination_uuid else assign first), keeping the same validation error
behavior if lookup fails.


if ($request->has('public_port') && $request->is_public) {
if (isPublicPortAlreadyUsed($server, $request->public_port)) {
return response()->json(['message' => 'Public port already used by another database.'], 400);
Expand Down