Activate/Deactivate workflow and Discard Draft (#7022)
## Setup This PR can be tested only if some feature flags have specific values: - `IsWorkflowEnabled` equals `true` - `IsQueryRunnerTwentyORMEnabled` equals `false` These feature flags weren't committed to don't break other branches. ## What this PR brings - Display buttons to activate and deactivate a workflow version and a button to discard the current draft version. I also scaffolded a "Test" button, which doesn't do anything for now. - Wired the activate, deactivate and discard draft buttons to the backend. - Made it possible to "edit" active and deactivated versions by automatically creating a new draft version when the user tries to edit the version. - Hide the "Discard Draft", button if the current version is not a draft or is the first version ever created. - On the backend, don't consider discarded drafts when checking if a new draft version can be created. - On the backend, disallow deleting the first created workflow version. Otherwise, we will end up with a blank canvas in the front end, and it will be impossible to recover from it. - On the backend, disallow running deactivation steps if the workflow version is not currently active. Previously, we were throwing, which is unnecessary as it's a valid case. ## Spotted bugs that we must dive into ### Duplicate workflow versions in Apollo cache https://github.com/user-attachments/assets/7cfffd06-11e0-417a-8da0-f9a5f43b84e2 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
committed by
GitHub
parent
75b493ba6c
commit
729c990546
@ -12,6 +12,7 @@ import {
|
||||
getDevSeedCompanyCustomFields,
|
||||
getDevSeedPeopleCustomFields,
|
||||
} from 'src/database/typeorm-seeds/metadata/fieldsMetadata';
|
||||
import { getDevSeedCustomObjects } from 'src/database/typeorm-seeds/metadata/objectsMetadata';
|
||||
import { seedCalendarChannels } from 'src/database/typeorm-seeds/workspace/calendar-channel';
|
||||
import { seedCalendarChannelEventAssociations } from 'src/database/typeorm-seeds/workspace/calendar-channel-event-association';
|
||||
import { seedCalendarEventParticipants } from 'src/database/typeorm-seeds/workspace/calendar-event-participants';
|
||||
@ -150,6 +151,7 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
|
||||
objectMetadataMap[STANDARD_OBJECT_IDS.person],
|
||||
workspaceId,
|
||||
);
|
||||
await this.seedCustomObjects(workspaceId, dataSourceMetadata.id);
|
||||
|
||||
await workspaceDataSource.transaction(
|
||||
async (entityManager: EntityManager) => {
|
||||
@ -282,4 +284,15 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async seedCustomObjects(workspaceId: string, dataSourceId: string) {
|
||||
const devSeedCustomObjects = getDevSeedCustomObjects(
|
||||
workspaceId,
|
||||
dataSourceId,
|
||||
);
|
||||
|
||||
for (const customObject of devSeedCustomObjects) {
|
||||
await this.objectMetadataService.createOne(customObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
import { CreateObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/create-object.input';
|
||||
|
||||
export const getDevSeedCustomObjects = (
|
||||
workspaceId: string,
|
||||
dataSourceId: string,
|
||||
): CreateObjectInput[] => {
|
||||
return [
|
||||
{
|
||||
workspaceId,
|
||||
dataSourceId,
|
||||
labelPlural: 'Rockets',
|
||||
labelSingular: 'Rocket',
|
||||
namePlural: 'rockets',
|
||||
nameSingular: 'rocket',
|
||||
description: 'A rocket',
|
||||
icon: 'IconRocket',
|
||||
isRemote: false,
|
||||
},
|
||||
];
|
||||
};
|
||||
@ -1,5 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { IsNull, Not } from 'typeorm';
|
||||
|
||||
import {
|
||||
CreateOneResolverArgs,
|
||||
DeleteOneResolverArgs,
|
||||
@ -11,12 +13,12 @@ import {
|
||||
WorkflowQueryValidationException,
|
||||
WorkflowQueryValidationExceptionCode,
|
||||
} from 'src/modules/workflow/common/exceptions/workflow-query-validation.exception';
|
||||
import { assertWorkflowVersionIsDraft } from 'src/modules/workflow/common/utils/assert-workflow-version-is-draft.util';
|
||||
import { WorkflowCommonWorkspaceService } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';
|
||||
import {
|
||||
WorkflowVersionStatus,
|
||||
WorkflowVersionWorkspaceEntity,
|
||||
} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||
import { assertWorkflowVersionIsDraft } from 'src/modules/workflow/common/utils/assert-workflow-version-is-draft.util';
|
||||
import { WorkflowCommonWorkspaceService } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';
|
||||
|
||||
@Injectable()
|
||||
export class WorkflowVersionValidationWorkspaceService {
|
||||
@ -48,6 +50,8 @@ export class WorkflowVersionValidationWorkspaceService {
|
||||
where: {
|
||||
workflowId: payload.data.workflowId,
|
||||
status: WorkflowVersionStatus.DRAFT,
|
||||
// FIXME: soft-deleted rows selection will have to be improved globally
|
||||
deletedAt: IsNull(),
|
||||
},
|
||||
});
|
||||
|
||||
@ -84,5 +88,25 @@ export class WorkflowVersionValidationWorkspaceService {
|
||||
);
|
||||
|
||||
assertWorkflowVersionIsDraft(workflowVersion);
|
||||
|
||||
const workflowVersionRepository =
|
||||
await this.twentyORMManager.getRepository<WorkflowVersionWorkspaceEntity>(
|
||||
'workflowVersion',
|
||||
);
|
||||
|
||||
const otherWorkflowVersionsExist = await workflowVersionRepository.exists({
|
||||
where: {
|
||||
workflowId: workflowVersion.workflowId,
|
||||
deletedAt: IsNull(),
|
||||
id: Not(workflowVersion.id),
|
||||
},
|
||||
});
|
||||
|
||||
if (!otherWorkflowVersionsExist) {
|
||||
throw new WorkflowQueryValidationException(
|
||||
'The initial version of a workflow can not be deleted',
|
||||
WorkflowQueryValidationExceptionCode.FORBIDDEN,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,6 +203,10 @@ export class WorkflowTriggerWorkspaceService {
|
||||
workflowVersionNullable,
|
||||
);
|
||||
|
||||
if (workflowVersion.status !== WorkflowVersionStatus.ACTIVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.setDeactivatedVersionStatus(
|
||||
workflowVersion,
|
||||
workflowVersionRepository,
|
||||
|
||||
Reference in New Issue
Block a user