mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-11 00:59:35 +00:00
fix(automation): delete an automation together with its global triggers
The server refused to delete an automation while any global trigger pointed at it, so removing one meant finding its triggers in a second list and deleting each by hand first. The refusal was protecting against dead data, but a trigger pointing at a deleted automation is the dead data. Both are now written in a single patch, so there is no window where one outlives the other and nothing to roll back. An automation attached to an event is still refused: that reference lives in the rundown, and removing it is an edit to the show rather than to the automation settings. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AfDKsy6PE3Rbyt32Fg4YKf
This commit is contained in:
@@ -145,24 +145,18 @@ export async function deleteAutomation(projectRundowns: ProjectRundowns, automat
|
||||
return;
|
||||
}
|
||||
|
||||
// prevent deleting a automation that is in use in triggers
|
||||
const triggers = getAutomationTriggers().filter((trigger) => trigger.automationId === automationId);
|
||||
if (triggers.length) {
|
||||
const firstTrigger = triggers[0];
|
||||
const triggerTitle = firstTrigger?.title ?? 'Unknown trigger';
|
||||
throw new Error(
|
||||
`Unable to delete automation used in trigger ${triggerTitle}${triggers.length > 1 ? ` and ${triggers.length - 1} more` : ''}`,
|
||||
);
|
||||
}
|
||||
|
||||
// prevent deleting a automation that is in use in events
|
||||
// prevent deleting a automation that is in use in events, the user has to unlink it there
|
||||
const isInUse = isAutomationUsed(projectRundowns, automationId);
|
||||
if (isInUse) {
|
||||
throw new Error(`Unable to delete automation used in rundown: ${isInUse[0]}, in event with ID: ${isInUse[1]}`);
|
||||
}
|
||||
|
||||
// a global trigger without its automation is dead data, so it goes with it.
|
||||
// Both are written in a single patch, there is no state where one outlived the other
|
||||
const triggers = getAutomationTriggers().filter((trigger) => trigger.automationId !== automationId);
|
||||
|
||||
delete automations[automationId];
|
||||
await saveChanges({ automations });
|
||||
await saveChanges({ automations, triggers });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user