Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-7737 - Bump h5p server #5140

Merged
merged 12 commits into from
Jul 29, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
ContentPermission,
GeneralPermission,
IPermissionSystem,
IUser,
TemporaryFilePermission,
UserDataPermission,
} from '@lumieducation/h5p-server';

export default class EditorPermissionSystem implements IPermissionSystem<IUser> {
checkForUserData(
actingUser: IUser,
permission: UserDataPermission,
contentId: string,
affectedUserId?: string
): Promise<boolean> {
return Promise.resolve(false);
}

async checkForContent(
actingUser: IUser | undefined,
permission: ContentPermission,
contentId?: string
): Promise<boolean> {
return Promise.resolve(true);
}

async checkForTemporaryFile(
user: IUser | undefined,
permission: TemporaryFilePermission,
filename?: string
): Promise<boolean> {
return Promise.resolve(true);
}

async checkForGeneralAction(actingUser: IUser | undefined, permission: GeneralPermission): Promise<boolean> {
return Promise.resolve(false);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { H5PEditor, cacheImplementations } from '@lumieducation/h5p-server';

import { IH5PEditorOptions, ITranslationFunction } from '@lumieducation/h5p-server/build/src/types';
import { ContentStorage, LibraryStorage, TemporaryFileStorage, Translator } from '../service';
import { h5pConfig, h5pUrlGenerator } from '../service/config/h5p-service-config';
import { ContentStorage, Translator, LibraryStorage, TemporaryFileStorage } from '../service';
import EditorPermissionSystem from './editor-permission-system';

export const H5PEditorProvider = {
provide: H5PEditor,
Expand All @@ -14,9 +15,11 @@ export const H5PEditorProvider = {
) {
const cache = new cacheImplementations.CachedKeyValueStorage('kvcache');

const permissionSystem = new EditorPermissionSystem();
const h5pOptions: IH5PEditorOptions = {
enableHubLocalization: true,
enableLibraryNameLocalization: true,
permissionSystem,
};
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const translationFunction: ITranslationFunction = await Translator.translate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { S3ClientAdapter } from '@infra/s3-client';
import {
ContentId,
ContentPermission,
IContentMetadata,
IContentStorage,
IFileStats,
ILibraryName,
IUser as ILumiUser,
LibraryName,
Permission,
} from '@lumieducation/h5p-server';
import {
HttpException,
Expand All @@ -17,7 +18,6 @@ import {
NotFoundException,
UnprocessableEntityException,
} from '@nestjs/common';
import { S3ClientAdapter } from '@infra/s3-client';
import { ErrorUtils } from '@src/core/error/utils';
import { Readable } from 'stream';
import { H5pFileDto } from '../controller/dto/h5p-file.dto';
Expand Down Expand Up @@ -184,8 +184,14 @@ export class ContentStorage implements IContentStorage {
return result;
}

public getUserPermissions(): Promise<Permission[]> {
const permissions = [Permission.Delete, Permission.Download, Permission.Edit, Permission.Embed, Permission.View];
public getUserPermissions(): Promise<ContentPermission[]> {
const permissions = [
ContentPermission.Delete,
ContentPermission.Download,
ContentPermission.Edit,
ContentPermission.Embed,
ContentPermission.View,
];

return Promise.resolve(permissions);
}
Expand Down
9 changes: 0 additions & 9 deletions apps/server/src/modules/h5p-editor/types/lumi-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ export class LumiUserWithContentData implements IUser {

schoolId: EntityId;

canCreateRestricted: boolean;

canInstallRecommended: boolean;

canUpdateAndInstallLibraries: boolean;

email: string;

id: EntityId;
Expand All @@ -34,9 +28,6 @@ export class LumiUserWithContentData implements IUser {
this.contentParentId = parentParams.parentId;
this.schoolId = parentParams.schoolId;

this.canCreateRestricted = user.canCreateRestricted;
this.canInstallRecommended = user.canInstallRecommended;
this.canUpdateAndInstallLibraries = user.canUpdateAndInstallLibraries;
this.email = user.email;
this.id = user.id;
this.name = user.name;
Expand Down
3 changes: 0 additions & 3 deletions apps/server/src/modules/h5p-editor/uc/h5p.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,6 @@ export class H5PEditorUc {

private changeUserType(currentUser: ICurrentUser): LumiIUser {
const user: LumiIUser = {
canCreateRestricted: false,
canInstallRecommended: false,
canUpdateAndInstallLibraries: false,
email: '',
id: currentUser.userId,
name: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import {
H5PConfig,
cacheImplementations,
LibraryManager,
ContentTypeCache,
H5PConfig,
ILibraryAdministrationOverviewItem,
IUser,
LibraryAdministration,
ILibraryAdministrationOverviewItem,
LibraryManager,
} from '@lumieducation/h5p-server';
import ContentManager from '@lumieducation/h5p-server/build/src/ContentManager';
import ContentTypeInformationRepository from '@lumieducation/h5p-server/build/src/ContentTypeInformationRepository';
import { IHubContentType } from '@lumieducation/h5p-server/build/src/types';
import { Injectable, InternalServerErrorException, NotFoundException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ContentStorage, LibraryStorage } from '@src/modules/h5p-editor';
import { readFileSync } from 'fs';
import { parse } from 'yaml';
import { ConfigService } from '@nestjs/config';
import { IHubContentType } from '@lumieducation/h5p-server/build/src/types';
import { IH5PLibraryManagementConfig } from './h5p-library-management.config';
import LibraryManagementPermissionSystem from './library-management-permission-system';

const h5pConfig = new H5PConfig(undefined, {
baseUrl: '/api/v3/h5p-editor',
Expand Down Expand Up @@ -75,8 +76,14 @@ export class H5PLibraryManagementService {
undefined,
h5pConfig
);
this.contentTypeRepo = new ContentTypeInformationRepository(this.contentTypeCache, this.libraryManager, h5pConfig);
const contentManager = new ContentManager(this.contentStorage);
const permissionSystem = new LibraryManagementPermissionSystem();
this.contentTypeRepo = new ContentTypeInformationRepository(
this.contentTypeCache,
this.libraryManager,
h5pConfig,
permissionSystem
);
const contentManager = new ContentManager(this.contentStorage, permissionSystem);
this.libraryAdministration = new LibraryAdministration(this.libraryManager, contentManager);
const filePath = this.configService.get<string>('H5P_EDITOR__LIBRARY_LIST_PATH');

Expand Down Expand Up @@ -115,9 +122,6 @@ export class H5PLibraryManagementService {

private createDefaultIUser(): IUser {
const user: IUser = {
canCreateRestricted: true,
canInstallRecommended: true,
canUpdateAndInstallLibraries: true,
email: '[email protected]',
id: 'a',
name: 'a',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
ContentPermission,
GeneralPermission,
IPermissionSystem,
IUser,
TemporaryFilePermission,
UserDataPermission,
} from '@lumieducation/h5p-server';

export default class LibraryManagementPermissionSystem implements IPermissionSystem<IUser> {
checkForUserData(
actingUser: IUser,
permission: UserDataPermission,
contentId: string,
affectedUserId?: string
): Promise<boolean> {
return Promise.resolve(false);
}

async checkForContent(
actingUser: IUser | undefined,
permission: ContentPermission,
contentId?: string
): Promise<boolean> {
return Promise.resolve(false);
}

async checkForTemporaryFile(
user: IUser | undefined,
permission: TemporaryFilePermission,
filename?: string
): Promise<boolean> {
return Promise.resolve(false);
}

async checkForGeneralAction(actingUser: IUser | undefined, permission: GeneralPermission): Promise<boolean> {
switch (permission) {
case GeneralPermission.InstallRecommended:
return Promise.resolve(true);
case GeneralPermission.UpdateAndInstallLibraries:
return Promise.resolve(true);
case GeneralPermission.CreateRestricted:
return Promise.resolve(true);
default:
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spannend das hier dann kein Promise.resolve gefordert ist von ts. Könntest du noch mal kurz schauen ob mit den ts update die oberen Promise.resolve raus könnten?

}
}
}
66 changes: 40 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"@hendt/xml2json": "^1.0.3",
"@hpi-schul-cloud/commons": "^1.3.4",
"@keycloak/keycloak-admin-client": "^25.0.1",
"@lumieducation/h5p-server": "^9.2.0",
"@lumieducation/h5p-server": "^9.3.2",
"@mikro-orm/cli": "^5.6.16",
"@mikro-orm/core": "^5.6.16",
"@mikro-orm/migrations-mongodb": "^5.6.16",
Expand Down
Loading