From eceafede406bb4deeee2f6c575de117024b12806 Mon Sep 17 00:00:00 2001
From: Jeremy Friesen <jeremy.n.friesen@gmail.com>
Date: Tue, 16 Apr 2024 10:38:33 -0400
Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=81=20Porting=20over=20ApplicationCont?=
 =?UTF-8?q?roller=20from=20PALs?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/controllers/application_controller.rb | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7264610533..1661c88bec 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
   # For APIs, you may want to use :null_session instead.
   protect_from_forgery with: :exception, prepend: true
 
+  force_ssl if: :ssl_configured?
+
   helper Openseadragon::OpenseadragonHelper
   # Adds a few additional behaviors into the application controller
   include Blacklight::Controller
@@ -23,7 +25,8 @@ class ApplicationController < ActionController::Base
   before_action :require_active_account!, if: :multitenant?
   before_action :set_account_specific_connections!
   before_action :elevate_single_tenant!, if: :singletenant?
-
+  skip_after_action :discard_flash_if_xhr
+  
   rescue_from Apartment::TenantNotFound do
     raise ActionController::RoutingError, 'Not Found'
   end
@@ -90,7 +93,6 @@ def guest_user
     @guest_user
   end
 
-
   private
 
   def require_active_account!
@@ -103,6 +105,10 @@ def set_account_specific_connections!
     current_account&.switch!
   end
 
+  def ssl_configured?
+    ActiveRecord::Type::Boolean.new.cast(current_account.ssl_configured)
+  end
+
   def multitenant?
     @multitenant ||= ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYKU_MULTITENANT', false))
   end