fix(core): Remove unnecessary info from GET /workflows response (#5311)

* fix(core): Remove unnecessary info from `GET /workflows` response

* fix(core): Remove unnecessary info from `GET /workflows` response

* fix(core): Remove credentials from `GET /workflows` response

* fix(core): Update unit tests for `GET /workflows` response

* fix(core): Remove `usedCredentials` from `GET /workflows` response

* fix(core): Update unit tests for `GET /workflows` response

* fix(core): remove nodes from getMany

* fix(core): remove unnecessary owner props from workflow list items

* fix(core): fix lint error

* fix(core): remove unused function

* fix(core): simplifying ownerId usage

* fix(core): trim down the query for workflow listing
This commit is contained in:
Csaba Tuncsik
2023-02-16 10:36:24 +01:00
committed by GitHub
parent 1a20fd9f46
commit a2c6ea9e11
5 changed files with 51 additions and 117 deletions

View File

@@ -1,7 +1,7 @@
import { validate as jsonSchemaValidate } from 'jsonschema';
import type { INode, IPinData, JsonObject } from 'n8n-workflow';
import { NodeApiError, jsonParse, LoggerProxy, Workflow } from 'n8n-workflow';
import type { FindOptionsWhere, UpdateResult } from 'typeorm';
import type { FindOptionsSelect, FindOptionsWhere, UpdateResult } from 'typeorm';
import { In } from 'typeorm';
import pick from 'lodash.pick';
import { v4 as uuid } from 'uuid';
@@ -25,12 +25,12 @@ import * as WorkflowExecuteAdditionalData from '@/WorkflowExecuteAdditionalData'
import * as TestWebhooks from '@/TestWebhooks';
import { getSharedWorkflowIds } from '@/WorkflowHelpers';
import { isSharingEnabled, whereClause } from '@/UserManagement/UserManagementHelper';
import type { WorkflowForList } from '@/workflows/workflows.types';
export interface IGetWorkflowsQueryFilter {
id?: string;
name?: string;
active?: boolean;
}
export type IGetWorkflowsQueryFilter = Pick<
FindOptionsWhere<WorkflowEntity>,
'id' | 'name' | 'active'
>;
const schemaGetWorkflowsQueryFilter = {
$id: '/IGetWorkflowsQueryFilter',
@@ -114,7 +114,7 @@ export class WorkflowsService {
return getSharedWorkflowIds(user, roles);
}
static async getMany(user: User, rawFilter: string): Promise<WorkflowEntity[]> {
static async getMany(user: User, rawFilter: string): Promise<WorkflowForList[]> {
const sharedWorkflowIds = await this.getWorkflowIdsForUser(user, ['owner']);
if (sharedWorkflowIds.length === 0) {
// return early since without shared workflows there can be no hits
@@ -122,7 +122,7 @@ export class WorkflowsService {
return [];
}
let filter: IGetWorkflowsQueryFilter | undefined = undefined;
let filter: IGetWorkflowsQueryFilter = {};
if (rawFilter) {
try {
const filterJson: JsonObject = jsonParse(rawFilter);
@@ -152,31 +152,32 @@ export class WorkflowsService {
return [];
}
const fields: Array<keyof WorkflowEntity> = [
'id',
'name',
'active',
'createdAt',
'updatedAt',
'nodes',
];
const select: FindOptionsSelect<WorkflowEntity> = {
id: true,
name: true,
active: true,
createdAt: true,
updatedAt: true,
};
const relations: string[] = [];
if (!config.getEnv('workflowTagsDisabled')) {
relations.push('tags');
select.tags = { name: true };
}
if (isSharingEnabled()) {
relations.push('shared', 'shared.user', 'shared.role');
relations.push('shared');
select.shared = { userId: true, roleId: true };
select.versionId = true;
}
filter.id = In(sharedWorkflowIds);
return Db.collections.Workflow.find({
select: isSharingEnabled() ? [...fields, 'versionId'] : fields,
select,
relations,
where: {
id: In(sharedWorkflowIds),
...filter,
},
where: filter,
order: { updatedAt: 'DESC' },
});
}