feat: Return scopes on executions (no-changelog) (#10310)

This commit is contained in:
Val
2024-08-07 10:19:09 +01:00
committed by GitHub
parent 6d8323fade
commit fa17391dbd
10 changed files with 94 additions and 4 deletions

View File

@@ -8,12 +8,14 @@ import { RoleService } from '@/services/role.service';
import type { Scope } from '@n8n/permissions';
import type { ProjectRole } from '@/databases/entities/ProjectRelation';
import type { WorkflowSharingRole } from '@/databases/entities/SharedWorkflow';
import { ProjectRelationRepository } from '@/databases/repositories/projectRelation.repository';
@Service()
export class WorkflowSharingService {
constructor(
private readonly sharedWorkflowRepository: SharedWorkflowRepository,
private readonly roleService: RoleService,
private readonly projectRelationRepository: ProjectRelationRepository,
) {}
/**
@@ -64,4 +66,28 @@ export class WorkflowSharingService {
return sharedWorkflows.map(({ workflowId }) => workflowId);
}
async getSharedWorkflowScopes(
workflowIds: string[],
user: User,
): Promise<Array<[string, Scope[]]>> {
const projectRelations = await this.projectRelationRepository.findAllByUser(user.id);
const sharedWorkflows =
await this.sharedWorkflowRepository.getRelationsByWorkflowIdsAndProjectIds(
workflowIds,
projectRelations.map((p) => p.projectId),
);
return workflowIds.map((workflowId) => {
return [
workflowId,
this.roleService.combineResourceScopes(
'workflow',
user,
sharedWorkflows.filter((s) => s.workflowId === workflowId),
projectRelations,
),
];
});
}
}