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

feat(API): Exclude pinned data from workflows #12261

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
2 changes: 1 addition & 1 deletion packages/cli/src/databases/entities/workflow-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class WorkflowEntity extends WithTimestampsAndStringId implements IWorkfl
nullable: true,
transformer: sqlite.jsonColumn,
})
pinData: ISimplifiedPinData;
pinData?: ISimplifiedPinData;

@Column({ length: 36 })
versionId: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/public-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ export declare namespace WorkflowRequest {
active: boolean;
name?: string;
projectId?: string;
excludePinnedData?: boolean;
}
>;

type Create = AuthenticatedRequest<{}, {}, WorkflowEntity, {}>;
type Get = AuthenticatedRequest<{ id: string }, {}, {}, {}>;
type Get = AuthenticatedRequest<{ id: string }, {}, {}, { excludePinnedData?: boolean }>;
type Delete = Get;
type Update = AuthenticatedRequest<{ id: string }, {}, WorkflowEntity, {}>;
type Activate = Get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ get:
summary: Retrieves a workflow
description: Retrieves a workflow.
parameters:
- name: excludePinnedData
in: query
required: false
description: Set this to avoid retrieving pinned data
schema:
type: boolean
example: true
- $ref: '../schemas/parameters/workflowId.yml'
responses:
'200':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ get:
schema:
type: string
example: VmwOO9HeTEj20kxM
- name: excludePinnedData
in: query
required: false
description: Set this to avoid retrieving pinned data
schema:
type: boolean
example: true
- $ref: '../../../../shared/spec/parameters/limit.yml'
- $ref: '../../../../shared/spec/parameters/cursor.yml'
responses:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export = {
projectScope('workflow:read', 'workflow'),
async (req: WorkflowRequest.Get, res: express.Response): Promise<express.Response> => {
const { id } = req.params;
const { excludePinnedData = false } = req.query;

const workflow = await Container.get(SharedWorkflowRepository).findWorkflowForUser(
id,
Expand All @@ -120,6 +121,10 @@ export = {
return res.status(404).json({ message: 'Not Found' });
}

if (excludePinnedData) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't have to fix this here, but maybe we should create a tech-debt ticket to remove this at the query level, instead of using delete on the returned data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a tech-debt ticket: PAY-2385.

delete workflow.pinData;
}

Container.get(EventService).emit('user-retrieved-workflow', {
userId: req.user.id,
publicApi: true,
Expand All @@ -131,7 +136,15 @@ export = {
getWorkflows: [
validCursor,
async (req: WorkflowRequest.GetAll, res: express.Response): Promise<express.Response> => {
const { offset = 0, limit = 100, active, tags, name, projectId } = req.query;
const {
offset = 0,
limit = 100,
excludePinnedData = false,
active,
tags,
name,
projectId,
} = req.query;

const where: FindOptionsWhere<WorkflowEntity> = {
...(active !== undefined && { active }),
Expand Down Expand Up @@ -199,6 +212,12 @@ export = {
...(!config.getEnv('workflowTagsDisabled') && { relations: ['tags'] }),
});

if (excludePinnedData) {
workflows.forEach((workflow) => {
delete workflow.pinData;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

});
}

Container.get(EventService).emit('user-retrieved-all-workflows', {
userId: req.user.id,
publicApi: true,
Expand Down
61 changes: 61 additions & 0 deletions packages/cli/test/integration/public-api/workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,47 @@ describe('GET /workflows', () => {
expect(updatedAt).toBeDefined();
}
});

test('should return all owned workflows without pinned data', async () => {
await Promise.all([
createWorkflow(
{
pinData: {
Webhook1: [{ json: { first: 'first' } }],
},
},
member,
),
createWorkflow(
{
pinData: {
Webhook2: [{ json: { second: 'second' } }],
},
},
member,
),
createWorkflow(
{
pinData: {
Webhook3: [{ json: { third: 'third' } }],
},
},
member,
),
]);

const response = await authMemberAgent.get('/workflows?excludePinnedData=true');

expect(response.statusCode).toBe(200);
expect(response.body.data.length).toBe(3);
expect(response.body.nextCursor).toBeNull();

for (const workflow of response.body.data) {
const { pinData } = workflow;

expect(pinData).not.toBeDefined();
}
});
});

describe('GET /workflows/:id', () => {
Expand Down Expand Up @@ -444,6 +485,26 @@ describe('GET /workflows/:id', () => {
expect(createdAt).toEqual(workflow.createdAt.toISOString());
expect(updatedAt).toEqual(workflow.updatedAt.toISOString());
});

test('should retrieve workflow without pinned data', async () => {
// create and assign workflow to owner
const workflow = await createWorkflow(
{
pinData: {
Webhook1: [{ json: { first: 'first' } }],
},
},
member,
);

const response = await authMemberAgent.get(`/workflows/${workflow.id}?excludePinnedData=true`);

expect(response.statusCode).toBe(200);

const { pinData } = response.body;

expect(pinData).not.toBeDefined();
});
});

describe('DELETE /workflows/:id', () => {
Expand Down
Loading