Skip to content

Commit

Permalink
feat(annotations): Disable highlight button if no download permission (
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan authored Sep 14, 2020
1 parent 4cf773f commit b3a72d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b3a72d6

Please sign in to comment.