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

Chore: Do not load annotations on shared links #88

Merged
merged 1 commit into from
Apr 24, 2017
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
9 changes: 8 additions & 1 deletion src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,15 @@ class DocBaseViewer extends BaseViewer {
initAnnotations() {
this.setupPageIds();

const { apiHost, file, location, token } = this.options;
const { apiHost, file, location, token, sharedLink } = this.options;
const fileVersionID = file.file_version.id;

// Do not initialize annotations for shared links
// TODO(@spramod): Determine the expected behavior on shared links
if (sharedLink) {
return;
}

// Users can currently only view annotations on mobile
const canAnnotate = checkPermission(file, PERMISSION_ANNOTATE) && !Browser.isMobile();
const annotationService = new AnnotationService({
Expand Down
7 changes: 7 additions & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,13 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
expect(stubs.setupPageIds).to.be.called;
});

it('should do nothing if expiring embed is a shared link', () => {
stubs.checkPermission.withArgs(docBase.options.file, PERMISSION_ANNOTATE).returns(true);
docBase.options.sharedLink = 'url';
docBase.initAnnotations();
expect(docBase.annotator).to.be.undefined;
});

it('should allow annotations based on browser and permissions', () => {
stubs.checkPermission.withArgs(docBase.options.file, PERMISSION_ANNOTATE).returns(true);
docBase.initAnnotations();
Expand Down
9 changes: 8 additions & 1 deletion src/lib/viewers/image/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,14 @@ class ImageViewer extends ImageBaseViewer {
}

// Users can currently only view annotations on mobile
const { apiHost, file, location, token } = this.options;
const { apiHost, file, location, token, sharedLink } = this.options;

// Do not initialize annotations for shared links
// TODO(@spramod): Determine the expected behavior on shared links
if (sharedLink) {
return;
}

const canAnnotate = checkPermission(file, PERMISSION_ANNOTATE) && !Browser.isMobile();
this.canAnnotate = canAnnotate;

Expand Down
7 changes: 7 additions & 0 deletions src/lib/viewers/image/__tests__/ImageViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ describe('lib/viewers/image/ImageViewer', () => {
expect(image.annotator).to.be.undefined;
});

it('should do nothing if expiring embed is a shared link', () => {
stubs.annotatable.returns(true);
image.options.sharedLink = 'url';
image.initAnnotations();
expect(image.annotator).to.be.undefined;
});

it('should init annotations if user can annotate', () => {
stubs.checkPermission.withArgs(image.options.file, PERMISSION_ANNOTATE).returns(true);
stubs.annotatable.returns(true);
Expand Down