Deactivate workflow when deleted (#12677)
## Done Update manually (without status update job) workflow and workflowVersions statuses when workflow is deleted ## Not Done Status optimistic rendering on workflow index deleted page. This page is already buggy, this will be fix by https://discord.com/channels/1130383047699738754/1384177035244732487
This commit is contained in:
@ -13,12 +13,19 @@ import {
|
|||||||
} from 'src/modules/workflow/common/exceptions/workflow-common.exception';
|
} from 'src/modules/workflow/common/exceptions/workflow-common.exception';
|
||||||
import { WorkflowAutomatedTriggerWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-automated-trigger.workspace-entity';
|
import { WorkflowAutomatedTriggerWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-automated-trigger.workspace-entity';
|
||||||
import { WorkflowRunWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
|
import { WorkflowRunWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
|
||||||
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
import {
|
||||||
|
WorkflowVersionStatus,
|
||||||
|
WorkflowVersionWorkspaceEntity,
|
||||||
|
} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||||
import { WorkflowActionType } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
|
import { WorkflowActionType } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
|
||||||
import {
|
import {
|
||||||
WorkflowTriggerException,
|
WorkflowTriggerException,
|
||||||
WorkflowTriggerExceptionCode,
|
WorkflowTriggerExceptionCode,
|
||||||
} from 'src/modules/workflow/workflow-trigger/exceptions/workflow-trigger.exception';
|
} from 'src/modules/workflow/workflow-trigger/exceptions/workflow-trigger.exception';
|
||||||
|
import {
|
||||||
|
WorkflowStatus,
|
||||||
|
WorkflowWorkspaceEntity,
|
||||||
|
} from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
|
||||||
|
|
||||||
export type ObjectMetadataInfo = {
|
export type ObjectMetadataInfo = {
|
||||||
objectMetadataItemWithFieldsMaps: ObjectMetadataItemWithFieldMaps;
|
objectMetadataItemWithFieldsMaps: ObjectMetadataItemWithFieldMaps;
|
||||||
@ -182,6 +189,13 @@ export class WorkflowCommonWorkspaceService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.deactivateVersionOnDelete({
|
||||||
|
workflowVersionRepository,
|
||||||
|
workflowId,
|
||||||
|
workspaceId,
|
||||||
|
operation,
|
||||||
|
});
|
||||||
|
|
||||||
await this.handleServerlessFunctionSubEntities({
|
await this.handleServerlessFunctionSubEntities({
|
||||||
workflowVersionRepository,
|
workflowVersionRepository,
|
||||||
workflowId,
|
workflowId,
|
||||||
@ -191,6 +205,62 @@ export class WorkflowCommonWorkspaceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async deactivateVersionOnDelete({
|
||||||
|
workflowVersionRepository,
|
||||||
|
workflowId,
|
||||||
|
workspaceId,
|
||||||
|
operation,
|
||||||
|
}: {
|
||||||
|
workflowVersionRepository: WorkspaceRepository<WorkflowVersionWorkspaceEntity>;
|
||||||
|
workspaceId: string;
|
||||||
|
workflowId: string;
|
||||||
|
operation: 'restore' | 'delete' | 'destroy';
|
||||||
|
}) {
|
||||||
|
if (operation !== 'delete') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const workflowRepository =
|
||||||
|
await this.twentyORMGlobalManager.getRepositoryForWorkspace<WorkflowWorkspaceEntity>(
|
||||||
|
workspaceId,
|
||||||
|
'workflow',
|
||||||
|
{ shouldBypassPermissionChecks: true }, // settings permissions are checked at resolver-level
|
||||||
|
);
|
||||||
|
|
||||||
|
const workflow = await workflowRepository.findOne({
|
||||||
|
where: { id: workflowId },
|
||||||
|
withDeleted: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (workflow?.statuses?.includes(WorkflowStatus.ACTIVE)) {
|
||||||
|
const newStatuses = [
|
||||||
|
...workflow.statuses.filter(
|
||||||
|
(status) => status !== WorkflowStatus.ACTIVE,
|
||||||
|
),
|
||||||
|
WorkflowStatus.DEACTIVATED,
|
||||||
|
];
|
||||||
|
|
||||||
|
await workflowRepository.update(workflowId, {
|
||||||
|
statuses: newStatuses,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const workflowVersions = await workflowVersionRepository.find({
|
||||||
|
where: {
|
||||||
|
workflowId,
|
||||||
|
},
|
||||||
|
withDeleted: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const workflowVersion of workflowVersions) {
|
||||||
|
if (workflowVersion.status === WorkflowVersionStatus.ACTIVE) {
|
||||||
|
await workflowVersionRepository.update(workflowVersion.id, {
|
||||||
|
status: WorkflowVersionStatus.DEACTIVATED,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async handleServerlessFunctionSubEntities({
|
async handleServerlessFunctionSubEntities({
|
||||||
workflowVersionRepository,
|
workflowVersionRepository,
|
||||||
workflowId,
|
workflowId,
|
||||||
@ -198,9 +268,7 @@ export class WorkflowCommonWorkspaceService {
|
|||||||
operation,
|
operation,
|
||||||
}: {
|
}: {
|
||||||
workflowVersionRepository: WorkspaceRepository<WorkflowVersionWorkspaceEntity>;
|
workflowVersionRepository: WorkspaceRepository<WorkflowVersionWorkspaceEntity>;
|
||||||
|
|
||||||
workflowId: string;
|
workflowId: string;
|
||||||
|
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
operation: 'restore' | 'delete' | 'destroy';
|
operation: 'restore' | 'delete' | 'destroy';
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user