feat(core): Add onlySharedWithMe filter to GET /workflows endpoint (no-changelog) (#14853)

This commit is contained in:
Ricardo Espinoza
2025-04-28 14:04:33 -04:00
committed by GitHub
parent eb465763cf
commit d2178a13b1
5 changed files with 74 additions and 1 deletions

View File

@@ -67,6 +67,23 @@ export class WorkflowSharingService {
return sharedWorkflows.map(({ workflowId }) => workflowId); return sharedWorkflows.map(({ workflowId }) => workflowId);
} }
async getSharedWithMeIds(user: User) {
const sharedWithMeWorkflows = await this.sharedWorkflowRepository.find({
select: ['workflowId'],
where: {
role: 'workflow:editor',
project: {
projectRelations: {
userId: user.id,
role: 'project:personalOwner',
},
},
},
});
return sharedWithMeWorkflows.map(({ workflowId }) => workflowId);
}
async getSharedWorkflowScopes( async getSharedWorkflowScopes(
workflowIds: string[], workflowIds: string[],
user: User, user: User,

View File

@@ -45,7 +45,11 @@ export declare namespace WorkflowRequest {
{}, {},
{}, {},
{}, {},
ListQuery.Params & { includeScopes?: string; includeFolders?: string } ListQuery.Params & {
includeScopes?: string;
includeFolders?: string;
onlySharedWithMe?: string;
}
> & { > & {
listQueryOptions: ListQuery.Options; listQueryOptions: ListQuery.Options;
}; };

View File

@@ -69,6 +69,7 @@ export class WorkflowService {
options?: ListQuery.Options, options?: ListQuery.Options,
includeScopes?: boolean, includeScopes?: boolean,
includeFolders?: boolean, includeFolders?: boolean,
onlySharedWithMe?: boolean,
) { ) {
let count; let count;
let workflows; let workflows;
@@ -86,6 +87,8 @@ export class WorkflowService {
if (isPersonalProject) { if (isPersonalProject) {
sharedWorkflowIds = sharedWorkflowIds =
await this.workflowSharingService.getOwnedWorkflowsInPersonalProject(user); await this.workflowSharingService.getOwnedWorkflowsInPersonalProject(user);
} else if (onlySharedWithMe) {
sharedWorkflowIds = await this.workflowSharingService.getSharedWithMeIds(user);
} else { } else {
sharedWorkflowIds = await this.workflowSharingService.getSharedWorkflowIds(user, { sharedWorkflowIds = await this.workflowSharingService.getSharedWorkflowIds(user, {
scopes: ['workflow:read'], scopes: ['workflow:read'],

View File

@@ -228,6 +228,7 @@ export class WorkflowsController {
req.listQueryOptions, req.listQueryOptions,
!!req.query.includeScopes, !!req.query.includeScopes,
!!req.query.includeFolders, !!req.query.includeFolders,
!!req.query.onlySharedWithMe,
); );
res.json({ count, data }); res.json({ count, data });

View File

@@ -1313,6 +1313,54 @@ describe('GET /workflows', () => {
}); });
}); });
describe('GET /workflows?onlySharedWithMe=true', () => {
test('should return only workflows shared with me', async () => {
const memberPersonalProject = await projectRepository.getPersonalProjectForUserOrFail(
member.id,
);
const ownerPersonalProject = await projectRepository.getPersonalProjectForUserOrFail(owner.id);
await createWorkflow({ name: 'First' }, owner);
await createWorkflow({ name: 'Second' }, member);
const workflow3 = await createWorkflow({ name: 'Third' }, member);
await shareWorkflowWithUsers(workflow3, [owner]);
const response = await authOwnerAgent.get('/workflows').query({ onlySharedWithMe: true });
expect(200);
expect(response.body).toEqual({
count: 1,
data: arrayContaining([
objectContaining({
id: any(String),
name: 'Third',
active: any(Boolean),
createdAt: any(String),
updatedAt: any(String),
versionId: any(String),
parentFolder: null,
homeProject: {
id: memberPersonalProject.id,
name: member.createPersonalProjectName(),
icon: null,
type: memberPersonalProject.type,
},
sharedWithProjects: [
objectContaining({
id: any(String),
name: ownerPersonalProject.name,
icon: null,
type: ownerPersonalProject.type,
}),
],
}),
]),
});
});
});
describe('GET /workflows?includeFolders=true', () => { describe('GET /workflows?includeFolders=true', () => {
test('should return zero workflows and folders if none exist', async () => { test('should return zero workflows and folders if none exist', async () => {
const response = await authOwnerAgent.get('/workflows').query({ includeFolders: true }); const response = await authOwnerAgent.get('/workflows').query({ includeFolders: true });