refactor(core): Use injectable classes for db repositories (part-1) (no-changelog) (#5953)
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
committed by
GitHub
parent
323e26acfd
commit
10f8c35dbb
@@ -8,7 +8,6 @@ import { Request, Response } from 'express';
|
||||
import type { ILogger } from 'n8n-workflow';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { LoginRequest, UserRequest } from '@/requests';
|
||||
import type { Repository } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
import type { Config } from '@/config';
|
||||
import type {
|
||||
@@ -23,6 +22,7 @@ import {
|
||||
isLdapCurrentAuthenticationMethod,
|
||||
isSamlCurrentAuthenticationMethod,
|
||||
} from '@/sso/ssoHelpers';
|
||||
import type { UserRepository } from '@db/repositories';
|
||||
|
||||
@RestController()
|
||||
export class AuthController {
|
||||
@@ -32,7 +32,7 @@ export class AuthController {
|
||||
|
||||
private readonly internalHooks: IInternalHooksClass;
|
||||
|
||||
private readonly userRepository: Repository<User>;
|
||||
private readonly userRepository: UserRepository;
|
||||
|
||||
private readonly postHog?: PostHogClient;
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ import {
|
||||
validatePassword,
|
||||
} from '@/UserManagement/UserManagementHelper';
|
||||
import { BadRequestError } from '@/ResponseHelper';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { validateEntity } from '@/GenericHelpers';
|
||||
import { issueCookie } from '@/auth/jwt';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { UserRepository } from '@db/repositories';
|
||||
import { Response } from 'express';
|
||||
import type { Repository } from 'typeorm';
|
||||
import type { ILogger } from 'n8n-workflow';
|
||||
import {
|
||||
AuthenticatedRequest,
|
||||
@@ -38,7 +38,7 @@ export class MeController {
|
||||
|
||||
private readonly internalHooks: IInternalHooksClass;
|
||||
|
||||
private readonly userRepository: Repository<User>;
|
||||
private readonly userRepository: UserRepository;
|
||||
|
||||
constructor({
|
||||
logger,
|
||||
|
||||
@@ -9,14 +9,16 @@ import {
|
||||
} from '@/UserManagement/UserManagementHelper';
|
||||
import { issueCookie } from '@/auth/jwt';
|
||||
import { Response } from 'express';
|
||||
import type { Repository } from 'typeorm';
|
||||
import type { ILogger } from 'n8n-workflow';
|
||||
import type { Config } from '@/config';
|
||||
import { OwnerRequest } from '@/requests';
|
||||
import type { IDatabaseCollections, IInternalHooksClass, ICredentialsDb } from '@/Interfaces';
|
||||
import type { Settings } from '@db/entities/Settings';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
import type { IDatabaseCollections, IInternalHooksClass } from '@/Interfaces';
|
||||
import type {
|
||||
CredentialsRepository,
|
||||
SettingsRepository,
|
||||
UserRepository,
|
||||
WorkflowRepository,
|
||||
} from '@db/repositories';
|
||||
|
||||
@RestController('/owner')
|
||||
export class OwnerController {
|
||||
@@ -26,13 +28,13 @@ export class OwnerController {
|
||||
|
||||
private readonly internalHooks: IInternalHooksClass;
|
||||
|
||||
private readonly userRepository: Repository<User>;
|
||||
private readonly userRepository: UserRepository;
|
||||
|
||||
private readonly settingsRepository: Repository<Settings>;
|
||||
private readonly settingsRepository: SettingsRepository;
|
||||
|
||||
private readonly credentialsRepository: Repository<ICredentialsDb>;
|
||||
private readonly credentialsRepository: CredentialsRepository;
|
||||
|
||||
private readonly workflowsRepository: Repository<WorkflowEntity>;
|
||||
private readonly workflowsRepository: WorkflowRepository;
|
||||
|
||||
constructor({
|
||||
config,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { Repository } from 'typeorm';
|
||||
import { IsNull, MoreThanOrEqual, Not } from 'typeorm';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import validator from 'validator';
|
||||
@@ -20,7 +19,7 @@ import type { UserManagementMailer } from '@/UserManagement/email';
|
||||
import { Response } from 'express';
|
||||
import type { ILogger } from 'n8n-workflow';
|
||||
import type { Config } from '@/config';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { UserRepository } from '@db/repositories';
|
||||
import { PasswordResetRequest } from '@/requests';
|
||||
import type { IDatabaseCollections, IExternalHooksClass, IInternalHooksClass } from '@/Interfaces';
|
||||
import { issueCookie } from '@/auth/jwt';
|
||||
@@ -39,7 +38,7 @@ export class PasswordResetController {
|
||||
|
||||
private readonly mailer: UserManagementMailer;
|
||||
|
||||
private readonly userRepository: Repository<User>;
|
||||
private readonly userRepository: UserRepository;
|
||||
|
||||
constructor({
|
||||
config,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import type { Repository } from 'typeorm';
|
||||
import type { Config } from '@/config';
|
||||
import { Delete, Get, Middleware, Patch, Post, RestController } from '@/decorators';
|
||||
import type { IDatabaseCollections, IExternalHooksClass, ITagWithCountDb } from '@/Interfaces';
|
||||
import { TagEntity } from '@db/entities/TagEntity';
|
||||
import type { TagRepository } from '@db/repositories';
|
||||
import { validateEntity } from '@/GenericHelpers';
|
||||
import { BadRequestError, UnauthorizedError } from '@/ResponseHelper';
|
||||
import { TagsRequest } from '@/requests';
|
||||
@@ -14,7 +14,7 @@ export class TagsController {
|
||||
|
||||
private externalHooks: IExternalHooksClass;
|
||||
|
||||
private tagsRepository: Repository<TagEntity>;
|
||||
private tagsRepository: TagRepository;
|
||||
|
||||
constructor({
|
||||
config,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import validator from 'validator';
|
||||
import type { Repository } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
import type { ILogger } from 'n8n-workflow';
|
||||
import { ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
|
||||
@@ -23,7 +22,6 @@ import { Response } from 'express';
|
||||
import type { Config } from '@/config';
|
||||
import { UserRequest } from '@/requests';
|
||||
import type { UserManagementMailer } from '@/UserManagement/email';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import type {
|
||||
PublicUser,
|
||||
IDatabaseCollections,
|
||||
@@ -36,6 +34,12 @@ import { AuthIdentity } from '@db/entities/AuthIdentity';
|
||||
import type { PostHogClient } from '@/posthog';
|
||||
import { userManagementEnabledMiddleware } from '../middlewares/userManagementEnabled';
|
||||
import { isSamlLicensedAndEnabled } from '../sso/saml/samlHelpers';
|
||||
import type {
|
||||
RoleRepository,
|
||||
SharedCredentialsRepository,
|
||||
SharedWorkflowRepository,
|
||||
UserRepository,
|
||||
} from '@db/repositories';
|
||||
|
||||
@RestController('/users')
|
||||
export class UsersController {
|
||||
@@ -47,13 +51,13 @@ export class UsersController {
|
||||
|
||||
private internalHooks: IInternalHooksClass;
|
||||
|
||||
private userRepository: Repository<User>;
|
||||
private userRepository: UserRepository;
|
||||
|
||||
private roleRepository: Repository<Role>;
|
||||
private roleRepository: RoleRepository;
|
||||
|
||||
private sharedCredentialsRepository: Repository<SharedCredentials>;
|
||||
private sharedCredentialsRepository: SharedCredentialsRepository;
|
||||
|
||||
private sharedWorkflowRepository: Repository<SharedWorkflow>;
|
||||
private sharedWorkflowRepository: SharedWorkflowRepository;
|
||||
|
||||
private activeWorkflowRunner: ActiveWorkflowRunner;
|
||||
|
||||
@@ -147,7 +151,7 @@ export class UsersController {
|
||||
createUsers[invite.email.toLowerCase()] = null;
|
||||
});
|
||||
|
||||
const role = await this.roleRepository.findOneBy({ scope: 'global', name: 'member' });
|
||||
const role = await this.roleRepository.findGlobalMemberRole();
|
||||
|
||||
if (!role) {
|
||||
this.logger.error(
|
||||
@@ -396,8 +400,8 @@ export class UsersController {
|
||||
}
|
||||
|
||||
const [workflowOwnerRole, credentialOwnerRole] = await Promise.all([
|
||||
this.roleRepository.findOneBy({ name: 'owner', scope: 'workflow' }),
|
||||
this.roleRepository.findOneBy({ name: 'owner', scope: 'credential' }),
|
||||
this.roleRepository.findWorkflowOwnerRole(),
|
||||
this.roleRepository.findCredentialOwnerRole(),
|
||||
]);
|
||||
|
||||
if (transferId) {
|
||||
|
||||
Reference in New Issue
Block a user