mirror of
https://github.com/n8n-io/n8n.git
synced 2024-09-11 13:15:28 +03:00
fix: Get workflow not returning home project and shared projects (no-changelog) (#9815)
This commit is contained in:
parent
e1e8a75763
commit
aeeced4d97
@ -13,7 +13,6 @@ import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
|||||||
import { NotFoundError } from '@/errors/response-errors/not-found.error';
|
import { NotFoundError } from '@/errors/response-errors/not-found.error';
|
||||||
import { Logger } from '@/Logger';
|
import { Logger } from '@/Logger';
|
||||||
import type {
|
import type {
|
||||||
CredentialUsedByWorkflow,
|
|
||||||
WorkflowWithSharingsAndCredentials,
|
WorkflowWithSharingsAndCredentials,
|
||||||
WorkflowWithSharingsMetaDataAndCredentials,
|
WorkflowWithSharingsMetaDataAndCredentials,
|
||||||
} from './workflows.types';
|
} from './workflows.types';
|
||||||
@ -101,16 +100,15 @@ export class EnterpriseWorkflowService {
|
|||||||
const userCredentialIds = userCredentials.map((credential) => credential.id);
|
const userCredentialIds = userCredentials.map((credential) => credential.id);
|
||||||
workflowCredentials.forEach((credential) => {
|
workflowCredentials.forEach((credential) => {
|
||||||
const credentialId = credential.id;
|
const credentialId = credential.id;
|
||||||
const workflowCredential: CredentialUsedByWorkflow = {
|
const filledCred = this.ownershipService.addOwnedByAndSharedWith(credential);
|
||||||
|
workflow.usedCredentials?.push({
|
||||||
id: credentialId,
|
id: credentialId,
|
||||||
name: credential.name,
|
name: credential.name,
|
||||||
type: credential.type,
|
type: credential.type,
|
||||||
currentUserHasAccess: userCredentialIds.includes(credentialId),
|
currentUserHasAccess: userCredentialIds.includes(credentialId),
|
||||||
sharedWith: [],
|
homeProject: filledCred.homeProject,
|
||||||
ownedBy: null,
|
sharedWithProjects: filledCred.sharedWithProjects,
|
||||||
};
|
});
|
||||||
credential = this.ownershipService.addOwnedByAndSharedWith(credential);
|
|
||||||
workflow.usedCredentials?.push(workflowCredential);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import type { IUser } from 'n8n-workflow';
|
|
||||||
import type { SharedWorkflow } from '@db/entities/SharedWorkflow';
|
import type { SharedWorkflow } from '@db/entities/SharedWorkflow';
|
||||||
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||||
import type { SlimProject } from '@/requests';
|
import type { SlimProject } from '@/requests';
|
||||||
@ -21,6 +20,6 @@ export interface CredentialUsedByWorkflow {
|
|||||||
name: string;
|
name: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
currentUserHasAccess: boolean;
|
currentUserHasAccess: boolean;
|
||||||
ownedBy?: IUser | null;
|
homeProject: SlimProject | null;
|
||||||
sharedWith?: IUser[];
|
sharedWithProjects: SlimProject[];
|
||||||
}
|
}
|
||||||
|
@ -527,6 +527,35 @@ describe('GET /workflows/:workflowId', () => {
|
|||||||
]);
|
]);
|
||||||
expect(member2Workflow.sharedWithProjects).toHaveLength(1);
|
expect(member2Workflow.sharedWithProjects).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should return workflow credentials home project and shared with projects', async () => {
|
||||||
|
const savedCredential = await saveCredential(randomCredentialPayload(), { user: member });
|
||||||
|
// Both users have access to the credential (none is owner)
|
||||||
|
await shareCredentialWithUsers(savedCredential, [anotherMember]);
|
||||||
|
|
||||||
|
const workflowPayload = makeWorkflow({
|
||||||
|
withPinData: false,
|
||||||
|
withCredential: { id: savedCredential.id, name: savedCredential.name },
|
||||||
|
});
|
||||||
|
const workflow = await createWorkflow(workflowPayload, member);
|
||||||
|
await shareWorkflowWithUsers(workflow, [anotherMember]);
|
||||||
|
|
||||||
|
const responseMember1 = await authMemberAgent.get(`/workflows/${workflow.id}`).expect(200);
|
||||||
|
const member1Workflow: WorkflowWithSharingsMetaDataAndCredentials = responseMember1.body.data;
|
||||||
|
|
||||||
|
expect(member1Workflow.usedCredentials).toMatchObject([
|
||||||
|
{
|
||||||
|
id: savedCredential.id,
|
||||||
|
name: savedCredential.name,
|
||||||
|
currentUserHasAccess: true,
|
||||||
|
homeProject: {
|
||||||
|
id: memberPersonalProject.id,
|
||||||
|
},
|
||||||
|
sharedWithProjects: [{ id: anotherMemberPersonalProject.id }],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
expect(member1Workflow.sharedWithProjects).toHaveLength(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('POST /workflows', () => {
|
describe('POST /workflows', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user