Skip to content

Commit

Permalink
BC-8075 Switch admin-api-server configuration flow (#5239)
Browse files Browse the repository at this point in the history
  • Loading branch information
CeEv authored Sep 25, 2024
1 parent 7425d58 commit b20156a
Show file tree
Hide file tree
Showing 64 changed files with 260 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InterceptorConfig } from '@shared/common';
import { LoggerConfig } from '../logger';
import { LoggerConfig } from './logger';

export interface CoreModuleConfig extends InterceptorConfig, LoggerConfig {}
2 changes: 1 addition & 1 deletion apps/server/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { CoreModule } from './core.module';
export { DomainErrorHandler } from './error';
export * from './interfaces';
export { CoreModuleConfig } from './core.config';
1 change: 0 additions & 1 deletion apps/server/src/core/interfaces/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions apps/server/src/core/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './logger';
export * from './error-logger';
export * from './types';
export * from './logging.utils';
export { LoggerConfig } from './logger.config';
1 change: 0 additions & 1 deletion apps/server/src/core/logger/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './logger-config';
export * from './legacy-logger.interface';
export * from './loggable';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface LoggerConfig {
NEST_LOG_LEVEL: string;
EXIT_ON_ERROR?: boolean;
EXIT_ON_ERROR: boolean;
}
2 changes: 1 addition & 1 deletion apps/server/src/core/logger/logger.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ConfigService } from '@nestjs/config';
import { utilities, WinstonModule } from 'nest-winston';
import winston from 'winston';
import { ErrorLogger } from './error-logger';
import { LoggerConfig } from './interfaces';
import { LoggerConfig } from './logger.config';
import { LegacyLogger } from './legacy-logger.service';
import { Logger } from './logger';

Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/infra/auth-guard/auth-guard.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface AuthGuardConfig {
ADMIN_API__ALLOWED_API_KEYS: string[];
JWT_AUD: string;
JWT_LIFETIME: string;
AUTHENTICATION: string;
}
1 change: 1 addition & 0 deletions apps/server/src/infra/auth-guard/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { JwtValidationAdapter } from './adapter';
export { AuthGuardModule } from './auth-guard.module';
export { AuthGuardConfig } from './auth-guard.config';
export { XApiKeyConfig, authConfig } from './config';
export { CurrentUser, JWT, JwtAuthentication } from './decorator';
// JwtAuthGuard only exported because api tests still overried this guard.
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/infra/calendar/calendar.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LoggerConfig } from '@src/core/logger';

