Skip to content

Commit

Permalink
BC-7737 - Bump h5p server (#5140)
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax authored Jul 29, 2024
1 parent e3f0373 commit 9fcd3e6
Show file tree
Hide file tree
Showing 13 changed files with 589 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import {
ContentPermission,
GeneralPermission,
TemporaryFilePermission,
UserDataPermission,
} from '@lumieducation/h5p-server';
import EditorPermissionSystem from './editor-permission-system';

describe('EditorPermissionSystem', () => {
const buildUser = () => {
return { id: '1', email: '', name: '', type: '' };
};

describe('checkForUserData', () => {
it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForUserData(user, UserDataPermission.DeleteFinished, '1');

expect(result).toBe(false);
});

it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForUserData(user, UserDataPermission.DeleteState, '1');

expect(result).toBe(false);
});

it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForUserData(user, UserDataPermission.EditFinished, '1');

expect(result).toBe(false);
});

it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForUserData(user, UserDataPermission.EditState, '1');

expect(result).toBe(false);
});

it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForUserData(user, UserDataPermission.ListStates, '1');

expect(result).toBe(false);
});

it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForUserData(user, UserDataPermission.ViewFinished, '1');

expect(result).toBe(false);
});

it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForUserData(user, UserDataPermission.ViewState, '1');

expect(result).toBe(false);
});
});

describe('checkForContent', () => {
it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForContent(user, ContentPermission.Create, '1');

expect(result).toBe(true);
});

it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForContent(user, ContentPermission.Delete, '1');

expect(result).toBe(true);
});

it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForContent(user, ContentPermission.Download, '1');

expect(result).toBe(true);
});

it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForContent(user, ContentPermission.Edit, '1');

expect(result).toBe(true);
});

it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForContent(user, ContentPermission.Embed, '1');

expect(result).toBe(true);
});

it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForContent(user, ContentPermission.List, '1');

expect(result).toBe(true);
});

it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForContent(user, ContentPermission.View, '1');

expect(result).toBe(true);
});
});

describe('checkForTemporaryFile', () => {
it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForTemporaryFile(user, TemporaryFilePermission.Create, '1');

expect(result).toBe(true);
});

it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForTemporaryFile(user, TemporaryFilePermission.Delete, '1');

expect(result).toBe(true);
});

it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForTemporaryFile(user, TemporaryFilePermission.List, '1');

expect(result).toBe(true);
});

it('should return true', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForTemporaryFile(user, TemporaryFilePermission.View, '1');

expect(result).toBe(true);
});
});

describe('checkForGeneralAction', () => {
it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForGeneralAction(user, GeneralPermission.InstallRecommended);

expect(result).toBe(false);
});

it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForGeneralAction(user, GeneralPermission.UpdateAndInstallLibraries);

expect(result).toBe(false);
});

it('should return false', async () => {
const user = buildUser();

const permissionSystem = new EditorPermissionSystem();
const result = await permissionSystem.checkForGeneralAction(user, GeneralPermission.CreateRestricted);

expect(result).toBe(false);
});
});
});
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
Expand Up @@ -66,9 +66,6 @@ const helpers = {

createUser() {
return {
canCreateRestricted: false,
canInstallRecommended: false,
canUpdateAndInstallLibraries: false,
email: '[email protected]',
id: '12345',
name: 'Example User',
Expand Down Expand Up @@ -131,9 +128,6 @@ describe('ContentStorage', () => {
const existingContent = helpers.buildContent(0).withID();

const iUser: IUser = {
canCreateRestricted: false,
canInstallRecommended: false,
canUpdateAndInstallLibraries: false,
email: '[email protected]',
id: new ObjectId().toHexString(),
name: 'Example User',
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import { TemporaryFileStorage } from './temporary-file-storage.service';
const helpers = {
createUser() {
return {
canCreateRestricted: false,
canInstallRecommended: false,
canUpdateAndInstallLibraries: false,
email: '[email protected]',
id: '12345',
name: 'Example User',
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
Loading

0 comments on commit 9fcd3e6

Please sign in to comment.