diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e7c26b..3229d40 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -102,12 +102,6 @@ workflows: version: 2 test: jobs: - - test_node10: - <<: *filter_all - - test_node12: - <<: *filter_all - - test_node14: - <<: *filter_all - deploy_package: <<: *filter_release context: diff --git a/README.md b/README.md index d154b85..ac823cb 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,14 @@ export LDAP_SEARCH_BASE= export LDAP_SEARCH_FILTER= ``` +The following env variables are optional: + +This flag, when true, will prevent users from either going into edit mode or making any edits to a page they had already opened in edit mode in their browsers. This environment variable is optional and you can set it up from your Clay instance and it'll be picked up here since it'll share the same env file! +It will redirect users to the login page where they'll see a message saying that Clay is under maintenance. +```bash +export MAINTENANCE_MODE_ENABLED=true +``` + ## License MIT diff --git a/constants.js b/constants.js index 3c701f0..7c1ebc7 100644 --- a/constants.js +++ b/constants.js @@ -5,3 +5,4 @@ module.exports.AUTH_LEVELS = { ADMIN: 'admin', WRITE: 'write', }; +module.exports.MAINTENANCE_MODE_ENABLED = Boolean(process.env.MAINTENANCE_MODE_ENABLED); diff --git a/index.js b/index.js index 15b94f0..60d8116 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ const _isEmpty = require('lodash/isEmpty'), } = require('./utils'), createSessionStore = require('./services/session-store'), strategyService = require('./strategies'), - { AUTH_LEVELS } = require('./constants'), + { AUTH_LEVELS, MAINTENANCE_MODE_ENABLED } = require('./constants'), { withAuthLevel } = require('./services/auth'), { setDb } = require('./services/storage'), { setBus } = require('./controllers/users'); @@ -39,6 +39,13 @@ function isProtectedRoute(req) { */ function isAuthenticated(site) { return function (req, res, next) { + // This variable controls wether or not people can log in to Clay + // and stops people from being able to make edits to pages. + // If someone were to edit something on a tab that was already opened, + // or attempted to go into edit mode, with this flag active, + // they'd get redirected to a screen displaying a message that the CMS is under maintenance. + if (MAINTENANCE_MODE_ENABLED) return res.redirect(`${getAuthUrl(site)}/login`); + if (req.isAuthenticated()) { next(); // already logged in } else if (req.get('Authorization')) { @@ -98,13 +105,14 @@ function onLogin(site, providers) { // going to use varnish to automatically redirect them back to the ldap auth } else { res.send(template({ - path: getPathOrBase(site), - flash: flash, currentProviders: currentProviders, - user: req.user, - logoutLink: `${authUrl}/logout`, + flash: flash, localAuthPath: `${authUrl}/local`, - useLocalAuth: providers.includes('local') + logoutLink: `${authUrl}/logout`, + path: getPathOrBase(site), + maintenanceModeEnabled: MAINTENANCE_MODE_ENABLED, + useLocalAuth: providers.includes('local'), + user: req.user })); } }; diff --git a/views/login.handlebars b/views/login.handlebars index 97a1ad4..0765ebb 100644 --- a/views/login.handlebars +++ b/views/login.handlebars @@ -4,6 +4,15 @@ Log In - Clay