mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Improve cleaning function
This commit is contained in:
parent
cc971e3a3c
commit
a20bc33c7d
|
@ -6,8 +6,6 @@ import express = require('express');
|
|||
import * as SwaggerParser from '@apidevtools/swagger-parser';
|
||||
import { In } from 'typeorm';
|
||||
import { validate as uuidValidate } from 'uuid';
|
||||
import { Workflow } from 'n8n-workflow';
|
||||
import { worker } from 'cluster';
|
||||
import { User } from '../databases/entities/User';
|
||||
import type { Role } from '../databases/entities/Role';
|
||||
import { ActiveWorkflowRunner, Db, InternalHooksManager, ITelemetryUserDeletionData } from '..';
|
||||
|
@ -71,12 +69,6 @@ export const connectionName = (): string => {
|
|||
return 'default';
|
||||
};
|
||||
|
||||
export const clean = (users: User[], options?: { includeRole: boolean }): Array<Partial<User>> => {
|
||||
return users.map((user) =>
|
||||
pick(user, getSelectableProperties('user').concat(options?.includeRole ? ['globalRole'] : [])),
|
||||
);
|
||||
};
|
||||
|
||||
const middlewareDefined = (operationId: OperationID, middlewares: IMiddlewares) =>
|
||||
operationId && middlewares[operationId];
|
||||
|
||||
|
@ -344,3 +336,24 @@ export async function deleteDataAndSendTelemetry(data: {
|
|||
await deleteWorkflowsAndCredentials(data);
|
||||
await sendUserDeleteTelemetry(data);
|
||||
}
|
||||
|
||||
export function clean(user: User, options?: { includeRole: boolean }): Partial<User>;
|
||||
export function clean(users: User[], options?: { includeRole: boolean }): Array<Partial<User>>;
|
||||
|
||||
export function clean(
|
||||
users: User[] | User,
|
||||
options?: { includeRole: boolean },
|
||||
): Array<Partial<User>> | Partial<User> {
|
||||
if (Array.isArray(users)) {
|
||||
return users.map((user) =>
|
||||
pick(
|
||||
user,
|
||||
getSelectableProperties('user').concat(options?.includeRole ? ['globalRole'] : []),
|
||||
),
|
||||
);
|
||||
}
|
||||
return pick(
|
||||
users,
|
||||
getSelectableProperties('user').concat(options?.includeRole ? ['globalRole'] : []),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ export = {
|
|||
toUser: transferee,
|
||||
});
|
||||
|
||||
return clean([userToDelete]).pop();
|
||||
return clean(userToDelete);
|
||||
}
|
||||
|
||||
await deleteDataAndSendTelemetry({
|
||||
|
@ -109,7 +109,7 @@ export = {
|
|||
transferId,
|
||||
});
|
||||
|
||||
return clean([userToDelete], { includeRole }).pop();
|
||||
return clean(userToDelete);
|
||||
},
|
||||
// eslint-disable-next-line consistent-return
|
||||
getUser: async (req: UserRequest.Get, res: express.Response): Promise<any> => {
|
||||
|
|
Loading…
Reference in a new issue