-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3f0373
commit 9fcd3e6
Showing
13 changed files
with
589 additions
and
63 deletions.
There are no files selected for viewing
210 changes: 210 additions & 0 deletions
210
apps/server/src/modules/h5p-editor/provider/editor-permission-system.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
apps/server/src/modules/h5p-editor/provider/editor-permission-system.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,9 +66,6 @@ const helpers = { | |
|
||
createUser() { | ||
return { | ||
canCreateRestricted: false, | ||
canInstallRecommended: false, | ||
canUpdateAndInstallLibraries: false, | ||
email: '[email protected]', | ||
id: '12345', | ||
name: 'Example User', | ||
|
@@ -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', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.