mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-11 09:09:34 +00:00
fix: check automation usage in all rundowns before allowing delete
This commit is contained in:
committed by
Alex Christoffer Rasmussen
parent
cbd7bce106
commit
bcabc50ad1
@@ -2,9 +2,8 @@ import type {
|
||||
Automation,
|
||||
AutomationDTO,
|
||||
AutomationSettings,
|
||||
EntryId,
|
||||
NormalisedAutomation,
|
||||
Rundown,
|
||||
ProjectRundowns,
|
||||
Trigger,
|
||||
TriggerDTO,
|
||||
} from 'ontime-types';
|
||||
@@ -136,15 +135,15 @@ export async function editAutomation(id: string, newAutomation: AutomationDTO):
|
||||
/**
|
||||
* Deletes a automation given its ID
|
||||
*/
|
||||
export async function deleteAutomation(rundown: Rundown, timedEventOrder: EntryId[], id: string): Promise<void> {
|
||||
export async function deleteAutomation(projectRundowns: ProjectRundowns, automationId: string): Promise<void> {
|
||||
const automations = getAutomations();
|
||||
// ignore request if automation does not exist
|
||||
if (!Object.hasOwn(automations, id)) {
|
||||
if (!Object.hasOwn(automations, automationId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// prevent deleting a automation that is in use in triggers
|
||||
const triggers = getAutomationTriggers().filter((trigger) => trigger.automationId === id);
|
||||
const triggers = getAutomationTriggers().filter((trigger) => trigger.automationId === automationId);
|
||||
if (triggers.length) {
|
||||
throw new Error(
|
||||
`Unable to delete automation used in trigger ${triggers[0].title}${triggers.length > 1 ? ` and ${triggers.length - 1} more` : ''}`,
|
||||
@@ -152,12 +151,12 @@ export async function deleteAutomation(rundown: Rundown, timedEventOrder: EntryI
|
||||
}
|
||||
|
||||
// prevent deleting a automation that is in use in events
|
||||
const isInUse = isAutomationUsed(rundown, timedEventOrder, id);
|
||||
const isInUse = isAutomationUsed(projectRundowns, automationId);
|
||||
if (isInUse) {
|
||||
throw new Error(`Unable to delete automation used in event with ID ${isInUse}`);
|
||||
throw new Error(`Unable to delete automation used in rundown: ${isInUse[0]}, in event with ID: ${isInUse[1]}`);
|
||||
}
|
||||
|
||||
delete automations[id];
|
||||
delete automations[automationId];
|
||||
await saveChanges({ automations });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user