fix(core): Fix workflow activation with history and workflow history for EE (no-changelog) (#7508)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
@@ -27,7 +27,6 @@ import {
|
||||
import { WorkflowsService } from '@/workflows/workflows.services';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { RoleService } from '@/services/role.service';
|
||||
import { isWorkflowHistoryLicensed } from '@/workflows/workflowHistory/workflowHistoryHelper.ee';
|
||||
import { WorkflowHistoryService } from '@/workflows/workflowHistory/workflowHistory.service.ee';
|
||||
|
||||
export = {
|
||||
@@ -47,13 +46,11 @@ export = {
|
||||
|
||||
const createdWorkflow = await createWorkflow(workflow, req.user, role);
|
||||
|
||||
if (isWorkflowHistoryLicensed()) {
|
||||
await Container.get(WorkflowHistoryService).saveVersion(
|
||||
req.user,
|
||||
createdWorkflow,
|
||||
createdWorkflow.id,
|
||||
);
|
||||
}
|
||||
await Container.get(WorkflowHistoryService).saveVersion(
|
||||
req.user,
|
||||
createdWorkflow,
|
||||
createdWorkflow.id,
|
||||
);
|
||||
|
||||
await Container.get(ExternalHooks).run('workflow.afterCreate', [createdWorkflow]);
|
||||
void Container.get(InternalHooks).onWorkflowCreated(req.user, createdWorkflow, true);
|
||||
@@ -202,7 +199,7 @@ export = {
|
||||
|
||||
const updatedWorkflow = await getWorkflowById(sharedWorkflow.workflowId);
|
||||
|
||||
if (isWorkflowHistoryLicensed() && updatedWorkflow) {
|
||||
if (updatedWorkflow) {
|
||||
await Container.get(WorkflowHistoryService).saveVersion(
|
||||
req.user,
|
||||
updatedWorkflow,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { SharedWorkflowRepository } from '@/databases/repositories';
|
||||
import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository';
|
||||
import { Service } from 'typedi';
|
||||
import { isWorkflowHistoryEnabled } from './workflowHistoryHelper.ee';
|
||||
import { getLogger } from '@/Logger';
|
||||
|
||||
export class SharedWorkflowNotFoundError extends Error {}
|
||||
export class HistoryVersionNotFoundError extends Error {}
|
||||
@@ -66,13 +67,20 @@ export class WorkflowHistoryService {
|
||||
|
||||
async saveVersion(user: User, workflow: WorkflowEntity, workflowId: string) {
|
||||
if (isWorkflowHistoryEnabled()) {
|
||||
await this.workflowHistoryRepository.insert({
|
||||
authors: user.firstName + ' ' + user.lastName,
|
||||
connections: workflow.connections,
|
||||
nodes: workflow.nodes,
|
||||
versionId: workflow.versionId,
|
||||
workflowId,
|
||||
});
|
||||
try {
|
||||
await this.workflowHistoryRepository.insert({
|
||||
authors: user.firstName + ' ' + user.lastName,
|
||||
connections: workflow.connections,
|
||||
nodes: workflow.nodes,
|
||||
versionId: workflow.versionId,
|
||||
workflowId,
|
||||
});
|
||||
} catch (e) {
|
||||
getLogger().error(
|
||||
`Failed to save workflow history version for workflow ${workflowId}`,
|
||||
e as Error,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import { RoleService } from '@/services/role.service';
|
||||
import * as utils from '@/utils';
|
||||
import { listQueryMiddleware } from '@/middlewares';
|
||||
import { TagService } from '@/services/tag.service';
|
||||
import { WorkflowHistoryService } from './workflowHistory/workflowHistory.service.ee';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
export const EEWorkflowController = express.Router();
|
||||
@@ -186,6 +187,12 @@ EEWorkflowController.post(
|
||||
);
|
||||
}
|
||||
|
||||
await Container.get(WorkflowHistoryService).saveVersion(
|
||||
req.user,
|
||||
savedWorkflow,
|
||||
savedWorkflow.id,
|
||||
);
|
||||
|
||||
if (tagIds && !config.getEnv('workflowTagsDisabled') && savedWorkflow.tags) {
|
||||
savedWorkflow.tags = Container.get(TagService).sortByRequestOrder(savedWorkflow.tags, {
|
||||
requestOrder: tagIds,
|
||||
|
||||
@@ -26,7 +26,6 @@ import { RoleService } from '@/services/role.service';
|
||||
import * as utils from '@/utils';
|
||||
import { listQueryMiddleware } from '@/middlewares';
|
||||
import { TagService } from '@/services/tag.service';
|
||||
import { isWorkflowHistoryLicensed } from './workflowHistory/workflowHistoryHelper.ee';
|
||||
import { WorkflowHistoryService } from './workflowHistory/workflowHistory.service.ee';
|
||||
|
||||
export const workflowsController = express.Router();
|
||||
@@ -101,13 +100,11 @@ workflowsController.post(
|
||||
throw new ResponseHelper.InternalServerError('Failed to save workflow');
|
||||
}
|
||||
|
||||
if (isWorkflowHistoryLicensed()) {
|
||||
await Container.get(WorkflowHistoryService).saveVersion(
|
||||
req.user,
|
||||
savedWorkflow,
|
||||
savedWorkflow.id,
|
||||
);
|
||||
}
|
||||
await Container.get(WorkflowHistoryService).saveVersion(
|
||||
req.user,
|
||||
savedWorkflow,
|
||||
savedWorkflow.id,
|
||||
);
|
||||
|
||||
if (tagIds && !config.getEnv('workflowTagsDisabled') && savedWorkflow.tags) {
|
||||
savedWorkflow.tags = Container.get(TagService).sortByRequestOrder(savedWorkflow.tags, {
|
||||
|
||||
@@ -33,7 +33,6 @@ import { WorkflowRepository } from '@/databases/repositories';
|
||||
import { RoleService } from '@/services/role.service';
|
||||
import { OwnershipService } from '@/services/ownership.service';
|
||||
import { isStringArray, isWorkflowIdValid } from '@/utils';
|
||||
import { isWorkflowHistoryLicensed } from './workflowHistory/workflowHistoryHelper.ee';
|
||||
import { WorkflowHistoryService } from './workflowHistory/workflowHistory.service.ee';
|
||||
import { BinaryDataService } from 'n8n-core';
|
||||
|
||||
@@ -222,13 +221,19 @@ export class WorkflowsService {
|
||||
);
|
||||
}
|
||||
|
||||
let onlyActiveUpdate = false;
|
||||
|
||||
if (
|
||||
Object.keys(workflow).length === 3 &&
|
||||
workflow.id !== undefined &&
|
||||
workflow.versionId !== undefined &&
|
||||
workflow.active !== undefined
|
||||
(Object.keys(workflow).length === 3 &&
|
||||
workflow.id !== undefined &&
|
||||
workflow.versionId !== undefined &&
|
||||
workflow.active !== undefined) ||
|
||||
(Object.keys(workflow).length === 2 &&
|
||||
workflow.versionId !== undefined &&
|
||||
workflow.active !== undefined)
|
||||
) {
|
||||
// we're just updating the active status of the workflow, don't update the versionId
|
||||
onlyActiveUpdate = true;
|
||||
} else {
|
||||
// Update the workflow's version
|
||||
workflow.versionId = uuid();
|
||||
@@ -301,7 +306,7 @@ export class WorkflowsService {
|
||||
);
|
||||
}
|
||||
|
||||
if (isWorkflowHistoryLicensed() && workflow.versionId !== shared.workflow.versionId) {
|
||||
if (!onlyActiveUpdate && workflow.versionId !== shared.workflow.versionId) {
|
||||
await Container.get(WorkflowHistoryService).saveVersion(user, workflow, workflowId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user