From b80ce316b2281f50a1976b547d45c0ccc6f22f02 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Mon, 3 Dec 2018 14:53:57 -0500 Subject: [PATCH 1/2] Use hasCloudPermission flag as another factor in determining whether the user can use cloud or not. --- src/lib/cloud-manager-hoc.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/cloud-manager-hoc.jsx b/src/lib/cloud-manager-hoc.jsx index 407b50c99..a78239b80 100644 --- a/src/lib/cloud-manager-hoc.jsx +++ b/src/lib/cloud-manager-hoc.jsx @@ -48,9 +48,7 @@ const cloudManagerHOC = function (WrappedComponent) { this.disconnectFromCloud(); } canUseCloud (props) { - // TODO add a canUseCloud to pass down to this HOC (e.g. from www) and also check that here. - // This should cover info about the website specifically, like scrather status - return !!(props.cloudHost && props.username && props.vm && props.projectId); + return !!(props.cloudHost && props.username && props.vm && props.projectId && props.hasCloudPermission); } shouldNotModifyCloudData (props) { return (props.hasEverEnteredEditor && !props.canSave); @@ -92,7 +90,7 @@ const cloudManagerHOC = function (WrappedComponent) { handleCloudDataUpdate (projectHasCloudData) { if (this.isConnected() && !projectHasCloudData) { this.disconnectFromCloud(); - } else if (!this.isConnected() && projectHasCloudData) { + } else if (!this.isConnected() && this.canUseCloud(this.props) && projectHasCloudData) { this.connectToCloud(); } } @@ -102,6 +100,7 @@ const cloudManagerHOC = function (WrappedComponent) { cloudHost, projectId, username, + hasCloudPermission, hasEverEnteredEditor, isShowingWithId, /* eslint-enable no-unused-vars */ @@ -121,6 +120,7 @@ const cloudManagerHOC = function (WrappedComponent) { CloudManager.propTypes = { canSave: PropTypes.bool.isRequired, cloudHost: PropTypes.string, + hasCloudPermission: PropTypes.bool, hasEverEnteredEditor: PropTypes.bool, isShowingWithId: PropTypes.bool, projectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), From 6bdf80302865e779254c511afbadb54b02fdfb05 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Mon, 3 Dec 2018 15:00:37 -0500 Subject: [PATCH 2/2] Add unit test for new hasCloudPermission prop. Update existing tests. --- test/unit/util/cloud-manager-hoc.test.jsx | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/unit/util/cloud-manager-hoc.test.jsx b/test/unit/util/cloud-manager-hoc.test.jsx index 84e4687cc..977b5045f 100644 --- a/test/unit/util/cloud-manager-hoc.test.jsx +++ b/test/unit/util/cloud-manager-hoc.test.jsx @@ -59,6 +59,7 @@ describe('CloudManagerHOC', () => { mount( { mount( { mount( { mount( { expect(CloudProvider).not.toHaveBeenCalled(); }); + test('when hasCloudPermission is false, the cloud provider is not set on the vm', () => { + const Component = () =>
; + const WrappedComponent = cloudManagerHOC(Component); + mount( + + ); + + expect(vm.setCloudProvider.mock.calls.length).toBe(0); + expect(CloudProvider).not.toHaveBeenCalled(); + }); + test('if the isShowingWithId prop becomes true, it sets the cloud provider on the vm', () => { const Component = () =>
; const WrappedComponent = cloudManagerHOC(Component); const mounted = mount( { const mounted = mount( { const mounted = mount( { const mounted = mount( { const mounted = mount( { mount( { mount( { mount( { const mounted = mount( { const WrappedComponent = cloudManagerHOC(Component); const mounted = mount(