diff --git a/src/api/public/me/me.controller.spec.ts b/src/api/public/me/me.controller.spec.ts index 5b8d6f7ff..4f1daf4a0 100644 --- a/src/api/public/me/me.controller.spec.ts +++ b/src/api/public/me/me.controller.spec.ts @@ -23,6 +23,8 @@ import { HistoryEntry } from '../../../history/history-entry.entity'; import { NoteGroupPermission } from '../../../permissions/note-group-permission.entity'; import { NoteUserPermission } from '../../../permissions/note-user-permission.entity'; import { Group } from '../../../groups/group.entity'; +import { ConfigModule } from '@nestjs/config'; +import appConfigMock from '../../../config/app.config.mock'; describe('Me Controller', () => { let controller: MeController; @@ -30,7 +32,16 @@ describe('Me Controller', () => { beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ controllers: [MeController], - imports: [UsersModule, HistoryModule, NotesModule, LoggerModule], + imports: [ + UsersModule, + HistoryModule, + NotesModule, + LoggerModule, + ConfigModule.forRoot({ + isGlobal: true, + load: [appConfigMock], + }), + ], }) .overrideProvider(getRepositoryToken(User)) .useValue({}) diff --git a/src/api/public/notes/notes.controller.spec.ts b/src/api/public/notes/notes.controller.spec.ts index 187e5ef1b..117b4fd9f 100644 --- a/src/api/public/notes/notes.controller.spec.ts +++ b/src/api/public/notes/notes.controller.spec.ts @@ -26,6 +26,8 @@ import { NoteGroupPermission } from '../../../permissions/note-group-permission. import { NoteUserPermission } from '../../../permissions/note-user-permission.entity'; import { Group } from '../../../groups/group.entity'; import { GroupsModule } from '../../../groups/groups.module'; +import { ConfigModule } from '@nestjs/config'; +import appConfigMock from '../../../config/app.config.mock'; describe('Notes Controller', () => { let controller: NotesController; @@ -51,6 +53,10 @@ describe('Notes Controller', () => { LoggerModule, PermissionsModule, HistoryModule, + ConfigModule.forRoot({ + isGlobal: true, + load: [appConfigMock], + }), ], }) .overrideProvider(getRepositoryToken(Note)) diff --git a/src/config/app.config.mock.ts b/src/config/app.config.mock.ts index 9b013a75c..6e23d5dfb 100644 --- a/src/config/app.config.mock.ts +++ b/src/config/app.config.mock.ts @@ -8,4 +8,5 @@ import { registerAs } from '@nestjs/config'; export default registerAs('appConfig', () => ({ port: 3000, + forbiddenNoteIds: ['forbiddenNoteId'], })); diff --git a/src/config/app.config.ts b/src/config/app.config.ts index 85b52d70b..c25b19628 100644 --- a/src/config/app.config.ts +++ b/src/config/app.config.ts @@ -7,12 +7,13 @@ import { registerAs } from '@nestjs/config'; import * as Joi from 'joi'; import { Loglevel } from './loglevel.enum'; -import { buildErrorMessage } from './utils'; +import { buildErrorMessage, toArrayConfig } from './utils'; export interface AppConfig { domain: string; port: number; loglevel: Loglevel; + forbiddenNoteIds: string[]; } const schema = Joi.object({ @@ -23,6 +24,10 @@ const schema = Joi.object({ .default(Loglevel.WARN) .optional() .label('HD_LOGLEVEL'), + forbiddenNoteIds: Joi.string() + .optional() + .default([]) + .label('HD_FORBIDDEN_NOTE_IDS'), }); export default registerAs('appConfig', () => { @@ -31,6 +36,7 @@ export default registerAs('appConfig', () => { domain: process.env.HD_DOMAIN, port: parseInt(process.env.PORT) || undefined, loglevel: process.env.HD_LOGLEVEL, + forbiddenNoteIds: toArrayConfig(process.env.HD_FORBIDDEN_NOTE_IDS, ','), }, { abortEarly: false, diff --git a/src/history/history.module.ts b/src/history/history.module.ts index 410d50863..20bf1746d 100644 --- a/src/history/history.module.ts +++ b/src/history/history.module.ts @@ -11,6 +11,7 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { HistoryEntry } from './history-entry.entity'; import { UsersModule } from '../users/users.module'; import { NotesModule } from '../notes/notes.module'; +import { ConfigModule } from '@nestjs/config'; @Module({ providers: [HistoryService], @@ -20,6 +21,7 @@ import { NotesModule } from '../notes/notes.module'; TypeOrmModule.forFeature([HistoryEntry]), UsersModule, NotesModule, + ConfigModule, ], }) export class HistoryModule {} diff --git a/src/history/history.service.spec.ts b/src/history/history.service.spec.ts index fe104eb1c..9956ecc74 100644 --- a/src/history/history.service.spec.ts +++ b/src/history/history.service.spec.ts @@ -30,6 +30,8 @@ import { NotInDBError } from '../errors/errors'; import { NoteGroupPermission } from '../permissions/note-group-permission.entity'; import { NoteUserPermission } from '../permissions/note-user-permission.entity'; import { Group } from '../groups/group.entity'; +import { ConfigModule } from '@nestjs/config'; +import appConfigMock from '../config/app.config.mock'; describe('HistoryService', () => { let service: HistoryService; @@ -45,7 +47,15 @@ describe('HistoryService', () => { useClass: Repository, }, ], - imports: [LoggerModule, UsersModule, NotesModule], + imports: [ + LoggerModule, + UsersModule, + NotesModule, + ConfigModule.forRoot({ + isGlobal: true, + load: [appConfigMock], + }), + ], }) .overrideProvider(getRepositoryToken(User)) .useValue({}) diff --git a/src/media/media.service.spec.ts b/src/media/media.service.spec.ts index d84a98dba..d04017a79 100644 --- a/src/media/media.service.spec.ts +++ b/src/media/media.service.spec.ts @@ -34,6 +34,7 @@ import { ClientError, NotInDBError, PermissionError } from '../errors/errors'; import { NoteGroupPermission } from '../permissions/note-group-permission.entity'; import { NoteUserPermission } from '../permissions/note-user-permission.entity'; import { Group } from '../groups/group.entity'; +import appConfigMock from '../../src/config/app.config.mock'; describe('MediaService', () => { let service: MediaService; @@ -54,7 +55,7 @@ describe('MediaService', () => { imports: [ ConfigModule.forRoot({ isGlobal: true, - load: [mediaConfigMock], + load: [mediaConfigMock, appConfigMock], }), LoggerModule, NotesModule, diff --git a/src/notes/notes.module.ts b/src/notes/notes.module.ts index 609489ac3..685752038 100644 --- a/src/notes/notes.module.ts +++ b/src/notes/notes.module.ts @@ -16,6 +16,7 @@ import { Tag } from './tag.entity'; import { NoteGroupPermission } from '../permissions/note-group-permission.entity'; import { NoteUserPermission } from '../permissions/note-user-permission.entity'; import { GroupsModule } from '../groups/groups.module'; +import { ConfigModule } from '@nestjs/config'; @Module({ imports: [ @@ -30,6 +31,7 @@ import { GroupsModule } from '../groups/groups.module'; UsersModule, GroupsModule, LoggerModule, + ConfigModule, ], controllers: [], providers: [NotesService], diff --git a/src/notes/notes.service.spec.ts b/src/notes/notes.service.spec.ts index f1858f30b..6ffca14b1 100644 --- a/src/notes/notes.service.spec.ts +++ b/src/notes/notes.service.spec.ts @@ -37,6 +37,8 @@ import { NoteGroupPermission } from '../permissions/note-group-permission.entity import { NoteUserPermission } from '../permissions/note-user-permission.entity'; import { GroupsModule } from '../groups/groups.module'; import { Group } from '../groups/group.entity'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +import appConfigMock from '../config/app.config.mock'; describe('NotesService', () => { let service: NotesService; @@ -58,7 +60,16 @@ describe('NotesService', () => { useClass: Repository, }, ], - imports: [LoggerModule, UsersModule, GroupsModule, RevisionsModule], + imports: [ + ConfigModule.forRoot({ + isGlobal: true, + load: [appConfigMock], + }), + LoggerModule, + UsersModule, + GroupsModule, + RevisionsModule, + ], }) .overrideProvider(getRepositoryToken(Note)) .useClass(Repository) diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 0ff2e7112..0ecbbe57f 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -30,6 +30,7 @@ import { NoteUserPermission } from '../permissions/note-user-permission.entity'; import { NoteGroupPermission } from '../permissions/note-group-permission.entity'; import { GroupsService } from '../groups/groups.service'; import { checkArrayForDuplicates } from '../utils/arrayDuplicatCheck'; +import appConfiguration, { AppConfig } from '../config/app.config'; @Injectable() export class NotesService { @@ -41,6 +42,8 @@ export class NotesService { @Inject(GroupsService) private groupsService: GroupsService, @Inject(forwardRef(() => RevisionsService)) private revisionsService: RevisionsService, + @Inject(appConfiguration.KEY) + private appConfig: AppConfig, ) { this.logger.setContext(NotesService.name); } diff --git a/src/permissions/permissions.service.spec.ts b/src/permissions/permissions.service.spec.ts index a5bcde491..c612b360a 100644 --- a/src/permissions/permissions.service.spec.ts +++ b/src/permissions/permissions.service.spec.ts @@ -28,6 +28,8 @@ import { NoteGroupPermission } from './note-group-permission.entity'; import { NoteUserPermission } from './note-user-permission.entity'; import { PermissionsModule } from './permissions.module'; import { GuestPermission, PermissionsService } from './permissions.service'; +import { ConfigModule } from '@nestjs/config'; +import appConfigMock from '../config/app.config.mock'; describe('PermissionsService', () => { let permissionsService: PermissionsService; @@ -35,7 +37,16 @@ describe('PermissionsService', () => { beforeAll(async () => { const module: TestingModule = await Test.createTestingModule({ providers: [PermissionsService], - imports: [PermissionsModule, UsersModule, LoggerModule, NotesModule], + imports: [ + PermissionsModule, + UsersModule, + LoggerModule, + NotesModule, + ConfigModule.forRoot({ + isGlobal: true, + load: [appConfigMock], + }), + ], }) .overrideProvider(getRepositoryToken(User)) .useValue({}) diff --git a/src/revisions/revisions.module.ts b/src/revisions/revisions.module.ts index 80b240523..7ecc61491 100644 --- a/src/revisions/revisions.module.ts +++ b/src/revisions/revisions.module.ts @@ -11,12 +11,14 @@ import { NotesModule } from '../notes/notes.module'; import { Authorship } from './authorship.entity'; import { Revision } from './revision.entity'; import { RevisionsService } from './revisions.service'; +import { ConfigModule } from '@nestjs/config'; @Module({ imports: [ TypeOrmModule.forFeature([Revision, Authorship]), forwardRef(() => NotesModule), LoggerModule, + ConfigModule, ], providers: [RevisionsService], exports: [RevisionsService], diff --git a/src/revisions/revisions.service.spec.ts b/src/revisions/revisions.service.spec.ts index fe82a346f..ada09533f 100644 --- a/src/revisions/revisions.service.spec.ts +++ b/src/revisions/revisions.service.spec.ts @@ -20,6 +20,8 @@ import { Tag } from '../notes/tag.entity'; import { NoteGroupPermission } from '../permissions/note-group-permission.entity'; import { NoteUserPermission } from '../permissions/note-user-permission.entity'; import { Group } from '../groups/group.entity'; +import { ConfigModule } from '@nestjs/config'; +import appConfigMock from '../config/app.config.mock'; describe('RevisionsService', () => { let service: RevisionsService; @@ -33,7 +35,14 @@ describe('RevisionsService', () => { useValue: {}, }, ], - imports: [NotesModule, LoggerModule], + imports: [ + NotesModule, + LoggerModule, + ConfigModule.forRoot({ + isGlobal: true, + load: [appConfigMock], + }), + ], }) .overrideProvider(getRepositoryToken(Authorship)) .useValue({}) diff --git a/test/public-api/me.e2e-spec.ts b/test/public-api/me.e2e-spec.ts index aa4733080..a26488bc9 100644 --- a/test/public-api/me.e2e-spec.ts +++ b/test/public-api/me.e2e-spec.ts @@ -31,6 +31,7 @@ import { UsersModule } from '../../src/users/users.module'; import { HistoryModule } from '../../src/history/history.module'; import { ConfigModule } from '@nestjs/config'; import mediaConfigMock from '../../src/config/media.config.mock'; +import appConfigMock from '../../src/config/app.config.mock'; import { User } from '../../src/users/user.entity'; // TODO Tests have to be reworked using UserService functions @@ -47,7 +48,7 @@ describe('Notes', () => { imports: [ ConfigModule.forRoot({ isGlobal: true, - load: [mediaConfigMock], + load: [mediaConfigMock, appConfigMock], }), PublicApiModule, NotesModule, diff --git a/test/public-api/media.e2e-spec.ts b/test/public-api/media.e2e-spec.ts index 89843b1cf..0c5d67ad1 100644 --- a/test/public-api/media.e2e-spec.ts +++ b/test/public-api/media.e2e-spec.ts @@ -17,6 +17,7 @@ import { promises as fs } from 'fs'; import * as request from 'supertest'; import { PublicApiModule } from '../../src/api/public/public-api.module'; import mediaConfigMock from '../../src/config/media.config.mock'; +import appConfigMock from '../../src/config/app.config.mock'; import { GroupsModule } from '../../src/groups/groups.module'; import { LoggerModule } from '../../src/logger/logger.module'; import { NestConsoleLoggerService } from '../../src/logger/nest-console-logger.service'; @@ -40,7 +41,7 @@ describe('Notes', () => { imports: [ ConfigModule.forRoot({ isGlobal: true, - load: [mediaConfigMock], + load: [mediaConfigMock, appConfigMock], }), PublicApiModule, MediaModule, diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index 4aaa18ef1..04fbc174d 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -16,6 +16,7 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import * as request from 'supertest'; import { PublicApiModule } from '../../src/api/public/public-api.module'; import mediaConfigMock from '../../src/config/media.config.mock'; +import appConfigMock from '../../src/config/app.config.mock'; import { NotInDBError } from '../../src/errors/errors'; import { GroupsModule } from '../../src/groups/groups.module'; import { LoggerModule } from '../../src/logger/logger.module'; @@ -40,7 +41,7 @@ describe('Notes', () => { imports: [ ConfigModule.forRoot({ isGlobal: true, - load: [mediaConfigMock], + load: [mediaConfigMock, appConfigMock], }), PublicApiModule, NotesModule,