Skip to content

Commit

Permalink
Exchange AuthorizationReferenceService with AuthorizationClientAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax committed Aug 2, 2024
1 parent c48d0d0 commit cb5a702
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
14 changes: 13 additions & 1 deletion apps/server/src/modules/h5p-editor/h5p-editor.config.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/modules/h5p-editor/h5p-editor.module.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -27,7 +27,7 @@ const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = {

const imports = [
AuthenticationModule,
AuthorizationReferenceModule,
AuthorizationClientModule.register(authorizationClientConfig),
CoreModule,
UserModule,
RabbitMQWrapperModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<H5PContentParentType, AuthorizableReferenceType>();
static mapToAllowedAuthorizationEntityType(type: H5PContentParentType): AuthorizationBodyParamsReferenceType {
const types = new Map<H5PContentParentType, AuthorizationBodyParamsReferenceType>();

types.set(H5PContentParentType.Lesson, AuthorizableReferenceType.Lesson);
types.set(H5PContentParentType.Lesson, AuthorizationBodyParamsReferenceType.LESSONS);

const res = types.get(type);

Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/modules/h5p-editor/uc/h5p.uc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AuthorizationClientAdapter } from '@infra/authorization-client';
import {
AjaxSuccessResponse,
H5PAjaxEndpoint,
Expand Down Expand Up @@ -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';
Expand All @@ -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
) {}

Expand All @@ -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 = () => {
Expand Down

0 comments on commit cb5a702

Please sign in to comment.