From b3a72d6331c4beed8fac734af1fcdb2c4e2b55d3 Mon Sep 17 00:00:00 2001 From: Conrad Chan Date: Mon, 14 Sep 2020 11:38:15 -0700 Subject: [PATCH] feat(annotations): Disable highlight button if no download permission (#1253) --- src/lib/viewers/doc/DocBaseViewer.js | 4 +++- src/lib/viewers/doc/__tests__/DocBaseViewer-test.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lib/viewers/doc/DocBaseViewer.js b/src/lib/viewers/doc/DocBaseViewer.js index d677a6521..5886741b7 100644 --- a/src/lib/viewers/doc/DocBaseViewer.js +++ b/src/lib/viewers/doc/DocBaseViewer.js @@ -1105,11 +1105,13 @@ class DocBaseViewer extends BaseViewer { this.controls.add(__('exit_fullscreen'), this.toggleFullscreen, 'bp-exit-fullscreen-icon', ICON_FULLSCREEN_OUT); if (this.areNewAnnotationsEnabled() && this.hasAnnotationCreatePermission()) { + const canDownload = checkPermission(this.options.file, PERMISSION_DOWNLOAD); + this.annotationControls.init({ fileId: this.options.file.id, onClick: this.handleAnnotationControlsClick, onEscape: this.handleAnnotationControlsEscape, - showHighlightText: this.options.showAnnotationsHighlightText, + showHighlightText: this.options.showAnnotationsHighlightText && canDownload, }); } } diff --git a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js index 46ce17c85..d05a72383 100644 --- a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js +++ b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js @@ -2302,6 +2302,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { stubs.isFindDisabled = sandbox.stub(docBase, 'isFindDisabled'); stubs.areNewAnnotationsEnabled = sandbox.stub(docBase, 'areNewAnnotationsEnabled').returns(true); stubs.hasCreatePermission = sandbox.stub(docBase, 'hasAnnotationCreatePermission').returns(true); + stubs.checkPermission.withArgs(docBase.options.file, PERMISSION_DOWNLOAD).returns(true); }); it('should add the correct controls', () => { @@ -2380,6 +2381,18 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { }), ); + it('should not showHighlightText if file has no download permission', () => { + stubs.checkPermission.withArgs(docBase.options.file, PERMISSION_DOWNLOAD).returns(false); + + docBase.bindControlListeners(); + + expect(docBase.annotationControls.init).to.be.calledWith( + sinon.match({ + showHighlightText: false, + }), + ); + }); + it('should not add the toggle thumbnails control if the option is not enabled', () => { // Create a new instance that has enableThumbnailsSidebar as false docBase.options.enableThumbnailsSidebar = false;