Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix guest lookup to be unscoped #2395

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions app/controllers/devise_guest_controllers_helpers_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An override comment could be useful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear there was one. but yes I 100% agree with you

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)
Loading