Config: Add forbiddenNoteIds to AppConfig

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-02-20 22:15:04 +01:00 committed by David Mehren
parent 2a83c9b2ac
commit 966f5ee2fe
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
16 changed files with 88 additions and 10 deletions

View file

@ -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({})

View file

@ -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))

View file

@ -8,4 +8,5 @@ import { registerAs } from '@nestjs/config';
export default registerAs('appConfig', () => ({
port: 3000,
forbiddenNoteIds: ['forbiddenNoteId'],
}));

View file

@ -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,

View file

@ -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 {}

View file

@ -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({})

View file

@ -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,

View file

@ -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],

View file

@ -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)

View file

@ -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);
}

View file

@ -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({})

View file

@ -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],

View file

@ -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({})

View file

@ -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,

View file

@ -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,

View file

@ -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,