feat: setupSpecialGroups in bootstrap

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-10-31 00:06:55 +02:00 committed by David Mehren
parent bcf35c61a5
commit 0470497ccb
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 37 additions and 0 deletions

View file

@ -14,6 +14,7 @@ import { AuthConfig } from './config/auth.config';
import { MediaConfig } from './config/media.config';
import { ConsoleLoggerService } from './logger/console-logger.service';
import { BackendType } from './media/backends/backend-type.enum';
import { setupSpecialGroups } from './utils/createSpecialGroups';
import { setupFrontendProxy } from './utils/frontend-integration';
import { setupSessionMiddleware } from './utils/session';
import { setupValidationPipe } from './utils/setup-pipes';
@ -51,6 +52,8 @@ async function bootstrap(): Promise<void> {
setupFrontendProxy(app, logger);
}
await setupSpecialGroups(app);
setupSessionMiddleware(app, authConfig);
app.enableCors({

View file

@ -0,0 +1,34 @@
/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { NestExpressApplication } from '@nestjs/platform-express';
import { AlreadyInDBError } from '../errors/errors';
import { GroupsService } from '../groups/groups.service';
import { SpecialGroup } from '../groups/groups.special';
export async function setupSpecialGroups(
app: NestExpressApplication,
): Promise<void> {
const groupService = app.get<GroupsService>(GroupsService);
try {
await groupService.createGroup(
SpecialGroup.EVERYONE,
SpecialGroup.EVERYONE,
true,
);
await groupService.createGroup(
SpecialGroup.LOGGED_IN,
SpecialGroup.LOGGED_IN,
true,
);
} catch (e) {
if (e instanceof AlreadyInDBError) {
// It's no problem if the special groups already exist
return;
}
throw e;
}
}