mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(core): Add onlySharedWithMe filter to GET /workflows endpoint (no-changelog) (#14853)
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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'],
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|||||||
Reference in New Issue
Block a user