mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
feat: check for cred when updating workflow and remove credential_usage table (#4350) (no-changelog)
* feat: check for cred when updating workflow and remove credential_usage table
This commit is contained in:
@@ -11,7 +11,6 @@ import { SharedWorkflow } from '../databases/entities/SharedWorkflow';
|
||||
import { LoggerProxy } from 'n8n-workflow';
|
||||
import * as TagHelpers from '../TagHelpers';
|
||||
import { EECredentialsService as EECredentials } from '../credentials/credentials.service.ee';
|
||||
import { CredentialUsage } from '../databases/entities/CredentialUsage';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
export const EEWorkflowController = express.Router();
|
||||
@@ -155,29 +154,6 @@ EEWorkflowController.post(
|
||||
});
|
||||
|
||||
await transactionManager.save<SharedWorkflow>(newSharedWorkflow);
|
||||
|
||||
const credentialUsage: CredentialUsage[] = [];
|
||||
newWorkflow.nodes.forEach((node) => {
|
||||
if (!node.credentials) {
|
||||
return;
|
||||
}
|
||||
Object.keys(node.credentials).forEach((credentialType) => {
|
||||
const credentialId = node.credentials?.[credentialType].id;
|
||||
if (credentialId) {
|
||||
const newCredentialusage = new CredentialUsage();
|
||||
Object.assign(newCredentialusage, {
|
||||
credentialId,
|
||||
nodeId: node.id,
|
||||
workflowId: savedWorkflow?.id,
|
||||
});
|
||||
credentialUsage.push(newCredentialusage);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (credentialUsage.length) {
|
||||
await transactionManager.save<CredentialUsage>(credentialUsage);
|
||||
}
|
||||
});
|
||||
|
||||
if (!savedWorkflow) {
|
||||
@@ -202,3 +178,28 @@ EEWorkflowController.post(
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
EEWorkflowController.patch(
|
||||
'/:id(\\d+)',
|
||||
ResponseHelper.send(async (req: WorkflowRequest.Update) => {
|
||||
const { id: workflowId } = req.params;
|
||||
|
||||
const updateData = new WorkflowEntity();
|
||||
const { tags, ...rest } = req.body;
|
||||
Object.assign(updateData, rest);
|
||||
|
||||
const updatedWorkflow = await EEWorkflows.updateWorkflow(
|
||||
req.user,
|
||||
updateData,
|
||||
workflowId,
|
||||
tags,
|
||||
);
|
||||
|
||||
const { id, ...remainder } = updatedWorkflow;
|
||||
|
||||
return {
|
||||
id: id.toString(),
|
||||
...remainder,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user