From f4a580cf2a67a911cd5798fe58f1fe3f44703889 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Sun, 30 Jan 2022 15:48:59 +0100 Subject: [PATCH] refactor(config): extract note config from app config This commit separates the app config object from a new note config object. This was done to separate different concerns in different config files. Especially if the number of settings that are about notes increase, it is a good idea to keep them separate from the app config. Signed-off-by: Philip Molares --- .../private/alias/alias.controller.spec.ts | 5 +- .../private/config/config.controller.spec.ts | 4 +- .../me/history/history.controller.spec.ts | 5 +- src/api/private/me/me.controller.spec.ts | 4 +- .../private/media/media.controller.spec.ts | 4 +- .../private/notes/notes.controller.spec.ts | 5 +- src/api/public/alias/alias.controller.spec.ts | 5 +- src/api/public/me/me.controller.spec.ts | 5 +- src/api/public/media/media.controller.spec.ts | 5 +- src/api/public/notes/notes.controller.spec.ts | 5 +- src/app.module.ts | 4 +- src/config/app.config.ts | 17 +------ src/config/mock/app.config.mock.ts | 20 ++++---- src/config/mock/note.config.mock.ts | 16 +++++++ src/config/note.config.ts | 46 +++++++++++++++++++ .../frontend-config.service.spec.ts | 13 ++++-- .../frontend-config.service.ts | 7 ++- src/history/history.service.spec.ts | 5 +- src/media/media.service.spec.ts | 5 +- src/notes/alias.service.spec.ts | 7 +-- src/notes/notes.service.spec.ts | 7 +-- src/notes/notes.service.ts | 10 ++-- src/permissions/permissions.service.spec.ts | 5 +- src/revisions/revisions.service.spec.ts | 5 +- test/private-api/alias.e2e-spec.ts | 4 +- test/private-api/history.e2e-spec.ts | 5 +- test/private-api/notes.e2e-spec.ts | 4 +- test/public-api/alias.e2e-spec.ts | 4 +- test/public-api/notes.e2e-spec.ts | 4 +- test/test-setup.ts | 4 +- 30 files changed, 161 insertions(+), 78 deletions(-) create mode 100644 src/config/mock/note.config.mock.ts create mode 100644 src/config/note.config.ts diff --git a/src/api/private/alias/alias.controller.spec.ts b/src/api/private/alias/alias.controller.spec.ts index c272c4298..ae0c12454 100644 --- a/src/api/private/alias/alias.controller.spec.ts +++ b/src/api/private/alias/alias.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -15,6 +15,7 @@ import { AuthToken } from '../../../auth/auth-token.entity'; import { Author } from '../../../authors/author.entity'; import appConfigMock from '../../../config/mock/app.config.mock'; import mediaConfigMock from '../../../config/mock/media.config.mock'; +import noteConfigMock from '../../../config/mock/note.config.mock'; import { Group } from '../../../groups/group.entity'; import { GroupsModule } from '../../../groups/groups.module'; import { HistoryEntry } from '../../../history/history-entry.entity'; @@ -75,7 +76,7 @@ describe('AliasController', () => { MediaModule, ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock, mediaConfigMock], + load: [appConfigMock, noteConfigMock, mediaConfigMock], }), TypeOrmModule.forRoot(), ], diff --git a/src/api/private/config/config.controller.spec.ts b/src/api/private/config/config.controller.spec.ts index a0ae5d16b..37d3262af 100644 --- a/src/api/private/config/config.controller.spec.ts +++ b/src/api/private/config/config.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -10,6 +10,7 @@ import appConfigMock from '../../../config/mock/app.config.mock'; import authConfigMock from '../../../config/mock/auth.config.mock'; import customizationConfigMock from '../../../config/mock/customization.config.mock'; import externalConfigMock from '../../../config/mock/external-services.config.mock'; +import noteConfigMock from '../../../config/mock/note.config.mock'; import { FrontendConfigModule } from '../../../frontend-config/frontend-config.module'; import { LoggerModule } from '../../../logger/logger.module'; import { ConfigController } from './config.controller'; @@ -24,6 +25,7 @@ describe('ConfigController', () => { isGlobal: true, load: [ appConfigMock, + noteConfigMock, authConfigMock, customizationConfigMock, externalConfigMock, diff --git a/src/api/private/me/history/history.controller.spec.ts b/src/api/private/me/history/history.controller.spec.ts index d3ab85c98..c0594b46b 100644 --- a/src/api/private/me/history/history.controller.spec.ts +++ b/src/api/private/me/history/history.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -14,6 +14,7 @@ import { import { AuthToken } from '../../../../auth/auth-token.entity'; import { Author } from '../../../../authors/author.entity'; import appConfigMock from '../../../../config/mock/app.config.mock'; +import noteConfigMock from '../../../../config/mock/note.config.mock'; import { Group } from '../../../../groups/group.entity'; import { HistoryEntry } from '../../../../history/history-entry.entity'; import { HistoryModule } from '../../../../history/history.module'; @@ -45,7 +46,7 @@ describe('HistoryController', () => { LoggerModule, ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock], + load: [appConfigMock, noteConfigMock], }), TypeOrmModule.forRoot(), ], diff --git a/src/api/private/me/me.controller.spec.ts b/src/api/private/me/me.controller.spec.ts index 38c2a367a..5543cbb2d 100644 --- a/src/api/private/me/me.controller.spec.ts +++ b/src/api/private/me/me.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -13,6 +13,7 @@ import authConfigMock from '../../../config/mock/auth.config.mock'; import customizationConfigMock from '../../../config/mock/customization.config.mock'; import externalServicesConfigMock from '../../../config/mock/external-services.config.mock'; import mediaConfigMock from '../../../config/mock/media.config.mock'; +import noteConfigMock from '../../../config/mock/note.config.mock'; import { Group } from '../../../groups/group.entity'; import { Identity } from '../../../identity/identity.entity'; import { LoggerModule } from '../../../logger/logger.module'; @@ -44,6 +45,7 @@ describe('MeController', () => { isGlobal: true, load: [ appConfigMock, + noteConfigMock, authConfigMock, mediaConfigMock, customizationConfigMock, diff --git a/src/api/private/media/media.controller.spec.ts b/src/api/private/media/media.controller.spec.ts index 774f34881..762478667 100644 --- a/src/api/private/media/media.controller.spec.ts +++ b/src/api/private/media/media.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -14,6 +14,7 @@ import authConfigMock from '../../../config/mock/auth.config.mock'; import customizationConfigMock from '../../../config/mock/customization.config.mock'; import externalConfigMock from '../../../config/mock/external-services.config.mock'; import mediaConfigMock from '../../../config/mock/media.config.mock'; +import noteConfigMock from '../../../config/mock/note.config.mock'; import { Group } from '../../../groups/group.entity'; import { Identity } from '../../../identity/identity.entity'; import { LoggerModule } from '../../../logger/logger.module'; @@ -45,6 +46,7 @@ describe('MediaController', () => { isGlobal: true, load: [ appConfigMock, + noteConfigMock, mediaConfigMock, authConfigMock, customizationConfigMock, diff --git a/src/api/private/notes/notes.controller.spec.ts b/src/api/private/notes/notes.controller.spec.ts index a47dda7ed..d0cb6c163 100644 --- a/src/api/private/notes/notes.controller.spec.ts +++ b/src/api/private/notes/notes.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -15,6 +15,7 @@ import { AuthToken } from '../../../auth/auth-token.entity'; import { Author } from '../../../authors/author.entity'; import appConfigMock from '../../../config/mock/app.config.mock'; import mediaConfigMock from '../../../config/mock/media.config.mock'; +import noteConfigMock from '../../../config/mock/note.config.mock'; import { Group } from '../../../groups/group.entity'; import { GroupsModule } from '../../../groups/groups.module'; import { HistoryEntry } from '../../../history/history-entry.entity'; @@ -73,7 +74,7 @@ describe('NotesController', () => { MediaModule, ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock, mediaConfigMock], + load: [appConfigMock, noteConfigMock, mediaConfigMock], }), TypeOrmModule.forRoot(), ], diff --git a/src/api/public/alias/alias.controller.spec.ts b/src/api/public/alias/alias.controller.spec.ts index c272c4298..ae0c12454 100644 --- a/src/api/public/alias/alias.controller.spec.ts +++ b/src/api/public/alias/alias.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -15,6 +15,7 @@ import { AuthToken } from '../../../auth/auth-token.entity'; import { Author } from '../../../authors/author.entity'; import appConfigMock from '../../../config/mock/app.config.mock'; import mediaConfigMock from '../../../config/mock/media.config.mock'; +import noteConfigMock from '../../../config/mock/note.config.mock'; import { Group } from '../../../groups/group.entity'; import { GroupsModule } from '../../../groups/groups.module'; import { HistoryEntry } from '../../../history/history-entry.entity'; @@ -75,7 +76,7 @@ describe('AliasController', () => { MediaModule, ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock, mediaConfigMock], + load: [appConfigMock, noteConfigMock, mediaConfigMock], }), TypeOrmModule.forRoot(), ], diff --git a/src/api/public/me/me.controller.spec.ts b/src/api/public/me/me.controller.spec.ts index 13cc6cebd..25db4da62 100644 --- a/src/api/public/me/me.controller.spec.ts +++ b/src/api/public/me/me.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -15,6 +15,7 @@ import { AuthToken } from '../../../auth/auth-token.entity'; import { Author } from '../../../authors/author.entity'; import appConfigMock from '../../../config/mock/app.config.mock'; import mediaConfigMock from '../../../config/mock/media.config.mock'; +import noteConfigMock from '../../../config/mock/note.config.mock'; import { Group } from '../../../groups/group.entity'; import { HistoryEntry } from '../../../history/history-entry.entity'; import { HistoryModule } from '../../../history/history.module'; @@ -44,7 +45,7 @@ describe('Me Controller', () => { imports: [ ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock, mediaConfigMock], + load: [appConfigMock, noteConfigMock, mediaConfigMock], }), UsersModule, HistoryModule, diff --git a/src/api/public/media/media.controller.spec.ts b/src/api/public/media/media.controller.spec.ts index 4c75c7f6a..e6108df1c 100644 --- a/src/api/public/media/media.controller.spec.ts +++ b/src/api/public/media/media.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -11,6 +11,7 @@ import { AuthToken } from '../../../auth/auth-token.entity'; import { Author } from '../../../authors/author.entity'; import appConfigMock from '../../../config/mock/app.config.mock'; import mediaConfigMock from '../../../config/mock/media.config.mock'; +import noteConfigMock from '../../../config/mock/note.config.mock'; import { Group } from '../../../groups/group.entity'; import { Identity } from '../../../identity/identity.entity'; import { LoggerModule } from '../../../logger/logger.module'; @@ -37,7 +38,7 @@ describe('Media Controller', () => { imports: [ ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock, mediaConfigMock], + load: [appConfigMock, noteConfigMock, mediaConfigMock], }), LoggerModule, MediaModule, diff --git a/src/api/public/notes/notes.controller.spec.ts b/src/api/public/notes/notes.controller.spec.ts index 77c281efc..4a7bfcb07 100644 --- a/src/api/public/notes/notes.controller.spec.ts +++ b/src/api/public/notes/notes.controller.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -15,6 +15,7 @@ import { AuthToken } from '../../../auth/auth-token.entity'; import { Author } from '../../../authors/author.entity'; import appConfigMock from '../../../config/mock/app.config.mock'; import mediaConfigMock from '../../../config/mock/media.config.mock'; +import noteConfigMock from '../../../config/mock/note.config.mock'; import { Group } from '../../../groups/group.entity'; import { GroupsModule } from '../../../groups/groups.module'; import { HistoryEntry } from '../../../history/history-entry.entity'; @@ -73,7 +74,7 @@ describe('Notes Controller', () => { MediaModule, ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock, mediaConfigMock], + load: [appConfigMock, noteConfigMock, mediaConfigMock], }), TypeOrmModule.forRoot(), ], diff --git a/src/app.module.ts b/src/app.module.ts index e3de9d89c..a8ce19c48 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -21,6 +21,7 @@ import databaseConfig from './config/database.config'; import externalConfig from './config/external-services.config'; import hstsConfig from './config/hsts.config'; import mediaConfig from './config/media.config'; +import noteConfig from './config/note.config'; import { FrontendConfigModule } from './frontend-config/frontend-config.module'; import { FrontendConfigService } from './frontend-config/frontend-config.service'; import { GroupsModule } from './groups/groups.module'; @@ -57,6 +58,7 @@ const routes: Routes = [ ConfigModule.forRoot({ load: [ appConfig, + noteConfig, mediaConfig, hstsConfig, cspConfig, diff --git a/src/config/app.config.ts b/src/config/app.config.ts index bcce771cc..90f7fc1ab 100644 --- a/src/config/app.config.ts +++ b/src/config/app.config.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -7,15 +7,13 @@ import { registerAs } from '@nestjs/config'; import * as Joi from 'joi'; import { Loglevel } from './loglevel.enum'; -import { buildErrorMessage, parseOptionalInt, toArrayConfig } from './utils'; +import { buildErrorMessage, parseOptionalInt } from './utils'; export interface AppConfig { domain: string; rendererOrigin: string; port: number; loglevel: Loglevel; - forbiddenNoteIds: string[]; - maxDocumentLength: number; } const schema = Joi.object({ @@ -30,15 +28,6 @@ const schema = Joi.object({ .default(Loglevel.WARN) .optional() .label('HD_LOGLEVEL'), - forbiddenNoteIds: Joi.array() - .items(Joi.string()) - .optional() - .default([]) - .label('HD_FORBIDDEN_NOTE_IDS'), - maxDocumentLength: Joi.number() - .default(100000) - .optional() - .label('HD_MAX_DOCUMENT_LENGTH'), }); export default registerAs('appConfig', () => { @@ -48,8 +37,6 @@ export default registerAs('appConfig', () => { rendererOrigin: process.env.HD_RENDERER_ORIGIN, port: parseOptionalInt(process.env.PORT), loglevel: process.env.HD_LOGLEVEL, - forbiddenNoteIds: toArrayConfig(process.env.HD_FORBIDDEN_NOTE_IDS, ','), - maxDocumentLength: parseOptionalInt(process.env.HD_MAX_DOCUMENT_LENGTH), }, { abortEarly: false, diff --git a/src/config/mock/app.config.mock.ts b/src/config/mock/app.config.mock.ts index aff64655d..059887e80 100644 --- a/src/config/mock/app.config.mock.ts +++ b/src/config/mock/app.config.mock.ts @@ -1,17 +1,19 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ import { registerAs } from '@nestjs/config'; +import { AppConfig } from '../app.config'; import { Loglevel } from '../loglevel.enum'; -export default registerAs('appConfig', () => ({ - domain: 'md.example.com', - rendererOrigin: 'md-renderer.example.com', - port: 3000, - loglevel: Loglevel.ERROR, - maxDocumentLength: 100000, - forbiddenNoteIds: ['forbiddenNoteId'], -})); +export default registerAs( + 'appConfig', + (): AppConfig => ({ + domain: 'md.example.com', + rendererOrigin: 'md-renderer.example.com', + port: 3000, + loglevel: Loglevel.ERROR, + }), +); diff --git a/src/config/mock/note.config.mock.ts b/src/config/mock/note.config.mock.ts new file mode 100644 index 000000000..978509545 --- /dev/null +++ b/src/config/mock/note.config.mock.ts @@ -0,0 +1,16 @@ +/* + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ +import { registerAs } from '@nestjs/config'; + +import { NoteConfig } from '../note.config'; + +export default registerAs( + 'noteConfig', + (): NoteConfig => ({ + maxDocumentLength: 100000, + forbiddenNoteIds: ['forbiddenNoteId'], + }), +); diff --git a/src/config/note.config.ts b/src/config/note.config.ts new file mode 100644 index 000000000..4746c3702 --- /dev/null +++ b/src/config/note.config.ts @@ -0,0 +1,46 @@ +/* + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ +import { registerAs } from '@nestjs/config'; +import * as Joi from 'joi'; + +import { buildErrorMessage, parseOptionalInt, toArrayConfig } from './utils'; + +export interface NoteConfig { + forbiddenNoteIds: string[]; + maxDocumentLength: number; +} + +const schema = Joi.object({ + forbiddenNoteIds: Joi.array() + .items(Joi.string()) + .optional() + .default([]) + .label('HD_FORBIDDEN_NOTE_IDS'), + maxDocumentLength: Joi.number() + .default(100000) + .optional() + .label('HD_MAX_DOCUMENT_LENGTH'), +}); + +export default registerAs('noteConfig', () => { + const noteConfig = schema.validate( + { + forbiddenNoteIds: toArrayConfig(process.env.HD_FORBIDDEN_NOTE_IDS, ','), + maxDocumentLength: parseOptionalInt(process.env.HD_MAX_DOCUMENT_LENGTH), + }, + { + abortEarly: false, + presence: 'required', + }, + ); + if (noteConfig.error) { + const errorMessages = noteConfig.error.details.map( + (detail) => detail.message, + ); + throw new Error(buildErrorMessage(errorMessages)); + } + return noteConfig.value as NoteConfig; +}); diff --git a/src/frontend-config/frontend-config.service.spec.ts b/src/frontend-config/frontend-config.service.spec.ts index 9c9b3b34d..c2f8088ff 100644 --- a/src/frontend-config/frontend-config.service.spec.ts +++ b/src/frontend-config/frontend-config.service.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -13,6 +13,7 @@ import { CustomizationConfig } from '../config/customization.config'; import { ExternalServicesConfig } from '../config/external-services.config'; import { GitlabScope, GitlabVersion } from '../config/gitlab.enum'; import { Loglevel } from '../config/loglevel.enum'; +import { NoteConfig } from '../config/note.config'; import { LoggerModule } from '../logger/logger.module'; import { getServerVersionFromPackageJson } from '../utils/serverVersion'; import { AuthProviderType } from './frontend-config.dto'; @@ -194,8 +195,6 @@ describe('FrontendConfigService', () => { rendererOrigin: renderOrigin ?? domain, port: 3000, loglevel: Loglevel.ERROR, - forbiddenNoteIds: [], - maxDocumentLength: maxDocumentLength, }; const authConfig: AuthConfig = { ...emptyAuthConfig, @@ -221,6 +220,10 @@ describe('FrontendConfigService', () => { plantUmlServer: plantUmlServer, imageProxy: imageProxy, }; + const noteConfig: NoteConfig = { + forbiddenNoteIds: [], + maxDocumentLength: maxDocumentLength, + }; const module: TestingModule = await Test.createTestingModule({ imports: [ @@ -240,6 +243,10 @@ describe('FrontendConfigService', () => { 'externalServicesConfig', () => externalServicesConfig, ), + registerAs( + 'noteConfig', + () => noteConfig, + ), ], }), LoggerModule, diff --git a/src/frontend-config/frontend-config.service.ts b/src/frontend-config/frontend-config.service.ts index 5b2b13bfb..9f86cfc4b 100644 --- a/src/frontend-config/frontend-config.service.ts +++ b/src/frontend-config/frontend-config.service.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -14,6 +14,7 @@ import customizationConfiguration, { import externalServicesConfiguration, { ExternalServicesConfig, } from '../config/external-services.config'; +import noteConfiguration, { NoteConfig } from '../config/note.config'; import { ConsoleLoggerService } from '../logger/console-logger.service'; import { getServerVersionFromPackageJson } from '../utils/serverVersion'; import { @@ -31,6 +32,8 @@ export class FrontendConfigService { private readonly logger: ConsoleLoggerService, @Inject(appConfiguration.KEY) private appConfig: AppConfig, + @Inject(noteConfiguration.KEY) + private noteConfig: NoteConfig, @Inject(authConfiguration.KEY) private authConfig: AuthConfig, @Inject(customizationConfiguration.KEY) @@ -49,7 +52,7 @@ export class FrontendConfigService { authProviders: this.getAuthProviders(), branding: this.getBranding(), iframeCommunication: this.getIframeCommunication(), - maxDocumentLength: this.appConfig.maxDocumentLength, + maxDocumentLength: this.noteConfig.maxDocumentLength, plantUmlServer: this.externalServicesConfig.plantUmlServer ? new URL(this.externalServicesConfig.plantUmlServer) : undefined, diff --git a/src/history/history.service.spec.ts b/src/history/history.service.spec.ts index eaf417344..896938695 100644 --- a/src/history/history.service.spec.ts +++ b/src/history/history.service.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -11,6 +11,7 @@ import { Connection, Repository } from 'typeorm'; import { AuthToken } from '../auth/auth-token.entity'; import { Author } from '../authors/author.entity'; import appConfigMock from '../config/mock/app.config.mock'; +import noteConfigMock from '../config/mock/note.config.mock'; import { NotInDBError } from '../errors/errors'; import { Group } from '../groups/group.entity'; import { Identity } from '../identity/identity.entity'; @@ -65,7 +66,7 @@ describe('HistoryService', () => { NotesModule, ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock], + load: [appConfigMock, noteConfigMock], }), ], }) diff --git a/src/media/media.service.spec.ts b/src/media/media.service.spec.ts index 0ce609ebd..1b68ed47d 100644 --- a/src/media/media.service.spec.ts +++ b/src/media/media.service.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -13,6 +13,7 @@ import appConfigMock from '../../src/config/mock/app.config.mock'; import { AuthToken } from '../auth/auth-token.entity'; import { Author } from '../authors/author.entity'; import mediaConfigMock from '../config/mock/media.config.mock'; +import noteConfigMock from '../config/mock/note.config.mock'; import { ClientError, NotInDBError } from '../errors/errors'; import { Group } from '../groups/group.entity'; import { Identity } from '../identity/identity.entity'; @@ -51,7 +52,7 @@ describe('MediaService', () => { imports: [ ConfigModule.forRoot({ isGlobal: true, - load: [mediaConfigMock, appConfigMock], + load: [mediaConfigMock, appConfigMock, noteConfigMock], }), LoggerModule, NotesModule, diff --git a/src/notes/alias.service.spec.ts b/src/notes/alias.service.spec.ts index 80cbd1a4a..9e96901cf 100644 --- a/src/notes/alias.service.spec.ts +++ b/src/notes/alias.service.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -11,6 +11,7 @@ import { Repository } from 'typeorm'; import { AuthToken } from '../auth/auth-token.entity'; import { Author } from '../authors/author.entity'; import appConfigMock from '../config/mock/app.config.mock'; +import noteConfigMock from '../config/mock/note.config.mock'; import { AlreadyInDBError, ForbiddenIdError, @@ -65,7 +66,7 @@ describe('AliasService', () => { imports: [ ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock], + load: [appConfigMock, noteConfigMock], }), LoggerModule, UsersModule, @@ -102,7 +103,7 @@ describe('AliasService', () => { .compile(); const config = module.get(ConfigService); - forbiddenNoteId = config.get('appConfig').forbiddenNoteIds[0]; + forbiddenNoteId = config.get('noteConfig').forbiddenNoteIds[0]; service = module.get(AliasService); noteRepo = module.get>(getRepositoryToken(Note)); aliasRepo = module.get>(getRepositoryToken(Alias)); diff --git a/src/notes/notes.service.spec.ts b/src/notes/notes.service.spec.ts index febf0b540..228e0f9fb 100644 --- a/src/notes/notes.service.spec.ts +++ b/src/notes/notes.service.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -11,6 +11,7 @@ import { Repository } from 'typeorm'; import { AuthToken } from '../auth/auth-token.entity'; import { Author } from '../authors/author.entity'; import appConfigMock from '../config/mock/app.config.mock'; +import noteConfigMock from '../config/mock/note.config.mock'; import { AlreadyInDBError, ForbiddenIdError, @@ -76,7 +77,7 @@ describe('NotesService', () => { imports: [ ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock], + load: [appConfigMock, noteConfigMock], }), LoggerModule, UsersModule, @@ -113,7 +114,7 @@ describe('NotesService', () => { .compile(); const config = module.get(ConfigService); - forbiddenNoteId = config.get('appConfig').forbiddenNoteIds[0]; + forbiddenNoteId = config.get('noteConfig').forbiddenNoteIds[0]; service = module.get(NotesService); noteRepo = module.get>(getRepositoryToken(Note)); revisionRepo = module.get>( diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 1154515ec..99c33904b 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -7,7 +7,7 @@ import { forwardRef, Inject, Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; -import appConfiguration, { AppConfig } from '../config/app.config'; +import noteConfiguration, { NoteConfig } from '../config/note.config'; import { AlreadyInDBError, ForbiddenIdError, @@ -47,8 +47,8 @@ export class NotesService { @Inject(GroupsService) private groupsService: GroupsService, @Inject(forwardRef(() => RevisionsService)) private revisionsService: RevisionsService, - @Inject(appConfiguration.KEY) - private appConfig: AppConfig, + @Inject(noteConfiguration.KEY) + private noteConfig: NoteConfig, ) { this.logger.setContext(NotesService.name); } @@ -227,7 +227,7 @@ export class NotesService { * @throws {ForbiddenIdError} the requested id or alias is forbidden */ checkNoteIdOrAlias(noteIdOrAlias: string): void { - if (this.appConfig.forbiddenNoteIds.includes(noteIdOrAlias)) { + if (this.noteConfig.forbiddenNoteIds.includes(noteIdOrAlias)) { this.logger.debug( `A note with the alias '${noteIdOrAlias}' is forbidden by the administrator.`, 'checkNoteIdOrAlias', diff --git a/src/permissions/permissions.service.spec.ts b/src/permissions/permissions.service.spec.ts index 0e60e2eb6..a76200c6c 100644 --- a/src/permissions/permissions.service.spec.ts +++ b/src/permissions/permissions.service.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -10,6 +10,7 @@ import { getRepositoryToken } from '@nestjs/typeorm'; import { AuthToken } from '../auth/auth-token.entity'; import { Author } from '../authors/author.entity'; import appConfigMock from '../config/mock/app.config.mock'; +import noteConfigMock from '../config/mock/note.config.mock'; import { Group } from '../groups/group.entity'; import { SpecialGroup } from '../groups/groups.special'; import { Identity } from '../identity/identity.entity'; @@ -42,7 +43,7 @@ describe('PermissionsService', () => { NotesModule, ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock], + load: [appConfigMock, noteConfigMock], }), ], }) diff --git a/src/revisions/revisions.service.spec.ts b/src/revisions/revisions.service.spec.ts index aacd68806..20cbc0fbc 100644 --- a/src/revisions/revisions.service.spec.ts +++ b/src/revisions/revisions.service.spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -11,6 +11,7 @@ import { Repository } from 'typeorm'; import { AuthToken } from '../auth/auth-token.entity'; import { Author } from '../authors/author.entity'; import appConfigMock from '../config/mock/app.config.mock'; +import noteConfigMock from '../config/mock/note.config.mock'; import { NotInDBError } from '../errors/errors'; import { Group } from '../groups/group.entity'; import { Identity } from '../identity/identity.entity'; @@ -45,7 +46,7 @@ describe('RevisionsService', () => { LoggerModule, ConfigModule.forRoot({ isGlobal: true, - load: [appConfigMock], + load: [appConfigMock, noteConfigMock], }), ], }) diff --git a/test/private-api/alias.e2e-spec.ts b/test/private-api/alias.e2e-spec.ts index 9a4a47b85..b8b50854d 100644 --- a/test/private-api/alias.e2e-spec.ts +++ b/test/private-api/alias.e2e-spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -25,7 +25,7 @@ describe('Alias', () => { await testSetup.app.init(); forbiddenNoteId = - testSetup.configService.get('appConfig').forbiddenNoteIds[0]; + testSetup.configService.get('noteConfig').forbiddenNoteIds[0]; users = testSetup.users; agent1 = request.agent(testSetup.app.getHttpServer()); diff --git a/test/private-api/history.e2e-spec.ts b/test/private-api/history.e2e-spec.ts index ce62f422e..090b0e048 100644 --- a/test/private-api/history.e2e-spec.ts +++ b/test/private-api/history.e2e-spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -33,12 +33,11 @@ describe('History', () => { testSetup = await TestSetupBuilder.create().build(); forbiddenNoteId = - testSetup.configService.get('appConfig').forbiddenNoteIds[0]; + testSetup.configService.get('noteConfig').forbiddenNoteIds[0]; const moduleRef = testSetup.moduleRef; const config = moduleRef.get(ConfigService); - forbiddenNoteId = config.get('appConfig').forbiddenNoteIds[0]; const authConfig = config.get('authConfig') as AuthConfig; setupSessionMiddleware(testSetup.app, authConfig); diff --git a/test/private-api/notes.e2e-spec.ts b/test/private-api/notes.e2e-spec.ts index 6c99599dd..46cbf6566 100644 --- a/test/private-api/notes.e2e-spec.ts +++ b/test/private-api/notes.e2e-spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -28,7 +28,7 @@ describe('Notes', () => { testSetup = await TestSetupBuilder.create().build(); forbiddenNoteId = - testSetup.configService.get('appConfig').forbiddenNoteIds[0]; + testSetup.configService.get('noteConfig').forbiddenNoteIds[0]; uploadPath = testSetup.configService.get('mediaConfig').backend.filesystem.uploadPath; diff --git a/test/public-api/alias.e2e-spec.ts b/test/public-api/alias.e2e-spec.ts index 942eeefdf..3956e4220 100644 --- a/test/public-api/alias.e2e-spec.ts +++ b/test/public-api/alias.e2e-spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -18,7 +18,7 @@ describe('Alias', () => { beforeEach(async () => { testSetup = await TestSetupBuilder.create().withUsers().withNotes().build(); forbiddenNoteId = - testSetup.configService.get('appConfig').forbiddenNoteIds[0]; + testSetup.configService.get('noteConfig').forbiddenNoteIds[0]; await testSetup.app.init(); diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index 42274cf76..154e95372 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -26,7 +26,7 @@ describe('Notes', () => { testSetup = await TestSetupBuilder.create().withMockAuth().build(); forbiddenNoteId = - testSetup.configService.get('appConfig').forbiddenNoteIds[0]; + testSetup.configService.get('noteConfig').forbiddenNoteIds[0]; uploadPath = testSetup.configService.get('mediaConfig').backend.filesystem.uploadPath; diff --git a/test/test-setup.ts b/test/test-setup.ts index a64fbb959..0ae69ce52 100644 --- a/test/test-setup.ts +++ b/test/test-setup.ts @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -23,6 +23,7 @@ import authConfigMock from '../src/config/mock/auth.config.mock'; import customizationConfigMock from '../src/config/mock/customization.config.mock'; import externalServicesConfigMock from '../src/config/mock/external-services.config.mock'; import mediaConfigMock from '../src/config/mock/media.config.mock'; +import noteConfigMock from '../src/config/mock/note.config.mock'; import { FrontendConfigModule } from '../src/frontend-config/frontend-config.module'; import { GroupsModule } from '../src/groups/groups.module'; import { HistoryModule } from '../src/history/history.module'; @@ -105,6 +106,7 @@ export class TestSetupBuilder { isGlobal: true, load: [ appConfigMock, + noteConfigMock, authConfigMock, mediaConfigMock, customizationConfigMock,