diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b1ef3ee4b..837e5a567 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -18,6 +18,7 @@ class ApplicationController < ActionController::Base with_themed_layout '1_column' include HykuHelper + include DeviseGuestControllersHelpersDecorator helper_method :current_account, :admin_host?, :home_page_theme, :show_page_theme, :search_results_theme before_action :authenticate_if_needed diff --git a/app/controllers/devise_guest_controllers_helpers_decorator.rb b/app/controllers/devise_guest_controllers_helpers_decorator.rb new file mode 100644 index 000000000..79d1ddda9 --- /dev/null +++ b/app/controllers/devise_guest_controllers_helpers_decorator.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +# OVERRIDE devise-invitable 2.0.9 to unscope user look up +module DeviseGuestControllersHelpersDecorator + def guest_user + return @guest_user if @guest_user + + if session[:guest_user_id] + begin + @guest_user = User.unscoped.find_by(User.authentication_keys.first => session[:guest_user_id]) + rescue + @guest_user = nil + end + @guest_user = nil if @guest_user.respond_to?(:guest) && !@guest_user.guest + end + + @guest_user ||= begin + u = create_guest_user(session[:guest_user_id]) + session[:guest_user_id] = u.send(User.authentication_keys.first) + u + end + + @guest_user + end +end + +DeviseGuests::Controllers::Helpers.prepend(DeviseGuestControllersHelpersDecorator)