Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: empty remote destinations could be removed

Andras Bacsai99bc37466426
diff --git a/apps/api/src/routes/api/v1/destinations/handlers.ts b/apps/api/src/routes/api/v1/destinations/handlers.ts
index 11b7903164..3966ecab9b 100644
--- a/apps/api/src/routes/api/v1/destinations/handlers.ts
+++ b/apps/api/src/routes/api/v1/destinations/handlers.ts
@@ -54,7 +54,7 @@ export async function getDestination(request: FastifyRequest<OnlyId>) {
const teamId = request.user?.teamId;
const destination = await prisma.destinationDocker.findFirst({
where: { id, teams: { some: { id: teamId === '0' ? undefined : teamId } } },
- include: { sshKey: true }
+ include: { sshKey: true, application: true, service: true, database: true }
});
if (!destination && id !== 'new') {
throw { status: 404, message: `Destination not found.` };
diff --git a/apps/ui/src/routes/destinations/[id]/__layout.svelte b/apps/ui/src/routes/destinations/[id]/__layout.svelte
index d97c547bc2..a653c17aa1 100644
--- a/apps/ui/src/routes/destinations/[id]/__layout.svelte
+++ b/apps/ui/src/routes/destinations/[id]/__layout.svelte
@@ -58,8 +58,10 @@
import DeleteIcon from '$lib/components/DeleteIcon.svelte';
const { id } = $page.params;
-
+ const isDestinationDeletable = destination.application.length === 0 && destination.database.length === 0 && destination.service.length === 0
+
async function deleteDestination(destination: any) {
+ if (!isDestinationDeletable) return
const sure = confirm($t('application.confirm_to_delete', { name: destination.name }));
if (sure) {
try {
@@ -70,20 +72,29 @@
}
}
}
+ function deletable() {
+ if (!isDestinationDeletable) {
+ return "Please delete all resources before deleting this."
+ }
+ if ($appSession.isAdmin) {
+ return $t('destination.delete_destination')
+ } else {
+ return $t('destination.permission_denied_delete_destination')
+ }
+ }
</script>
{#if id !== 'new'}
<nav class="nav-side">
<button
on:click={() => deleteDestination(destination)}
- title={$t('source.delete_git_source')}
+ title={$t('destination.delete_destination')}
type="submit"
- disabled={!$appSession.isAdmin}
- class:hover:text-red-500={$appSession.isAdmin}
+ disabled={!$appSession.isAdmin && isDestinationDeletable}
+ class:hover:text-red-500={$appSession.isAdmin && isDestinationDeletable}
class="icons tooltip-bottom bg-transparent text-sm"
- data-tooltip={$appSession.isAdmin
- ? $t('destination.delete_destination')
- : $t('destination.permission_denied_delete_destination')}><DeleteIcon /></button
+ class:text-stone-600={!isDestinationDeletable}
+ data-tooltip={deletable()}><DeleteIcon /></button
>
</nav>
{/if}