refactor: Consolidate WorkflowService.getMany() (no-changelog) (#6892)

In scope:

- Consolidate `WorkflowService.getMany()`.
- Support non-entity field `ownedBy` for `select`.
- Support `tags` for `filter`.
- Move `addOwnerId` to `OwnershipService`.
- Remove unneeded check for `filter.id`.
- Simplify DTO validation for `filter` and `select`.
- Expand tests for `GET /workflows`.

Workflow list query DTOs:

```
filter → name, active, tags
select → id, name, active, tags, createdAt, updatedAt, versionId, ownedBy
```

Out of scope:

- Migrate `shared_workflow.roleId` and `shared_credential.roleId` to
string IDs.
- Refactor `WorkflowHelpers.getSharedWorkflowIds()`.
This commit is contained in:
Iván Ovejero
2023-08-22 13:19:37 +02:00
committed by GitHub
parent f32e993227
commit 2cfa6d344e
20 changed files with 686 additions and 318 deletions

View File

@@ -8,6 +8,7 @@ import type {
INodeCredentialTestRequest,
IPinData,
IRunData,
IUser,
IWorkflowSettings,
} from 'n8n-workflow';
@@ -18,6 +19,7 @@ import type { Role } from '@db/entities/Role';
import type { User } from '@db/entities/User';
import type { UserManagementMailer } from '@/UserManagement/email';
import type { Variables } from '@db/entities/Variables';
import type { WorkflowEntity } from './databases/entities/WorkflowEntity';
export class UserUpdatePayload implements Pick<User, 'email' | 'firstName' | 'lastName'> {
@IsEmail()
@@ -113,23 +115,51 @@ export declare namespace WorkflowRequest {
// list query
// ----------------------------------
export type ListQueryRequest = AuthenticatedRequest<{}, {}, {}, ListQueryParams> & {
listQueryOptions?: ListQueryOptions;
};
export namespace ListQuery {
export type Request = AuthenticatedRequest<{}, {}, {}, Params> & {
listQueryOptions?: Options;
};
type ListQueryParams = {
filter?: string;
skip?: string;
take?: string;
select?: string;
};
export type Params = {
filter?: string;
skip?: string;
take?: string;
select?: string;
};
export type ListQueryOptions = {
filter?: Record<string, unknown>;
select?: Record<string, true>;
skip?: number;
take?: number;
};
export type Options = {
filter?: Record<string, unknown>;
select?: Record<string, true>;
skip?: number;
take?: number;
};
/**
* Slim workflow returned from a list query operation.
*/
export namespace Workflow {
type OptionalBaseFields = 'name' | 'active' | 'versionId' | 'createdAt' | 'updatedAt' | 'tags';
type BaseFields = Pick<WorkflowEntity, 'id'> &
Partial<Pick<WorkflowEntity, OptionalBaseFields>>;
type SharedField = Partial<Pick<WorkflowEntity, 'shared'>>;
type OwnedByField = { ownedBy: Pick<IUser, 'id'> | null };
export type Plain = BaseFields;
export type WithSharing = BaseFields & SharedField;
export type WithOwnership = BaseFields & OwnedByField;
}
}
export function hasSharing(
workflows: ListQuery.Workflow.Plain[] | ListQuery.Workflow.WithSharing[],
): workflows is ListQuery.Workflow.WithSharing[] {
return workflows.some((w) => 'shared' in w);
}
// ----------------------------------
// /credentials