Skip to content

Commit

Permalink
fix(annotations): Fix annotations control shows if no permission
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed May 6, 2020
1 parent 1c8ac70 commit 3b4858f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,11 @@ class BaseViewer extends EventEmitter {
*/
areNewAnnotationsEnabled() {
const { showAnnotationsControls, file } = this.options;
const { extension } = file || {};
const { permissions, extension } = file || {};

if (!this.hasAnnotationPermissions(permissions)) {
return false;
}

// Disable new annotations for Excel and iWork formats
if (EXCEL_EXTENSIONS.includes(extension) || IWORK_EXTENSIONS.includes(extension)) {
Expand Down
14 changes: 14 additions & 0 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,20 @@ describe('lib/viewers/BaseViewer', () => {
});

describe('areNewAnnotationsEnabled()', () => {
beforeEach(() => {
stubs.hasPermissions = sandbox.stub(base, 'hasAnnotationPermissions').returns(true);
base.options.file = {
permissions: {
can_annotate: true,
},
};
});

it('should return false if the user cannot create/view annotations', () => {
stubs.hasPermissions.returns(false);
expect(base.areNewAnnotationsEnabled()).to.be.false;
});

EXCEL_EXTENSIONS.concat(IWORK_EXTENSIONS).forEach(extension => {
it(`should return false if the file is ${extension} format`, () => {
base.options.file.extension = extension;
Expand Down

0 comments on commit 3b4858f

Please sign in to comment.