export interface CalendarConfig extends LoggerConfig {}
3 changes: 2 additions & 1 deletion apps/server/src/infra/calendar/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './calendar.module';
export { CalendarModule } from './calendar.module';
export * from './service/calendar.service';
export * from './dto/calendar-event.dto';
export { CalendarConfig } from './calendar.config';
5 changes: 4 additions & 1 deletion apps/server/src/modules/account/account-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export interface AccountConfig {
import { LoggerConfig } from '@src/core/logger';
import { SystemConfig } from '@modules/system';

export interface AccountConfig extends LoggerConfig, SystemConfig {
LOGIN_BLOCK_TIME: number;
TEACHER_STUDENT_VISIBILITY__IS_CONFIGURABLE: boolean;
FEATURE_IDENTITY_MANAGEMENT_LOGIN_ENABLED: boolean;
Expand Down
3 changes: 1 addition & 2 deletions apps/server/src/modules/account/account.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { IdentityManagementModule } from '@infra/identity-management';
import { SystemModule } from '@modules/system';
import { Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

import { CqrsModule } from '@nestjs/cqrs';
import { UserRepo } from '@shared/repo';
import { LoggerModule } from '@src/core/logger/logger.module';
Expand All @@ -23,7 +22,7 @@ function accountIdmToDtoMapperFactory(configService: ConfigService<AccountConfig
@Module({
imports: [CqrsModule, IdentityManagementModule, SystemModule, LoggerModule],
providers: [
UserRepo,
UserRepo, // should not be added as provider
AccountRepo,
AccountServiceDb,
AccountServiceIdm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ export class AccountService extends AbstractAccountService implements DeletionSe
if (updateUser) {
try {
await this.userRepo.save(user);
} catch (err) {
} catch (err: unknown) {
throw new EntityNotFoundError(User.name);
}
}
if (updateAccount) {
try {
await this.save(accountSave);
} catch (err) {
} catch (err: unknown) {
if (err instanceof ValidationError) {
throw err;
}
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/modules/authorization/authorization.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LoggerConfig } from '@src/core/logger';

export interface AuthorizationConfig extends LoggerConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { FeathersAuthorizationService, FeathersAuthProvider } from './feathers';
exports: [
FeathersAuthorizationService,
AuthorizationService,
SystemRule,
SystemRule, // Why export? This is a no go!
AuthorizationInjectionService,
AuthorizationHelper,
],
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/authorization/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { AuthorizationModule } from './authorization.module';
export { AuthorizationConfig } from './authorization.config';
export {
// Action should not be exported, but hard to solve for now. The AuthorizationContextBuilder is the prefared way
Action,
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/modules/class/class.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ClassConfig {}
5 changes: 3 additions & 2 deletions apps/server/src/modules/class/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './class.module';
export { ClassModule } from './class.module';
export * from './domain';
export * from './service';
export { ClassConfig } from './class.config';
export { ClassService } from './service';
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { LegacyLogger } from '@src/core/logger';
import { DomainDeletionReportBuilder } from '../../domain/builder';
import { DeletionLog, DeletionRequest } from '../../domain/do';
import { DataDeletedEvent, UserDeletedEvent } from '../../domain/event';
import { DeletionConfig, DomainDeletionReport } from '../../domain/interface';
import { DomainDeletionReport } from '../../domain/interface';
import { DeletionLogService, DeletionRequestService } from '../../domain/service';
import { DeletionRequestLogResponseBuilder } from '../builder';
import { DeletionRequestBodyProps, DeletionRequestLogResponse, DeletionRequestResponse } from '../controller/dto';
import { DeletionTargetRefBuilder } from '../controller/dto/builder';
import { DeletionConfig } from '../../deletion.config';

@Injectable()
@EventsHandler(DataDeletedEvent)
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/deletion/deletion-api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DeletionExecutionsController } from './api/controller/deletion-executio
import { DeletionRequestsController } from './api/controller/deletion-requests.controller';
import { DeletionRequestUc } from './api/uc';

// The most of this imports should not be part of the api module.
@Module({
imports: [
CalendarModule,
Expand Down
24 changes: 24 additions & 0 deletions apps/server/src/modules/deletion/deletion.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { LoggerConfig } from '@src/core/logger';
import { CalendarConfig } from '@src/infra/calendar';
import { ClassConfig } from '@modules/class';
import { XApiKeyConfig } from '@infra/auth-guard';
import { NewsConfig } from '@modules/news';
import { TeamsConfig } from '@modules/teams';
import { PseudonymConfig } from '@modules/pseudonym';
import { FilesConfig } from '@modules/files';
import { RocketChatUserConfig } from '@modules/rocketchat-user';

export interface DeletionConfig
extends LoggerConfig,
CalendarConfig,
ClassConfig,
NewsConfig,
TeamsConfig,
PseudonymConfig,
FilesConfig,
RocketChatUserConfig,
XApiKeyConfig {
ADMIN_API__MODIFICATION_THRESHOLD_MS: number;
ADMIN_API__MAX_CONCURRENT_DELETION_REQUESTS: number;
ADMIN_API__DELETION_DELAY_MILLISECONDS: number;
}

This file was deleted.

1 change: 0 additions & 1 deletion apps/server/src/modules/deletion/domain/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from './deletion-service';
export * from './domain-deletion-report';
export * from './domain-operation-report';
export * from './deletion-target-ref';
export * from './deletion-config';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConfigService } from '@nestjs/config';
import { DeletionRequestRepo } from '../../repo';
import { DeletionRequest } from '../do';
import { DomainName, StatusModel } from '../types';
import { DeletionConfig } from '../interface';
import { DeletionConfig } from '../../deletion.config';

@Injectable()
export class DeletionRequestService {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/deletion/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export { DeletionModule } from './deletion.module';
export { DeletionConfig } from './deletion.config';
export { DataDeletedEvent, UserDeletedEvent } from './domain/event';
export { DomainDeletionReportBuilder, DomainOperationReportBuilder } from './domain/builder';
export { DomainName, OperationType, StatusModel } from './domain/types';
export { DeletionService, DomainDeletionReport, DomainOperationReport } from './domain/interface';
export { DataDeletionDomainOperationLoggable } from './domain/loggable';
export { DeletionErrorLoggableException } from './domain/loggable-exception';
export { OperationReportHelper } from './domain/helper';
export { DeletionConfig } from './domain/interface';
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const fileStorageConfig: FileStorageConfig = {
USE_STREAM_TO_ANTIVIRUS: Configuration.get('FILES_STORAGE__USE_STREAM_TO_ANTIVIRUS') as boolean,
...authorizationClientConfig,
...defaultConfig,
EXIT_ON_ERROR: Configuration.get('EXIT_ON_ERROR') as boolean,
};

// The configurations lookup
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/modules/files/files.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LoggerConfig } from '@src/core/logger';

export interface FilesConfig extends LoggerConfig {}
3 changes: 2 additions & 1 deletion apps/server/src/modules/files/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './files.module';
export { FilesModule } from './files.module';
export { FilesConfig } from './files.config';
export * from './service';
2 changes: 2 additions & 0 deletions apps/server/src/modules/group/group.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface GroupConfig {}
3 changes: 2 additions & 1 deletion apps/server/src/modules/group/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './group.module';
export { GroupModule } from './group.module';
export { GroupConfig } from './group.config';
export * from './domain';
export { GroupService } from './service';
1 change: 1 addition & 0 deletions apps/server/src/modules/h5p-editor/h5p-editor.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const h5pEditorConfig: H5PEditorConfig = {
NEST_LOG_LEVEL: Configuration.get('NEST_LOG_LEVEL') as string,
INCOMING_REQUEST_TIMEOUT: Configuration.get('H5P_EDITOR__INCOMING_REQUEST_TIMEOUT') as number,
...authorizationClientConfig,
EXIT_ON_ERROR: Configuration.get('EXIT_ON_ERROR') as boolean,
};

export const translatorConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('Course Controller (API)', () => {
const response = await loggedInClient.postWithAttachment('import', 'file', course, courseFileName);

expect(response.statusCode).toEqual(201);
});
}, 10000);
});

describe('[POST] /courses/:courseId/stop-sync', () => {
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/modules/legacy-school/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './legacy-school.module';
export { LegacySchoolModule } from './legacy-school.module';
export { LegacySchoolConfig } from './legacy-school.config';
export * from './service';
export {
SchoolSystemOptionsBuilder,
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/modules/legacy-school/legacy-school.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { GroupConfig } from '@modules/group';
import { LoggerConfig } from '@src/core/logger';

export interface LegacySchoolConfig extends GroupConfig, LoggerConfig {}
3 changes: 2 additions & 1 deletion apps/server/src/modules/news/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './news.module';
export { NewsModule } from './news.module';
export { NewsConfig } from './news.config';
4 changes: 4 additions & 0 deletions apps/server/src/modules/news/news.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { AuthorizationConfig } from '@modules/authorization';
import { LoggerConfig } from '@src/core/logger';

export interface NewsConfig extends AuthorizationConfig, LoggerConfig {}
1 change: 1 addition & 0 deletions apps/server/src/modules/news/news.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TeamNewsController } from './controller/team-news.controller';
import { NewsUc } from './uc/news.uc';
import { NewsService } from './service/news.service';

// imports from deletion module?
@Module({
imports: [AuthorizationModule, CqrsModule, LoggerModule],
controllers: [NewsController, TeamNewsController],
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/modules/pseudonym/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './pseudonym.module';
export { PseudonymModule } from './pseudonym.module';
export { PseudonymConfig } from './pseudonym.config';
export * from './service';
6 changes: 6 additions & 0 deletions apps/server/src/modules/pseudonym/pseudonym.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LoggerConfig } from '@src/core/logger';
import { LearnroomConfig } from '@modules/learnroom';
import { ToolConfig } from '@modules/tool';
import { UserConfig } from '@modules/user';

export interface PseudonymConfig extends UserConfig, LearnroomConfig, ToolConfig, LoggerConfig {}
1 change: 1 addition & 0 deletions apps/server/src/modules/pseudonym/pseudonym.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LegacyLogger, LoggerModule } from '@src/core/logger';
import { ExternalToolPseudonymRepo, PseudonymsRepo } from './repo';
import { PseudonymService } from './service';

// Why import this module LearnroomModule and ToolModule, The UserModule should also checked, but maybe it is ok.
@Module({
imports: [LoggerModule, CqrsModule],
providers: [PseudonymService, PseudonymsRepo, ExternalToolPseudonymRepo, LegacyLogger],
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/modules/registration-pin/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './registration-pin.module';
export { RegistrationPinModule } from './registration-pin.module';
export { RegistrationPinConfig } from './registration-pin.config';
export { RegistrationPinService } from './service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LoggerConfig } from '@src/core/logger';

export interface RegistrationPinConfig extends LoggerConfig {}
3 changes: 2 additions & 1 deletion apps/server/src/modules/rocketchat-user/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './rocketchat-user.module';
export { RocketChatUserModule } from './rocketchat-user.module';
export { RocketChatUserConfig } from './rocketchat-user.config';
export * from './service';
export * from './domain';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { LoggerConfig } from '@src/core/logger';

export interface RocketChatUserConfig extends LoggerConfig {
ROCKET_CHAT_URI: string;
ROCKET_CHAT_ADMIN_ID: string;
ROCKET_CHAT_ADMIN_TOKEN: string;
ROCKET_CHAT_ADMIN_USER: string;
ROCKET_CHAT_ADMIN_PASSWORD: string;
}
1 change: 1 addition & 0 deletions apps/server/src/modules/role/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { RoleModule } from './role.module';
export { RoleService, RoleDto } from './service';
export { RoleConfig } from './role.config';
2 changes: 2 additions & 0 deletions apps/server/src/modules/role/role.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RoleConfig {}
Loading

0 comments on commit b20156a

Please sign in to comment.