fix: empty remote destinations could be removed

This commit is contained in:
Andras Bacsai 2022-08-08 12:17:01 +00:00
parent b999e7dab1
commit 99bc374664
2 changed files with 19 additions and 8 deletions

View File

@ -54,7 +54,7 @@ export async function getDestination(request: FastifyRequest<OnlyId>) {
const teamId = request.user?.teamId; const teamId = request.user?.teamId;
const destination = await prisma.destinationDocker.findFirst({ const destination = await prisma.destinationDocker.findFirst({
where: { id, teams: { some: { id: teamId === '0' ? undefined : teamId } } }, 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') { if (!destination && id !== 'new') {
throw { status: 404, message: `Destination not found.` }; throw { status: 404, message: `Destination not found.` };

View File

@ -58,8 +58,10 @@
import DeleteIcon from '$lib/components/DeleteIcon.svelte'; import DeleteIcon from '$lib/components/DeleteIcon.svelte';
const { id } = $page.params; const { id } = $page.params;
const isDestinationDeletable = destination.application.length === 0 && destination.database.length === 0 && destination.service.length === 0
async function deleteDestination(destination: any) { async function deleteDestination(destination: any) {
if (!isDestinationDeletable) return
const sure = confirm($t('application.confirm_to_delete', { name: destination.name })); const sure = confirm($t('application.confirm_to_delete', { name: destination.name }));
if (sure) { if (sure) {
try { 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> </script>
{#if id !== 'new'} {#if id !== 'new'}
<nav class="nav-side"> <nav class="nav-side">
<button <button
on:click={() => deleteDestination(destination)} on:click={() => deleteDestination(destination)}
title={$t('source.delete_git_source')} title={$t('destination.delete_destination')}
type="submit" type="submit"
disabled={!$appSession.isAdmin} disabled={!$appSession.isAdmin && isDestinationDeletable}
class:hover:text-red-500={$appSession.isAdmin} class:hover:text-red-500={$appSession.isAdmin && isDestinationDeletable}
class="icons tooltip-bottom bg-transparent text-sm" class="icons tooltip-bottom bg-transparent text-sm"
data-tooltip={$appSession.isAdmin class:text-stone-600={!isDestinationDeletable}
? $t('destination.delete_destination') data-tooltip={deletable()}><DeleteIcon /></button
: $t('destination.permission_denied_delete_destination')}><DeleteIcon /></button
> >
</nav> </nav>
{/if} {/if}