-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added contextId to user data classes * feat: contextId in H5PPlayer.play * feat: contextId in h5p-express and docs * test: added integration tests for contextId * test: contextId in rest example * feat(mongo-s3): added contextId to user data storage * refactor: permission system * refactor: permissions system * test: fix tests * test: fix more tests * test: fix more tests * refactor!: moved permissions from IUser to IPermissionSystem * refactor: permission system * refactor: fine grained permission types and REST example * refactor: prettier * refactor: more fine grained user data permission handling * feat: impersonate users and read only states * test: fixed test for new content user data interface * refactor: style improvement and docs * feat: add locales * test: fix tests * docs: extended docs * test: added test for impersonation * test: added impersonation and read only state to REST example
- Loading branch information
Showing
134 changed files
with
2,441 additions
and
1,023 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Authorization | ||
|
||
Many actions users perform in the H5P system need authorization. By default the | ||
library will allow everything to every user. You can customize who can do what, | ||
but passing in an implementation of `IPermissionSystem` into | ||
`options.permissionSystem` of the `H5PPlayer` or `H5PEditor` constructor. The | ||
library then calls the methods of `IPermissionSystem` whenever a user performs an | ||
action that requires authorization. | ||
|
||
See the documentation of `IPermissionSystem` for and the | ||
[`ExamplePermissionSystem`](/packages/h5p-rest-example-server/src/ExamplePermissionSystem.ts) | ||
for reference how to implement the permission system. | ||
|
||
Note that the `IPermissionSystem` is a generic. You can use any sub-type of | ||
`IUser` as the generic type. The call of the methods of `IPermissionSystem` will | ||
include a user of the generic type. This is the user object you've injected in | ||
your controllers. That means you can add any arbitrary date to it, like roles. |
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,30 @@ | ||
# Impersonating users | ||
|
||
It is possible to impersonate users when viewing a H5P object. This means that | ||
you can display another user's user state instead of your own. This is useful, | ||
if you want to implement a feature in which teachers can review the work of | ||
students. | ||
|
||
You do this by setting `options.asUserId` of the `H5PPlayer.render` method. Make | ||
sure that you [authorize users](authorization.md) as required in the permission | ||
system. | ||
|
||
## Read-only states | ||
|
||
In most cases in which your users impersonate another user, you'll want to | ||
disable saving the user state for the impersonator. You can do this by setting | ||
`options.readOnlyState` to true when calling `H5PPlayer.render`. This will do | ||
the following: | ||
|
||
- set the save interval to the longest possible value | ||
- adds the query parameter `ignorePost=yes` to the Ajax route responsible for | ||
handling user states | ||
|
||
The query parameter is necessary, as the H5P core client doesn't support user | ||
states that are read only. We work around this by ignoring a post calls when the | ||
query parameter is set in h5p-express. If the query parameter is set, we simply | ||
return a success, so the H5P core client doesn't realize we didn't save the | ||
state. If you don't use this package, you must do this yourself. | ||
|
||
Obviously you also have to make sure malicious users won't change the user state | ||
of others, by rejecting these operations in the authorization/permission system! |
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 |
---|---|---|
|
@@ -7,16 +7,10 @@ export default class User implements IUser { | |
constructor() { | ||
this.id = '1'; | ||
this.name = 'Firstname Surname'; | ||
this.canInstallRecommended = true; | ||
this.canUpdateAndInstallLibraries = true; | ||
this.canCreateRestricted = true; | ||
this.type = 'local'; | ||
this.email = '[email protected]'; | ||
} | ||
|
||
public canCreateRestricted: boolean; | ||
public canInstallRecommended: boolean; | ||
public canUpdateAndInstallLibraries: boolean; | ||
public email: string; | ||
public id: string; | ||
public name: string; | ||
|
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
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 |
---|---|---|
|
@@ -7,16 +7,10 @@ export default class User implements IUser { | |
constructor() { | ||
this.id = '1'; | ||
this.name = 'Firstname Surname'; | ||
this.canInstallRecommended = true; | ||
this.canUpdateAndInstallLibraries = true; | ||
this.canCreateRestricted = true; | ||
this.type = 'local'; | ||
this.email = '[email protected]'; | ||
} | ||
|
||
public canCreateRestricted: boolean; | ||
public canInstallRecommended: boolean; | ||
public canUpdateAndInstallLibraries: boolean; | ||
public email: string; | ||
public id: string; | ||
public name: string; | ||
|
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 |
---|---|---|
|
@@ -7,16 +7,10 @@ export default class User implements IUser { | |
constructor() { | ||
this.id = '1'; | ||
this.name = 'Firstname Surname'; | ||
this.canInstallRecommended = true; | ||
this.canUpdateAndInstallLibraries = true; | ||
this.canCreateRestricted = true; | ||
this.type = 'local'; | ||
this.email = '[email protected]'; | ||
} | ||
|
||
public canCreateRestricted: boolean; | ||
public canInstallRecommended: boolean; | ||
public canUpdateAndInstallLibraries: boolean; | ||
public email: string; | ||
public id: string; | ||
public name: string; | ||
|
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.