diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3c3328d7..76f75165 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,6 @@ # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later class ApplicationController < ActionController::Base - before_filter :set_locale + before_filter :set_locale, :redirect_to_maintenance protect_from_forgery @@ -19,6 +19,15 @@ class ApplicationController < ActionController::Base end end + def redirect_to_maintenance + if (Settings&.maintenance&.maintenance_mode && !current_user) + unless (self.class == Users::SessionsController && + ((Settings.maintenance.maintenance_token && params[:maintenance_token] == Settings.maintenance.maintenance_token) || params[:format] == 'json')) + redirect_to Settings.maintenance.maintenance_page + end + end + end + protected def json_saved(model, msg=nil) diff --git a/config/environment.rb b/config/environment.rb index b8209deb..b036d1a3 100755 --- a/config/environment.rb +++ b/config/environment.rb @@ -268,6 +268,20 @@ Config.schema do end end + # the settings to get into maintenance_mode + optional(:maintenance).schema do + # true if you want to be in maintenance mode, otherwise false + required(:maintenance_mode).filled(:bool?) + + # the token you pass into /users/sign_in to actually get to + # a signin page during maintenance mode + optional(:maintenance_token).filled(:str?) + + # the url, absolute or relative, that visitors should be redirected to + optional(:maintenance_page).filled(:str?) + + end + end Settings.reload! diff --git a/config/initializers/config.rb b/config/initializers/config.rb index 897a47c5..b253585e 100644 --- a/config/initializers/config.rb +++ b/config/initializers/config.rb @@ -2,7 +2,7 @@ Config.setup do |config| # Name of the constant exposing loaded settings config.const_name = 'Settings' - + config.use_env = true # Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'. # # config.knockout_prefix = nil diff --git a/public/maintenance.html b/public/maintenance.html index 1f46eb24..75e2d914 100644 --- a/public/maintenance.html +++ b/public/maintenance.html @@ -26,7 +26,6 @@
All of our hamsters needed a break from running in their wheels all day.
We're sorry for the inconvenience. Please check back soon.