diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0b029efc..2ffcf741 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,6 +36,9 @@ class ApplicationController < ActionController::Base # Manually handle BigBlueButton errors rescue_from BigBlueButton::BigBlueButtonException, with: :handle_bigbluebutton_error + # Manually Handle errors when application is in readonly mode + rescue_from ActiveRecord::ReadOnlyRecord, with: :handle_readonly_error + protect_from_forgery with: :exception MEETING_NAME_LIMIT = 90 @@ -47,7 +50,7 @@ class ApplicationController < ActionController::Base end def maintenance_mode? - if ENV["MAINTENANCE_MODE"].present? + if ENV["MAINTENANCE_MODE"] == "full" render "errors/greenlight_error", status: 503, formats: :html, locals: { status_code: 503, @@ -190,4 +193,10 @@ class ApplicationController < ActionController::Base def handle_bigbluebutton_error render "errors/bigbluebutton_error" end + + # Manually Handle errors when application is in readonly mode + def handle_readonly_error + flash.clear + redirect_to request.referrer, flash: { alert: I18n.t("errors.maintenance.readonly") } + end end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index f315237b..58709624 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -22,4 +22,8 @@ class ApplicationRecord < ActiveRecord::Base def to_param uid end + + def readonly? + ENV["MAINTENANCE_MODE"] == "readonly" + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 2bedb799..8434beb5 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -124,6 +124,7 @@ en: maintenance: message: Sorry, we're down for maintenance. help: We'll be back soon! + readonly: This application is under maintenance. You will not be able to perform this action migration_error: contact_admin: If you are not an administrator, please contact one. continue: I'd like to stay using 1.0. diff --git a/sample.env b/sample.env index 57b6ba2a..c69304b6 100644 --- a/sample.env +++ b/sample.env @@ -144,6 +144,14 @@ NUMBER_OF_ROWS=25 # ENABLE_GOOGLE_CALENDAR_BUTTON=true|false ENABLE_GOOGLE_CALENDAR_BUTTON= +# Set the application into Maintenance Mode +# +# Current options supported: +# full: Renders an error page that does not allow users to access any of the features in the application +# readonly: Sets the database to readonly mode, which allows users to use actions that dont write to the database +# false: Application runs normally +MAINTENANCE_MODE=false + # Comment this out to send logs to STDOUT in production instead of log/production.log . # # RAILS_LOG_TO_STDOUT=true