mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 17:56:30 -05:00
Config: Add forbiddenNoteIds to AppConfig
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
2a83c9b2ac
commit
966f5ee2fe
16 changed files with 88 additions and 10 deletions
|
@ -23,6 +23,8 @@ import { HistoryEntry } from '../../../history/history-entry.entity';
|
||||||
import { NoteGroupPermission } from '../../../permissions/note-group-permission.entity';
|
import { NoteGroupPermission } from '../../../permissions/note-group-permission.entity';
|
||||||
import { NoteUserPermission } from '../../../permissions/note-user-permission.entity';
|
import { NoteUserPermission } from '../../../permissions/note-user-permission.entity';
|
||||||
import { Group } from '../../../groups/group.entity';
|
import { Group } from '../../../groups/group.entity';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import appConfigMock from '../../../config/app.config.mock';
|
||||||
|
|
||||||
describe('Me Controller', () => {
|
describe('Me Controller', () => {
|
||||||
let controller: MeController;
|
let controller: MeController;
|
||||||
|
@ -30,7 +32,16 @@ describe('Me Controller', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [MeController],
|
controllers: [MeController],
|
||||||
imports: [UsersModule, HistoryModule, NotesModule, LoggerModule],
|
imports: [
|
||||||
|
UsersModule,
|
||||||
|
HistoryModule,
|
||||||
|
NotesModule,
|
||||||
|
LoggerModule,
|
||||||
|
ConfigModule.forRoot({
|
||||||
|
isGlobal: true,
|
||||||
|
load: [appConfigMock],
|
||||||
|
}),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(User))
|
.overrideProvider(getRepositoryToken(User))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
|
|
@ -26,6 +26,8 @@ import { NoteGroupPermission } from '../../../permissions/note-group-permission.
|
||||||
import { NoteUserPermission } from '../../../permissions/note-user-permission.entity';
|
import { NoteUserPermission } from '../../../permissions/note-user-permission.entity';
|
||||||
import { Group } from '../../../groups/group.entity';
|
import { Group } from '../../../groups/group.entity';
|
||||||
import { GroupsModule } from '../../../groups/groups.module';
|
import { GroupsModule } from '../../../groups/groups.module';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import appConfigMock from '../../../config/app.config.mock';
|
||||||
|
|
||||||
describe('Notes Controller', () => {
|
describe('Notes Controller', () => {
|
||||||
let controller: NotesController;
|
let controller: NotesController;
|
||||||
|
@ -51,6 +53,10 @@ describe('Notes Controller', () => {
|
||||||
LoggerModule,
|
LoggerModule,
|
||||||
PermissionsModule,
|
PermissionsModule,
|
||||||
HistoryModule,
|
HistoryModule,
|
||||||
|
ConfigModule.forRoot({
|
||||||
|
isGlobal: true,
|
||||||
|
load: [appConfigMock],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(Note))
|
.overrideProvider(getRepositoryToken(Note))
|
||||||
|
|
|
@ -8,4 +8,5 @@ import { registerAs } from '@nestjs/config';
|
||||||
|
|
||||||
export default registerAs('appConfig', () => ({
|
export default registerAs('appConfig', () => ({
|
||||||
port: 3000,
|
port: 3000,
|
||||||
|
forbiddenNoteIds: ['forbiddenNoteId'],
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -7,12 +7,13 @@
|
||||||
import { registerAs } from '@nestjs/config';
|
import { registerAs } from '@nestjs/config';
|
||||||
import * as Joi from 'joi';
|
import * as Joi from 'joi';
|
||||||
import { Loglevel } from './loglevel.enum';
|
import { Loglevel } from './loglevel.enum';
|
||||||
import { buildErrorMessage } from './utils';
|
import { buildErrorMessage, toArrayConfig } from './utils';
|
||||||
|
|
||||||
export interface AppConfig {
|
export interface AppConfig {
|
||||||
domain: string;
|
domain: string;
|
||||||
port: number;
|
port: number;
|
||||||
loglevel: Loglevel;
|
loglevel: Loglevel;
|
||||||
|
forbiddenNoteIds: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = Joi.object({
|
const schema = Joi.object({
|
||||||
|
@ -23,6 +24,10 @@ const schema = Joi.object({
|
||||||
.default(Loglevel.WARN)
|
.default(Loglevel.WARN)
|
||||||
.optional()
|
.optional()
|
||||||
.label('HD_LOGLEVEL'),
|
.label('HD_LOGLEVEL'),
|
||||||
|
forbiddenNoteIds: Joi.string()
|
||||||
|
.optional()
|
||||||
|
.default([])
|
||||||
|
.label('HD_FORBIDDEN_NOTE_IDS'),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default registerAs('appConfig', () => {
|
export default registerAs('appConfig', () => {
|
||||||
|
@ -31,6 +36,7 @@ export default registerAs('appConfig', () => {
|
||||||
domain: process.env.HD_DOMAIN,
|
domain: process.env.HD_DOMAIN,
|
||||||
port: parseInt(process.env.PORT) || undefined,
|
port: parseInt(process.env.PORT) || undefined,
|
||||||
loglevel: process.env.HD_LOGLEVEL,
|
loglevel: process.env.HD_LOGLEVEL,
|
||||||
|
forbiddenNoteIds: toArrayConfig(process.env.HD_FORBIDDEN_NOTE_IDS, ','),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
abortEarly: false,
|
abortEarly: false,
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { HistoryEntry } from './history-entry.entity';
|
import { HistoryEntry } from './history-entry.entity';
|
||||||
import { UsersModule } from '../users/users.module';
|
import { UsersModule } from '../users/users.module';
|
||||||
import { NotesModule } from '../notes/notes.module';
|
import { NotesModule } from '../notes/notes.module';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [HistoryService],
|
providers: [HistoryService],
|
||||||
|
@ -20,6 +21,7 @@ import { NotesModule } from '../notes/notes.module';
|
||||||
TypeOrmModule.forFeature([HistoryEntry]),
|
TypeOrmModule.forFeature([HistoryEntry]),
|
||||||
UsersModule,
|
UsersModule,
|
||||||
NotesModule,
|
NotesModule,
|
||||||
|
ConfigModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class HistoryModule {}
|
export class HistoryModule {}
|
||||||
|
|
|
@ -30,6 +30,8 @@ import { NotInDBError } from '../errors/errors';
|
||||||
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
||||||
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import appConfigMock from '../config/app.config.mock';
|
||||||
|
|
||||||
describe('HistoryService', () => {
|
describe('HistoryService', () => {
|
||||||
let service: HistoryService;
|
let service: HistoryService;
|
||||||
|
@ -45,7 +47,15 @@ describe('HistoryService', () => {
|
||||||
useClass: Repository,
|
useClass: Repository,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
imports: [LoggerModule, UsersModule, NotesModule],
|
imports: [
|
||||||
|
LoggerModule,
|
||||||
|
UsersModule,
|
||||||
|
NotesModule,
|
||||||
|
ConfigModule.forRoot({
|
||||||
|
isGlobal: true,
|
||||||
|
load: [appConfigMock],
|
||||||
|
}),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(User))
|
.overrideProvider(getRepositoryToken(User))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
|
|
@ -34,6 +34,7 @@ import { ClientError, NotInDBError, PermissionError } from '../errors/errors';
|
||||||
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
||||||
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
|
import appConfigMock from '../../src/config/app.config.mock';
|
||||||
|
|
||||||
describe('MediaService', () => {
|
describe('MediaService', () => {
|
||||||
let service: MediaService;
|
let service: MediaService;
|
||||||
|
@ -54,7 +55,7 @@ describe('MediaService', () => {
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot({
|
ConfigModule.forRoot({
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
load: [mediaConfigMock],
|
load: [mediaConfigMock, appConfigMock],
|
||||||
}),
|
}),
|
||||||
LoggerModule,
|
LoggerModule,
|
||||||
NotesModule,
|
NotesModule,
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { Tag } from './tag.entity';
|
||||||
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
||||||
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||||
import { GroupsModule } from '../groups/groups.module';
|
import { GroupsModule } from '../groups/groups.module';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -30,6 +31,7 @@ import { GroupsModule } from '../groups/groups.module';
|
||||||
UsersModule,
|
UsersModule,
|
||||||
GroupsModule,
|
GroupsModule,
|
||||||
LoggerModule,
|
LoggerModule,
|
||||||
|
ConfigModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [NotesService],
|
providers: [NotesService],
|
||||||
|
|
|
@ -37,6 +37,8 @@ import { NoteGroupPermission } from '../permissions/note-group-permission.entity
|
||||||
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||||
import { GroupsModule } from '../groups/groups.module';
|
import { GroupsModule } from '../groups/groups.module';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
|
import appConfigMock from '../config/app.config.mock';
|
||||||
|
|
||||||
describe('NotesService', () => {
|
describe('NotesService', () => {
|
||||||
let service: NotesService;
|
let service: NotesService;
|
||||||
|
@ -58,7 +60,16 @@ describe('NotesService', () => {
|
||||||
useClass: Repository,
|
useClass: Repository,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
imports: [LoggerModule, UsersModule, GroupsModule, RevisionsModule],
|
imports: [
|
||||||
|
ConfigModule.forRoot({
|
||||||
|
isGlobal: true,
|
||||||
|
load: [appConfigMock],
|
||||||
|
}),
|
||||||
|
LoggerModule,
|
||||||
|
UsersModule,
|
||||||
|
GroupsModule,
|
||||||
|
RevisionsModule,
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(Note))
|
.overrideProvider(getRepositoryToken(Note))
|
||||||
.useClass(Repository)
|
.useClass(Repository)
|
||||||
|
|
|
@ -30,6 +30,7 @@ import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||||
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
||||||
import { GroupsService } from '../groups/groups.service';
|
import { GroupsService } from '../groups/groups.service';
|
||||||
import { checkArrayForDuplicates } from '../utils/arrayDuplicatCheck';
|
import { checkArrayForDuplicates } from '../utils/arrayDuplicatCheck';
|
||||||
|
import appConfiguration, { AppConfig } from '../config/app.config';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NotesService {
|
export class NotesService {
|
||||||
|
@ -41,6 +42,8 @@ export class NotesService {
|
||||||
@Inject(GroupsService) private groupsService: GroupsService,
|
@Inject(GroupsService) private groupsService: GroupsService,
|
||||||
@Inject(forwardRef(() => RevisionsService))
|
@Inject(forwardRef(() => RevisionsService))
|
||||||
private revisionsService: RevisionsService,
|
private revisionsService: RevisionsService,
|
||||||
|
@Inject(appConfiguration.KEY)
|
||||||
|
private appConfig: AppConfig,
|
||||||
) {
|
) {
|
||||||
this.logger.setContext(NotesService.name);
|
this.logger.setContext(NotesService.name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,8 @@ import { NoteGroupPermission } from './note-group-permission.entity';
|
||||||
import { NoteUserPermission } from './note-user-permission.entity';
|
import { NoteUserPermission } from './note-user-permission.entity';
|
||||||
import { PermissionsModule } from './permissions.module';
|
import { PermissionsModule } from './permissions.module';
|
||||||
import { GuestPermission, PermissionsService } from './permissions.service';
|
import { GuestPermission, PermissionsService } from './permissions.service';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import appConfigMock from '../config/app.config.mock';
|
||||||
|
|
||||||
describe('PermissionsService', () => {
|
describe('PermissionsService', () => {
|
||||||
let permissionsService: PermissionsService;
|
let permissionsService: PermissionsService;
|
||||||
|
@ -35,7 +37,16 @@ describe('PermissionsService', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [PermissionsService],
|
providers: [PermissionsService],
|
||||||
imports: [PermissionsModule, UsersModule, LoggerModule, NotesModule],
|
imports: [
|
||||||
|
PermissionsModule,
|
||||||
|
UsersModule,
|
||||||
|
LoggerModule,
|
||||||
|
NotesModule,
|
||||||
|
ConfigModule.forRoot({
|
||||||
|
isGlobal: true,
|
||||||
|
load: [appConfigMock],
|
||||||
|
}),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(User))
|
.overrideProvider(getRepositoryToken(User))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
|
|
@ -11,12 +11,14 @@ import { NotesModule } from '../notes/notes.module';
|
||||||
import { Authorship } from './authorship.entity';
|
import { Authorship } from './authorship.entity';
|
||||||
import { Revision } from './revision.entity';
|
import { Revision } from './revision.entity';
|
||||||
import { RevisionsService } from './revisions.service';
|
import { RevisionsService } from './revisions.service';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([Revision, Authorship]),
|
TypeOrmModule.forFeature([Revision, Authorship]),
|
||||||
forwardRef(() => NotesModule),
|
forwardRef(() => NotesModule),
|
||||||
LoggerModule,
|
LoggerModule,
|
||||||
|
ConfigModule,
|
||||||
],
|
],
|
||||||
providers: [RevisionsService],
|
providers: [RevisionsService],
|
||||||
exports: [RevisionsService],
|
exports: [RevisionsService],
|
||||||
|
|
|
@ -20,6 +20,8 @@ import { Tag } from '../notes/tag.entity';
|
||||||
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
import { NoteGroupPermission } from '../permissions/note-group-permission.entity';
|
||||||
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
import { NoteUserPermission } from '../permissions/note-user-permission.entity';
|
||||||
import { Group } from '../groups/group.entity';
|
import { Group } from '../groups/group.entity';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import appConfigMock from '../config/app.config.mock';
|
||||||
|
|
||||||
describe('RevisionsService', () => {
|
describe('RevisionsService', () => {
|
||||||
let service: RevisionsService;
|
let service: RevisionsService;
|
||||||
|
@ -33,7 +35,14 @@ describe('RevisionsService', () => {
|
||||||
useValue: {},
|
useValue: {},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
imports: [NotesModule, LoggerModule],
|
imports: [
|
||||||
|
NotesModule,
|
||||||
|
LoggerModule,
|
||||||
|
ConfigModule.forRoot({
|
||||||
|
isGlobal: true,
|
||||||
|
load: [appConfigMock],
|
||||||
|
}),
|
||||||
|
],
|
||||||
})
|
})
|
||||||
.overrideProvider(getRepositoryToken(Authorship))
|
.overrideProvider(getRepositoryToken(Authorship))
|
||||||
.useValue({})
|
.useValue({})
|
||||||
|
|
|
@ -31,6 +31,7 @@ import { UsersModule } from '../../src/users/users.module';
|
||||||
import { HistoryModule } from '../../src/history/history.module';
|
import { HistoryModule } from '../../src/history/history.module';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import mediaConfigMock from '../../src/config/media.config.mock';
|
import mediaConfigMock from '../../src/config/media.config.mock';
|
||||||
|
import appConfigMock from '../../src/config/app.config.mock';
|
||||||
import { User } from '../../src/users/user.entity';
|
import { User } from '../../src/users/user.entity';
|
||||||
|
|
||||||
// TODO Tests have to be reworked using UserService functions
|
// TODO Tests have to be reworked using UserService functions
|
||||||
|
@ -47,7 +48,7 @@ describe('Notes', () => {
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot({
|
ConfigModule.forRoot({
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
load: [mediaConfigMock],
|
load: [mediaConfigMock, appConfigMock],
|
||||||
}),
|
}),
|
||||||
PublicApiModule,
|
PublicApiModule,
|
||||||
NotesModule,
|
NotesModule,
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { promises as fs } from 'fs';
|
||||||
import * as request from 'supertest';
|
import * as request from 'supertest';
|
||||||
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
||||||
import mediaConfigMock from '../../src/config/media.config.mock';
|
import mediaConfigMock from '../../src/config/media.config.mock';
|
||||||
|
import appConfigMock from '../../src/config/app.config.mock';
|
||||||
import { GroupsModule } from '../../src/groups/groups.module';
|
import { GroupsModule } from '../../src/groups/groups.module';
|
||||||
import { LoggerModule } from '../../src/logger/logger.module';
|
import { LoggerModule } from '../../src/logger/logger.module';
|
||||||
import { NestConsoleLoggerService } from '../../src/logger/nest-console-logger.service';
|
import { NestConsoleLoggerService } from '../../src/logger/nest-console-logger.service';
|
||||||
|
@ -40,7 +41,7 @@ describe('Notes', () => {
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot({
|
ConfigModule.forRoot({
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
load: [mediaConfigMock],
|
load: [mediaConfigMock, appConfigMock],
|
||||||
}),
|
}),
|
||||||
PublicApiModule,
|
PublicApiModule,
|
||||||
MediaModule,
|
MediaModule,
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import * as request from 'supertest';
|
import * as request from 'supertest';
|
||||||
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
import { PublicApiModule } from '../../src/api/public/public-api.module';
|
||||||
import mediaConfigMock from '../../src/config/media.config.mock';
|
import mediaConfigMock from '../../src/config/media.config.mock';
|
||||||
|
import appConfigMock from '../../src/config/app.config.mock';
|
||||||
import { NotInDBError } from '../../src/errors/errors';
|
import { NotInDBError } from '../../src/errors/errors';
|
||||||
import { GroupsModule } from '../../src/groups/groups.module';
|
import { GroupsModule } from '../../src/groups/groups.module';
|
||||||
import { LoggerModule } from '../../src/logger/logger.module';
|
import { LoggerModule } from '../../src/logger/logger.module';
|
||||||
|
@ -40,7 +41,7 @@ describe('Notes', () => {
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot({
|
ConfigModule.forRoot({
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
load: [mediaConfigMock],
|
load: [mediaConfigMock, appConfigMock],
|
||||||
}),
|
}),
|
||||||
PublicApiModule,
|
PublicApiModule,
|
||||||
NotesModule,
|
NotesModule,
|
||||||
|
|
Loading…
Reference in a new issue