diff --git a/server/conf.js b/server/conf.js index 0394803f..7aa256a3 100644 --- a/server/conf.js +++ b/server/conf.js @@ -34,4 +34,5 @@ exports.publicValues = { googleClientId, googleApiKey, wordpressClientId, + allowSponsorship: !!paypalReceiverEmail, }; diff --git a/server/user.js b/server/user.js index 6f94411e..335296c8 100644 --- a/server/user.js +++ b/server/user.js @@ -105,6 +105,9 @@ exports.paypalIpn = (req, res, next) => Promise.resolve() .catch(next); exports.checkSponsor = (idToken) => { + if (!conf.publicValues.allowSponsorship) { + return Promise.resolve(true); + } if (!idToken) { return Promise.resolve(false); } diff --git a/src/components/menus/WorkspacesMenu.vue b/src/components/menus/WorkspacesMenu.vue index 5d7de7c1..7caafdc4 100644 --- a/src/components/menus/WorkspacesMenu.vue +++ b/src/components/menus/WorkspacesMenu.vue @@ -58,18 +58,14 @@ export default { store.dispatch('modal/open', { type: 'couchdbWorkspace', }); - } catch (e) { - // Cancel - } + } catch (e) { /* Cancel */ } }, async addGithubWorkspace() { try { store.dispatch('modal/open', { type: 'githubWorkspace', }); - } catch (e) { - // Cancel - } + } catch (e) { /* Cancel */ } }, async addGitlabWorkspace() { try { @@ -79,9 +75,7 @@ export default { type: 'gitlabWorkspace', token, }); - } catch (e) { - // Cancel - } + } catch (e) { /* Cancel */ } }, async addGoogleDriveWorkspace() { try { @@ -90,12 +84,12 @@ export default { type: 'googleDriveWorkspace', token, }); - } catch (e) { - // Cancel - } + } catch (e) { /* Cancel */ } }, manageWorkspaces() { - store.dispatch('modal/open', 'workspaceManagement'); + try { + store.dispatch('modal/open', 'workspaceManagement'); + } catch (e) { /* Cancel */ } }, }, }; diff --git a/src/store/data.js b/src/store/data.js index 0831f9a6..ae862730 100644 --- a/src/store/data.js +++ b/src/store/data.js @@ -64,21 +64,26 @@ const patcher = id => ({ state, commit }, data) => { }; // For layoutSettings -const layoutSettingsToggler = (propertyName, featureId) => ({ getters, dispatch }, value) => { - dispatch('patchLayoutSettings', { - [propertyName]: value === undefined ? !getters.layoutSettings[propertyName] : value, - }); - badgeSvc.addBadge(featureId); +const toggleLayoutSetting = (name, value, featureId, getters, dispatch) => { + const currentValue = getters.layoutSettings[name]; + const patch = { + [name]: value === undefined ? !currentValue : !!value, + }; + if (patch[name] !== currentValue) { + dispatch('patchLayoutSettings', patch); + badgeSvc.addBadge(featureId); + } }; -const notEnoughSpace = (getters) => { - const layoutConstants = getters['layout/constants']; - const showGutter = getters['discussion/currentDiscussion']; - return document.body.clientWidth < layoutConstants.editorMinWidth + + +const layoutSettingsToggler = (propertyName, featureId) => ({ getters, dispatch }, value) => + toggleLayoutSetting(propertyName, value, featureId, getters, dispatch); + +const notEnoughSpace = (layoutConstants, showGutter) => + document.body.clientWidth < layoutConstants.editorMinWidth + layoutConstants.explorerWidth + layoutConstants.sideBarWidth + layoutConstants.buttonBarWidth + (showGutter ? layoutConstants.gutterWidth : 0); -}; // For templates const makeAdditionalTemplate = (name, value, helpers = '\n') => ({ @@ -239,26 +244,30 @@ export default { // Reset side bar dispatch('setSideBarPanel'); + // Toggle it + toggleLayoutSetting('showSideBar', value, 'toggleSideBar', getters, dispatch); + // Close explorer if not enough space - const patch = { - showSideBar: value === undefined ? !getters.layoutSettings.showSideBar : value, - }; - if (patch.showSideBar && notEnoughSpace(rootGetters)) { - patch.showExplorer = false; + if (getters.layoutSettings.showSideBar && + notEnoughSpace(rootGetters['layout/constants'], rootGetters['discussion/currentDiscussion']) + ) { + dispatch('patchLayoutSettings', { + showExplorer: false, + }); } - dispatch('patchLayoutSettings', patch); - badgeSvc.addBadge('toggleSideBar'); }, toggleExplorer: ({ getters, dispatch, rootGetters }, value) => { + // Toggle explorer + toggleLayoutSetting('showExplorer', value, 'toggleExplorer', getters, dispatch); + // Close side bar if not enough space - const patch = { - showExplorer: value === undefined ? !getters.layoutSettings.showExplorer : value, - }; - if (patch.showExplorer && notEnoughSpace(rootGetters)) { - patch.showSideBar = false; + if (getters.layoutSettings.showExplorer && + notEnoughSpace(rootGetters['layout/constants'], rootGetters['discussion/currentDiscussion']) + ) { + dispatch('patchLayoutSettings', { + showSideBar: false, + }); } - dispatch('patchLayoutSettings', patch); - badgeSvc.addBadge('toggleExplorer'); }, setSideBarPanel: ({ dispatch }, value) => dispatch('patchLayoutSettings', { sideBarPanel: value === undefined ? 'menu' : value, diff --git a/src/store/index.js b/src/store/index.js index 99affc82..006c730b 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -155,8 +155,14 @@ const store = new Vuex.Store({ return result; }, isSponsor: ({ light }, getters) => { + if (light) { + return true; + } + if (!getters['data/serverConf'].allowSponsorship) { + return true; + } const sponsorToken = getters['workspace/sponsorToken']; - return light || (sponsorToken && sponsorToken.isSponsor); + return sponsorToken ? sponsorToken.isSponsor : false; }, }, actions: {