fix(core): Don't create multiple owners when importing credentials or workflows (#9112)

This commit is contained in:
Danny Martini
2024-04-12 17:25:59 +02:00
committed by GitHub
parent 5433004d77
commit 3eb5be5f5a
12 changed files with 826 additions and 184 deletions

View File

@@ -19,12 +19,7 @@ export async function createManyWorkflows(
return await Promise.all(workflowRequests);
}
/**
* Store a workflow in the DB (without a trigger) and optionally assign it to a user.
* @param attributes workflow attributes
* @param user user to assign the workflow to
*/
export async function createWorkflow(attributes: Partial<WorkflowEntity> = {}, user?: User) {
export function newWorkflow(attributes: Partial<WorkflowEntity> = {}): WorkflowEntity {
const { active, name, nodes, connections, versionId } = attributes;
const workflowEntity = Container.get(WorkflowRepository).create({
@@ -45,7 +40,16 @@ export async function createWorkflow(attributes: Partial<WorkflowEntity> = {}, u
...attributes,
});
const workflow = await Container.get(WorkflowRepository).save(workflowEntity);
return workflowEntity;
}
/**
* Store a workflow in the DB (without a trigger) and optionally assign it to a user.
* @param attributes workflow attributes
* @param user user to assign the workflow to
*/
export async function createWorkflow(attributes: Partial<WorkflowEntity> = {}, user?: User) {
const workflow = await Container.get(WorkflowRepository).save(newWorkflow(attributes));
if (user) {
await Container.get(SharedWorkflowRepository).save({
@@ -121,5 +125,9 @@ export async function getAllWorkflows() {
return await Container.get(WorkflowRepository).find();
}
export async function getAllSharedWorkflows() {
return await Container.get(SharedWorkflowRepository).find();
}
export const getWorkflowById = async (id: string) =>
await Container.get(WorkflowRepository).findOneBy({ id });