Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(annotations): Don't show highlight button if no download permission #1253

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the canDownload util from lib/file.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like canDownload from lib/file.js checks a lot more than just the download permission related to actually being able to download the file. Might be too restrictive?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair point. It also looks like we only check the permission for textLayerMode. Should be good to go here.


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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way we can avoid using withArgs here? Will make converting to Jest (someday) easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this but it turns out stubs.checkPermission is already being used in the other tests


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