Skip to content

Commit

Permalink
Chore: Do not load annotations on shared links (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Apr 24, 2017
1 parent 059f6ac commit 8b959cd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
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

0 comments on commit 8b959cd

Please sign in to comment.