Skip to content

Commit

Permalink
feat(permissions): Add checks for new permission values on file object (
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoffan authored May 12, 2020
1 parent b0c4a62 commit 1f7cda6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,8 @@ class BaseViewer extends EventEmitter {

return !!(
permissions.can_annotate ||
permissions.can_create_annotations ||
permissions.can_view_annotations ||
permissions.can_view_annotations_all ||
permissions.can_view_annotations_self
);
Expand Down
18 changes: 15 additions & 3 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1156,9 +1156,11 @@ describe('lib/viewers/BaseViewer', () => {

describe('hasAnnotationPermissions()', () => {
const permissions = {
can_annotate: false,
can_view_annotations_all: false,
can_view_annotations_self: false,
can_annotate: false, // Old
can_create_annotations: false, // New
can_view_annotations: false, // New
can_view_annotations_all: false, // Old
can_view_annotations_self: false, // Old
};

it('does nothing if file permissions are undefined', () => {
Expand All @@ -1169,6 +1171,16 @@ describe('lib/viewers/BaseViewer', () => {
expect(base.hasAnnotationPermissions(permissions)).to.be.false;
});

it('should return true if the user can at least create annotations', () => {
permissions.can_create_annotations = true;
expect(base.hasAnnotationPermissions(permissions)).to.be.true;
});

it('should return true if the user can at least view annotations', () => {
permissions.can_view_annotations = true;
expect(base.hasAnnotationPermissions(permissions)).to.be.true;
});

it('should return true if the user can at least view all annotations', () => {
permissions.can_view_annotations_all = true;
expect(base.hasAnnotationPermissions(permissions)).to.be.true;
Expand Down

0 comments on commit 1f7cda6

Please sign in to comment.