From 0b64acaecf8c6a65c20ba6f62a765647523ac3f7 Mon Sep 17 00:00:00 2001
From: farhatahmad <35435341+farhatahmad@users.noreply.github.com>
Date: Tue, 23 Jul 2019 13:52:39 -0400
Subject: [PATCH] Fixed issues with maintenance mode (#683)

---
 app/controllers/application_controller.rb | 2 +-
 app/helpers/application_helper.rb         | 1 +
 bin/start                                 | 7 +++++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 2ffcf741..d81ff084 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -197,6 +197,6 @@ class ApplicationController < ActionController::Base
   # 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") }
+    redirect_to request.referrer || root_path, flash: { alert: I18n.t("errors.maintenance.readonly") }
   end
 end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d947f54b..ec81ac71 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -87,6 +87,7 @@ module ApplicationHelper
   def allow_greenlight_accounts?
     return Rails.configuration.allow_user_signup unless Rails.configuration.loadbalanced_configuration
     return false unless @user_domain && !@user_domain.empty? && Rails.configuration.allow_user_signup
+    return false if @user_domain == "greenlight"
     # Proceed with retrieving the provider info
     begin
       provider_info = retrieve_provider_info(@user_domain, 'api2', 'getUserGreenlightCredentials')
diff --git a/bin/start b/bin/start
index 3f99e49b..b5d475d2 100755
--- a/bin/start
+++ b/bin/start
@@ -9,8 +9,11 @@ if [ "$RAILS_ENV" = "production" ] && [ "$DB_ADAPTER" = "postgresql" ]; then
 fi
 
 bundle exec rake db:create
-if ! bundle exec rake db:migrate ; then
-  export DB_MIGRATE_FAILED=1
+
+if [ "$MAINTENANCE_MODE" != "readonly" ] && [ "$MAINTENANCE_MODE" != "full" ]; then
+  if ! bundle exec rake db:migrate ; then
+    export DB_MIGRATE_FAILED=1
+  fi
 fi
 
 bundle exec rake assets:precompile
-- 
GitLab