From ff1e68bd3f42788f0f2c60033f5493631c59d7a4 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 5 Dec 2024 14:41:34 -0800 Subject: [PATCH 1/5] fix guest lookup to be unscoped --- app/controllers/application_controller.rb | 1 + ...ise_guest_controllers_helpers_decorator.rb | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 app/controllers/devise_guest_controllers_helpers_decorator.rb 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..3126ee1be --- /dev/null +++ b/app/controllers/devise_guest_controllers_helpers_decorator.rb @@ -0,0 +1,20 @@ +module DeviseGuestControllersHelpersDecorator + def guest_user + return @guest_user if @guest_user + + if session[:guest_user_id] + @guest_user = User.unscoped.find_by(User.authentication_keys.first => session[:guest_user_id]) rescue nil + @guest_user = nil if @guest_user.respond_to? :guest and !@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) From 7ac4bdfcf54789afd6812228fb4e25e93180bfcb Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 5 Dec 2024 15:25:32 -0800 Subject: [PATCH 2/5] rubocop --- .../devise_guest_controllers_helpers_decorator.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/devise_guest_controllers_helpers_decorator.rb b/app/controllers/devise_guest_controllers_helpers_decorator.rb index 3126ee1be..2c2ea5bd1 100644 --- a/app/controllers/devise_guest_controllers_helpers_decorator.rb +++ b/app/controllers/devise_guest_controllers_helpers_decorator.rb @@ -1,9 +1,15 @@ +# frozen_string_literal: true + module DeviseGuestControllersHelpersDecorator def guest_user return @guest_user if @guest_user if session[:guest_user_id] - @guest_user = User.unscoped.find_by(User.authentication_keys.first => session[:guest_user_id]) rescue nil + 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 and !@guest_user.guest end From a42a9630cc91079db02d5560d7605ea866fab6cc Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 5 Dec 2024 16:05:30 -0800 Subject: [PATCH 3/5] rubocop --- app/controllers/devise_guest_controllers_helpers_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/devise_guest_controllers_helpers_decorator.rb b/app/controllers/devise_guest_controllers_helpers_decorator.rb index 2c2ea5bd1..b689ef704 100644 --- a/app/controllers/devise_guest_controllers_helpers_decorator.rb +++ b/app/controllers/devise_guest_controllers_helpers_decorator.rb @@ -10,7 +10,7 @@ def guest_user rescue @guest_user = nil end - @guest_user = nil if @guest_user.respond_to? :guest and !@guest_user.guest + @guest_user = nil if @guest_user.respond_to? :guest && !@guest_user.guest end @guest_user ||= begin From 5e6149cd637bff16ab30cad0f1752c7f5b4c31e7 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Mon, 9 Dec 2024 16:05:23 -0800 Subject: [PATCH 4/5] call the cops --- app/controllers/devise_guest_controllers_helpers_decorator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/devise_guest_controllers_helpers_decorator.rb b/app/controllers/devise_guest_controllers_helpers_decorator.rb index b689ef704..c6a18abe5 100644 --- a/app/controllers/devise_guest_controllers_helpers_decorator.rb +++ b/app/controllers/devise_guest_controllers_helpers_decorator.rb @@ -10,7 +10,7 @@ def guest_user rescue @guest_user = nil end - @guest_user = nil if @guest_user.respond_to? :guest && !@guest_user.guest + @guest_user = nil if @guest_user.respond_to?(:guest) && !@guest_user.guest end @guest_user ||= begin From ad6a6e36190cc041cf40b4bf5fcae33dad705baf Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Tue, 17 Dec 2024 16:59:00 -0800 Subject: [PATCH 5/5] Update devise_guest_controllers_helpers_decorator.rb --- app/controllers/devise_guest_controllers_helpers_decorator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/devise_guest_controllers_helpers_decorator.rb b/app/controllers/devise_guest_controllers_helpers_decorator.rb index c6a18abe5..79d1ddda9 100644 --- a/app/controllers/devise_guest_controllers_helpers_decorator.rb +++ b/app/controllers/devise_guest_controllers_helpers_decorator.rb @@ -1,5 +1,6 @@ # 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