Skip to content

Commit

Permalink
Add permission system
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax committed Jul 24, 2024
1 parent abd4cf1 commit b118570
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 26 deletions.
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
@@ -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 PermissionSystem implements IPermissionSystem<IUser> {
checkForUserData(
actingUser: IUser,
permission: UserDataPermission,
contentId: string,
affectedUserId?: string
): Promise<boolean> {
return Promise.resolve(true);
}

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(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
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 PermissionSystem from '../permission-system';
import { IH5PLibraryManagementConfig } from './h5p-library-management.config';

const h5pConfig = new H5PConfig(undefined, {
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 PermissionSystem();
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

0 comments on commit b118570

Please sign in to comment.