Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Account for owner when filtering by project ID in GET /workflows in Public API #10379

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ export = {
);
where.id = In(workflowIds);
}

if (projectId) {
const workflows = await Container.get(SharedWorkflowRepository).findAllWorkflowsForUser(
req.user,
['workflow:read'],
);

const workflowIds = workflows
.filter((workflow) => workflow.projectId === projectId)
.map((workflow) => workflow.id);

where.id = In(workflowIds);
}
} else {
const options: { workflowIds?: string[] } = {};

Expand Down
26 changes: 24 additions & 2 deletions packages/cli/test/integration/publicApi/workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,30 @@ describe('GET /workflows', () => {
}
});

test('should return all user-accessible workflows filtered by `projectId`', async () => {
license.setQuota('quota:maxTeamProjects', 2);
test('for owner, should return all workflows filtered by `projectId`', async () => {
license.setQuota('quota:maxTeamProjects', -1);
const firstProject = await Container.get(ProjectService).createTeamProject('First', owner);
const secondProject = await Container.get(ProjectService).createTeamProject('Second', member);

await Promise.all([
createWorkflow({ name: 'First workflow' }, firstProject),
createWorkflow({ name: 'Second workflow' }, secondProject),
]);

const firstResponse = await authOwnerAgent.get(`/workflows?projectId=${firstProject.id}`);
const secondResponse = await authOwnerAgent.get(`/workflows?projectId=${secondProject.id}`);

expect(firstResponse.statusCode).toBe(200);
expect(firstResponse.body.data.length).toBe(1);
expect(firstResponse.body.data[0].name).toBe('First workflow');

expect(secondResponse.statusCode).toBe(200);
expect(secondResponse.body.data.length).toBe(1);
expect(secondResponse.body.data[0].name).toBe('Second workflow');
});

test('for member, should return all member-accessible workflows filtered by `projectId`', async () => {
license.setQuota('quota:maxTeamProjects', -1);
const otherProject = await Container.get(ProjectService).createTeamProject(
'Other project',
member,
Expand Down
Loading