mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-09-26 19:51:42 +02:00
fix(core): Return homeProject when filtering workflows by project id (#12077)
This commit is contained in:
@@ -211,4 +211,13 @@ export class SharedWorkflowRepository extends Repository<SharedWorkflow> {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getAllRelationsForWorkflows(workflowIds: string[]) {
|
||||
return await this.find({
|
||||
where: {
|
||||
workflowId: In(workflowIds),
|
||||
},
|
||||
relations: ['project'],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,8 @@ export class WorkflowRepository extends Repository<WorkflowEntity> {
|
||||
.execute();
|
||||
}
|
||||
|
||||
async getMany(sharedWorkflowIds: string[], options?: ListQuery.Options) {
|
||||
async getMany(sharedWorkflowIds: string[], originalOptions: ListQuery.Options = {}) {
|
||||
const options = structuredClone(originalOptions);
|
||||
if (sharedWorkflowIds.length === 0) return { workflows: [], count: 0 };
|
||||
|
||||
if (typeof options?.filter?.projectId === 'string' && options.filter.projectId !== '') {
|
||||
|
||||
@@ -66,6 +66,20 @@ export class WorkflowService {
|
||||
let { workflows, count } = await this.workflowRepository.getMany(sharedWorkflowIds, options);
|
||||
|
||||
if (hasSharing(workflows)) {
|
||||
// Since we're filtering using project ID as part of the relation,
|
||||
// we end up filtering out all the other relations, meaning that if
|
||||
// it's shared to a project, it won't be able to find the home project.
|
||||
// To solve this, we have to get all the relation now, even though
|
||||
// we're deleting them later.
|
||||
if (typeof options?.filter?.projectId === 'string' && options.filter.projectId !== '') {
|
||||
const relations = await this.sharedWorkflowRepository.getAllRelationsForWorkflows(
|
||||
workflows.map((c) => c.id),
|
||||
);
|
||||
workflows.forEach((c) => {
|
||||
c.shared = relations.filter((r) => r.workflowId === c.id);
|
||||
});
|
||||
}
|
||||
|
||||
workflows = workflows.map((w) => this.ownershipService.addOwnedByAndSharedWith(w));
|
||||
}
|
||||
|
||||
@@ -75,8 +89,8 @@ export class WorkflowService {
|
||||
}
|
||||
|
||||
workflows.forEach((w) => {
|
||||
// @ts-expect-error: This is to emulate the old behaviour of removing the shared
|
||||
// field as part of `addOwnedByAndSharedWith`. We need this field in `addScopes`
|
||||
// This is to emulate the old behaviour of removing the shared field as
|
||||
// part of `addOwnedByAndSharedWith`. We need this field in `addScopes`
|
||||
// though. So to avoid leaking the information we just delete it.
|
||||
delete w.shared;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user