From cb5a702d52e535a0c8159a93147017df2810657d Mon Sep 17 00:00:00 2001 From: Max Bischof Date: Fri, 2 Aug 2024 13:16:04 +0200 Subject: [PATCH] Exchange AuthorizationReferenceService with AuthorizationClientAdapter --- .../src/modules/h5p-editor/h5p-editor.config.ts | 14 +++++++++++++- .../src/modules/h5p-editor/h5p-editor.module.ts | 6 +++--- .../h5p-editor/mapper/h5p-content.mapper.ts | 8 ++++---- apps/server/src/modules/h5p-editor/uc/h5p.uc.ts | 6 +++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/apps/server/src/modules/h5p-editor/h5p-editor.config.ts b/apps/server/src/modules/h5p-editor/h5p-editor.config.ts index e2364120443..e00f32542de 100644 --- a/apps/server/src/modules/h5p-editor/h5p-editor.config.ts +++ b/apps/server/src/modules/h5p-editor/h5p-editor.config.ts @@ -1,10 +1,22 @@ import { Configuration } from '@hpi-schul-cloud/commons'; +import { AuthorizationClientConfig } from '@infra/authorization-client'; import { S3Config } from '@infra/s3-client'; import { LanguageType } from '@shared/domain/interface'; +import { CoreModuleConfig } from '@src/core'; -const h5pEditorConfig = { +export interface H5PEditorConfig extends CoreModuleConfig, AuthorizationClientConfig { + NEST_LOG_LEVEL: string; + INCOMING_REQUEST_TIMEOUT: number; +} + +export const authorizationClientConfig: AuthorizationClientConfig = { + basePath: `${Configuration.get('API_HOST') as string}/v3/`, +}; + +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, }; export const translatorConfig = { diff --git a/apps/server/src/modules/h5p-editor/h5p-editor.module.ts b/apps/server/src/modules/h5p-editor/h5p-editor.module.ts index 5045d097d92..edd9103cd80 100644 --- a/apps/server/src/modules/h5p-editor/h5p-editor.module.ts +++ b/apps/server/src/modules/h5p-editor/h5p-editor.module.ts @@ -1,9 +1,9 @@ +import { AuthorizationClientModule } from '@infra/authorization-client'; import { RabbitMQWrapperModule } from '@infra/rabbitmq'; import { S3ClientModule } from '@infra/s3-client'; import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; import { AuthenticationModule } from '@modules/authentication'; -import { AuthorizationReferenceModule } from '@modules/authorization/authorization-reference.module'; import { UserModule } from '@modules/user'; import { Module, NotFoundException } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; @@ -13,7 +13,7 @@ import { CoreModule } from '@src/core'; import { Logger } from '@src/core/logger'; import { H5PEditorController } from './controller/h5p-editor.controller'; import { H5PContent, InstalledLibrary } from './entity'; -import { config, s3ConfigContent, s3ConfigLibraries } from './h5p-editor.config'; +import { authorizationClientConfig, config, s3ConfigContent, s3ConfigLibraries } from './h5p-editor.config'; import { H5PAjaxEndpointProvider, H5PEditorProvider, H5PPlayerProvider } from './provider'; import { H5PContentRepo, LibraryRepo } from './repo'; import { ContentStorage, LibraryStorage, TemporaryFileStorage } from './service'; @@ -27,7 +27,7 @@ const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { const imports = [ AuthenticationModule, - AuthorizationReferenceModule, + AuthorizationClientModule.register(authorizationClientConfig), CoreModule, UserModule, RabbitMQWrapperModule, diff --git a/apps/server/src/modules/h5p-editor/mapper/h5p-content.mapper.ts b/apps/server/src/modules/h5p-editor/mapper/h5p-content.mapper.ts index 1b760036db6..8861d0c3260 100644 --- a/apps/server/src/modules/h5p-editor/mapper/h5p-content.mapper.ts +++ b/apps/server/src/modules/h5p-editor/mapper/h5p-content.mapper.ts @@ -1,12 +1,12 @@ +import { AuthorizationBodyParamsReferenceType } from '@infra/authorization-client'; import { NotImplementedException } from '@nestjs/common'; -import { AuthorizableReferenceType } from '@src/modules/authorization/domain'; import { H5PContentParentType } from '../entity'; export class H5PContentMapper { - static mapToAllowedAuthorizationEntityType(type: H5PContentParentType): AuthorizableReferenceType { - const types = new Map(); + static mapToAllowedAuthorizationEntityType(type: H5PContentParentType): AuthorizationBodyParamsReferenceType { + const types = new Map(); - types.set(H5PContentParentType.Lesson, AuthorizableReferenceType.Lesson); + types.set(H5PContentParentType.Lesson, AuthorizationBodyParamsReferenceType.LESSONS); const res = types.get(type); diff --git a/apps/server/src/modules/h5p-editor/uc/h5p.uc.ts b/apps/server/src/modules/h5p-editor/uc/h5p.uc.ts index a6794b544a4..cbc425b31aa 100644 --- a/apps/server/src/modules/h5p-editor/uc/h5p.uc.ts +++ b/apps/server/src/modules/h5p-editor/uc/h5p.uc.ts @@ -1,3 +1,4 @@ +import { AuthorizationClientAdapter } from '@infra/authorization-client'; import { AjaxSuccessResponse, H5PAjaxEndpoint, @@ -25,7 +26,6 @@ import { LanguageType } from '@shared/domain/interface'; import { EntityId } from '@shared/domain/types'; import { ICurrentUser } from '@src/modules/authentication'; import { AuthorizationContext, AuthorizationContextBuilder } from '@src/modules/authorization'; -import { AuthorizationReferenceService } from '@src/modules/authorization/domain'; import { UserService } from '@src/modules/user'; import { Request } from 'express'; import { AjaxGetQueryParams, AjaxPostBodyParams, AjaxPostQueryParams } from '../controller/dto'; @@ -45,7 +45,7 @@ export class H5PEditorUc { private readonly h5pAjaxEndpoint: H5PAjaxEndpoint, private readonly libraryService: LibraryStorage, private readonly userService: UserService, - private readonly authorizationReferenceService: AuthorizationReferenceService, + private readonly authorizationClientAdapter: AuthorizationClientAdapter, private readonly h5pContentRepo: H5PContentRepo ) {} @@ -56,7 +56,7 @@ export class H5PEditorUc { context: AuthorizationContext ) { const allowedType = H5PContentMapper.mapToAllowedAuthorizationEntityType(parentType); - await this.authorizationReferenceService.checkPermissionByReferences(userId, allowedType, parentId, context); + await this.authorizationClientAdapter.checkPermissionsByReference(allowedType, parentId, context); } private fakeUndefinedAsString = () => {