diff --git a/src/lib/Preview.js b/src/lib/Preview.js index 1197f184bf..ca13164845 100644 --- a/src/lib/Preview.js +++ b/src/lib/Preview.js @@ -1187,7 +1187,7 @@ class Preview extends EventEmitter { } // Determine the viewer to use - const viewer = loader.determineViewer(this.file, Object.keys(this.disabledViewers)); + const viewer = loader.determineViewer(this.file, Object.keys(this.disabledViewers), this.options.viewers); // Log the type of file this.logger.setType(viewer.NAME); diff --git a/src/lib/viewers/office/OfficeLoader.js b/src/lib/viewers/office/OfficeLoader.js index 07edbb7ca8..9f1fbfbd71 100644 --- a/src/lib/viewers/office/OfficeLoader.js +++ b/src/lib/viewers/office/OfficeLoader.js @@ -1,3 +1,4 @@ +import get from 'lodash/get'; import AssetLoader from '../AssetLoader'; import OfficeViewer from './OfficeViewer'; import { checkPermission } from '../../file'; @@ -29,14 +30,15 @@ class OfficeLoader extends AssetLoader { /** * @inheritdoc */ - determineViewer(file, disabledViewers = []) { + determineViewer(file, disabledViewers = [], viewerOptions = {}) { // The Office viewer is disabled when this is a password protected shared link const isDisabledDueToPasswordProtectedSharedLink = file.shared_link && file.shared_link.is_password_enabled; - // If the user does not have permission to download the file, the file is larger than 5MB, or isDisabledDueToSharedLink is true, - // then disable the Office viewer + // If the user does not have permission to download the file, the file is larger than Appconf file size or 5MB, + // or isDisabledDueToSharedLink is true, then disable the Office viewer + const maxFileSize = get(viewerOptions, 'office.excelOnlineAllowedMaxFileSize') || FIVE_MB; if ( !checkPermission(file, PERMISSION_DOWNLOAD) || - file.size > FIVE_MB || + file.size > maxFileSize || isDisabledDueToPasswordProtectedSharedLink ) { disabledViewers.push(OFFICE_VIEWER_NAME); diff --git a/src/lib/viewers/office/__tests__/OfficeLoader-test.js b/src/lib/viewers/office/__tests__/OfficeLoader-test.js index 6f92fcbd33..53f8dfa5fe 100644 --- a/src/lib/viewers/office/__tests__/OfficeLoader-test.js +++ b/src/lib/viewers/office/__tests__/OfficeLoader-test.js @@ -3,6 +3,8 @@ import OfficeViewer from '../OfficeViewer'; import * as file from '../../../file'; import { PERMISSION_DOWNLOAD } from '../../../constants'; +const FIVE_MB = 5242880; + const sandbox = sinon.sandbox.create(); describe('lib/viewers/office/OfficeLoader', () => { @@ -43,9 +45,11 @@ describe('lib/viewers/office/OfficeLoader', () => { }); it('should choose the Office viewer if it is not disabled and the file is a shared link that is not password-protected', () => { - const editedFakeFile = fakeFile; - editedFakeFile.shared_link = { - is_password_enabled: false, + const editedFakeFile = { + ...fakeFile, + shared_link: { + is_password_enabled: false, + }, }; const viewer = OfficeLoader.determineViewer(editedFakeFile); expect(viewer.NAME).to.equal('Office'); @@ -57,8 +61,7 @@ describe('lib/viewers/office/OfficeLoader', () => { }); it('should not return a viewer if the file is too large', () => { - const editedFakeFile = fakeFile; - editedFakeFile.size = 5242881; + const editedFakeFile = { ...fakeFile, size: FIVE_MB + 1 }; const viewer = OfficeLoader.determineViewer(editedFakeFile, []); expect(viewer).to.equal(undefined); }); @@ -73,13 +76,26 @@ describe('lib/viewers/office/OfficeLoader', () => { }); it('should not return a viewer if the file is a password-protected shared link', () => { - const editedFakeFile = fakeFile; - editedFakeFile.shared_link = { - is_password_enabled: true, + const editedFakeFile = { + ...fakeFile, + shared_link: { + is_password_enabled: true, + }, }; const viewer = OfficeLoader.determineViewer(editedFakeFile, []); expect(viewer).to.equal(undefined); }); + + it('should respect maxFileSize in viewerOptions', () => { + const viewerOptions = { + office: { + excelOnlineAllowedMaxFileSize: FIVE_MB + 1, + }, + }; + const editedFakeFile = { ...fakeFile, size: FIVE_MB + 1 }; + const viewer = OfficeLoader.determineViewer(editedFakeFile, [], viewerOptions); + expect(viewer).to.not.equal(undefined); + }); }); }); });