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 b3ccf56
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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
16 changes: 15 additions & 1 deletion src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,21 @@ describe('lib/viewers/BaseViewer', () => {
});
});

describe('areNewAnnotationsEnabled()', () => {
describe.only('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 b3ccf56

Please sign in to comment.