feat(API): Add an isArchived filter to the public workflow list (#46037)

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Konstantin Tieber <46342664+konstantintieber@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-12-03 23:45:57 +00:00
1 parent 02b8b533a8
commit 1b83610fea
8 files changed
+114 -2

No files matched your search

@@ -10,9 +10,26 @@ describe('ListWorkflowsQueryDto', () => {
expect(result.data.limit).toBe(100);
expect(result.data.excludePinnedData).toBe(false);
expect(result.data.includeParentFolder).toBe(false);
expect(result.data.isArchived).toBeUndefined();
}
});
test('parses isArchived from a query string', () => {
const archived = ListWorkflowsQueryDto.safeParse({ isArchived: 'true' });
const notArchived = ListWorkflowsQueryDto.safeParse({ isArchived: 'false' });
const invalid = ListWorkflowsQueryDto.safeParse({ isArchived: 'yes' });
expect(archived.success).toBe(true);
if (archived.success) {
expect(archived.data.isArchived).toBe(true);
}
expect(notArchived.success).toBe(true);
if (notArchived.success) {
expect(notArchived.data.isArchived).toBe(false);
}
expect(invalid.success).toBe(false);
});
test('parses includeParentFolder from a query string', () => {
const result = ListWorkflowsQueryDto.safeParse({ includeParentFolder: 'true' });
@@ -2,7 +2,7 @@ import '../../openapi-extend';
import { z } from 'zod';
import { includeParentFolderOpenApi } from './workflow-public.openapi';
import { includeParentFolderOpenApi, isArchivedFilterOpenApi } from './workflow-public.openapi';
import { booleanFromString } from '../../schemas/boolean-from-string';
import { Z } from '../../zod-class';
import { publicApiPaginationSchema } from '../pagination/pagination.dto';
@@ -11,6 +11,7 @@ export class ListWorkflowsQueryDto extends Z.class({
...publicApiPaginationSchema,
cursor: z.string().optional(),
active: booleanFromString.optional(),
isArchived: booleanFromString.optional().openapi(isArchivedFilterOpenApi),
tags: z.string().optional(),
name: z.string().optional(),
projectId: z.string().optional(),
@@ -333,6 +333,11 @@ export const includeParentFolderOpenApi: ZodOpenAPIMetadata = {
'Whether to add `parentFolder` to each workflow. `parentFolder` holds the ID of the folder that contains the workflow, or is `null` at the project root.',
};
export const isArchivedFilterOpenApi: ZodOpenAPIMetadata = {
description:
'Filter by archived state. Leave this parameter unset to return archived and non-archived workflows.',
};
/** `ZodOpenAPIMetadata` is a union, which will not assign into a nested `properties` slot. */
function nestingDescriptor(schema: Record<string, unknown>): ZodOpenAPIMetadata {
return schema;
@@ -270,6 +270,7 @@ export class WorkflowsPublicController {
filters: {
name: query.name,
active: query.active,
isArchived: query.isArchived,
tagNames: query.tags ? parseTagNames(query.tags) : undefined,
projectId: query.projectId,
},
@@ -19,6 +19,15 @@ parameters:
required: false
name: active
in: query
- schema:
type: string
enum:
- 'true'
- 'false'
description: Filter by archived state. Leave this parameter unset to return archived and non-archived workflows.
required: false
name: isArchived
in: query
- schema:
type: string
required: false
@@ -304,6 +304,21 @@ describe('WorkflowFinderService', () => {
);
});
it('passes isArchived through as a filter', async () => {
const { service, workflowRepository } = setup();
await service.findWorkflowsForUser(user, ['workflow:read'], {
filters: { isArchived: false },
});
expect(workflowRepository.getManyAndCountWithSharingSubquery).toHaveBeenCalledWith(
user,
expect.anything(),
expect.objectContaining({ filter: { isArchived: false } }),
expect.anything(),
);
});
it('passes projectId through as a filter', async () => {
const { service, workflowRepository, folderRepository } = setup();
@@ -25,6 +25,7 @@ export type FindWorkflowsForUserOptions = {
filters?: {
name?: string;
active?: boolean;
isArchived?: boolean;
tagNames?: string[];
folderId?: string;
projectId?: string;
@@ -449,7 +450,7 @@ export class WorkflowFinderService {
includeActiveVersion = false,
includeParentFolder = false,
} = options;
const { name, active, tagNames, folderId, projectId } = filters;
const { name, active, isArchived, tagNames, folderId, projectId } = filters;
const [projectRoles, workflowRoles] = await Promise.all([
this.roleService.rolesWithScope('project', scopes),
@@ -490,6 +491,7 @@ export class WorkflowFinderService {
filter: {
...(name !== undefined && { name }),
...(active !== undefined && { active }),
...(isArchived !== undefined && { isArchived }),
...(tagNames?.length && { tags: tagNames }),
...(projectId && { projectId }),
...(parentFolderIds && { parentFolderIds }),
@@ -378,6 +378,68 @@ describe('GET /workflows', () => {
expect(response.body.nextCursor).toBeNull();
});
test('should filter workflows by isArchived', async () => {
const [archived, active] = await Promise.all([
createWorkflowWithHistory({ isArchived: true, name: 'Archived workflow' }, member),
createWorkflowWithHistory({ name: 'Active workflow' }, member),
]);
const included = await authMemberAgent.get('/workflows');
expect(included.statusCode).toBe(200);
expect(included.body.data.map((workflow: { id: string }) => workflow.id).sort()).toEqual(
[archived.id, active.id].sort(),
);
const onlyArchived = await authMemberAgent.get('/workflows?isArchived=true');
expect(onlyArchived.statusCode).toBe(200);
expect(onlyArchived.body.data).toHaveLength(1);
expect(onlyArchived.body.data[0].id).toBe(archived.id);
expect(onlyArchived.body.data[0].isArchived).toBe(true);
const onlyActive = await authMemberAgent.get('/workflows?isArchived=false');
expect(onlyActive.statusCode).toBe(200);
expect(onlyActive.body.data).toHaveLength(1);
expect(onlyActive.body.data[0].id).toBe(active.id);
expect(onlyActive.body.data[0].isArchived).toBe(false);
expect(onlyActive.body.nextCursor).toBeNull();
});
test('should keep full pages when isArchived filters workflows before pagination', async () => {
const archived = await createWorkflowWithHistory({ isArchived: true }, member);
await Promise.all([
createWorkflowWithHistory({}, member),
createWorkflowWithHistory({}, member),
]);
const firstPage = await authMemberAgent.get('/workflows?isArchived=false&limit=1');
expect(firstPage.statusCode).toBe(200);
expect(firstPage.body.data).toHaveLength(1);
expect(firstPage.body.data[0].id).not.toBe(archived.id);
expect(firstPage.body.data[0].isArchived).toBe(false);
expect(firstPage.body.nextCursor).not.toBeNull();
const secondPage = await authMemberAgent.get(
`/workflows?isArchived=false&limit=1&cursor=${firstPage.body.nextCursor}`,
);
expect(secondPage.statusCode).toBe(200);
expect(secondPage.body.data).toHaveLength(1);
expect(secondPage.body.data[0].id).not.toBe(firstPage.body.data[0].id);
expect(secondPage.body.data[0].id).not.toBe(archived.id);
expect(secondPage.body.data[0].isArchived).toBe(false);
expect(secondPage.body.nextCursor).toBeNull();
});
test('should reject an invalid isArchived value', async () => {
const response = await authMemberAgent.get('/workflows?isArchived=yes');
expect(response.statusCode).toBe(400);
});
test('should return all owned workflows filtered by tag', async () => {
const tag = await createTag({});