Skip to content

Commit

Permalink
Fix redirect errors with rails 7
Browse files Browse the repository at this point in the history
  • Loading branch information
russellporter committed Aug 1, 2024
1 parent 2d8fb75 commit dc2c90e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def after_sign_in_path_for(resource)
unless redirect_club_id.nil? then
club = Club.find_by_id(redirect_club_id)
session[:redirect_club_id] = nil
current_user.post_sign_in_clubsite_redirect_for_club(club, session)
clubsite_path(club)
else
session[:previous_url] || root_path
end
Expand Down
18 changes: 18 additions & 0 deletions app/controllers/clubs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ def index
end
end

def show_clubsite
club = Club.find_by_id(params[:club_id])
if current_user.nil?
url = club.clubsite_url('/')
else
cross_session = CrossAppSession.find_by cross_app_session_id: session[:cross_app_session_id]
# If we don't have a cross app session yet, create it.
if cross_session.nil?
cross_session = CrossAppSession.new_for_user(current_user)
session[:cross_app_session_id] = cross_session.cross_app_session_id
cross_session.save
end
url = club.clubsite_url("/users/localLogin?cross_app_session_id=" + cross_session.cross_app_session_id)
end

redirect_to url, allow_other_host: true
end

# provides a CSV file with participant counts for the club events and any child club events
def participant_counts
respond_to do |format|
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/short_links_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ShortLinksController < ApplicationController
def show
link = ShortLink.find_by!(name: params[:name])
redirect_to link.destination, status: :moved_permanently
redirect_to link.destination, status: :moved_permanently, allow_other_host: true
end
end
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def send_message
def sign_in_clubsite
if user_signed_in?
club = Club.find_by_id(params[:redirect_club_id])
redirect_to(current_user.post_sign_in_clubsite_redirect_for_club(club, session))
redirect_to(clubsite_url(club))
session[:redirect_club_id] = nil
else
session[:redirect_club_id] = params[:redirect_club_id]
Expand Down
12 changes: 0 additions & 12 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,6 @@ def self.find_all_real
User.where('users.email IS NOT NULL')
end

# Helpers
def post_sign_in_clubsite_redirect_for_club(club, session)
cross_session = CrossAppSession.find_by cross_app_session_id: session[:cross_app_session_id]
# If we don't have a cross app session yet, create it.
if cross_session.nil?
cross_session = CrossAppSession.new_for_user(self)
session[:cross_app_session_id] = cross_session.cross_app_session_id
cross_session.save
end
club.clubsite_url("/users/localLogin?cross_app_session_id=" + cross_session.cross_app_session_id)
end

def first_name
names = name.split
if names.length == 1
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
get 'events', to: 'events#index', format: true
get 'club/:club_id/events', to: 'events#index', format: true
get 'club/:club_id/participation_report', to: 'clubs#participant_counts'
get 'clubsite/:club_id', to: 'clubs#show_clubsite', as: :clubsite

get 'api/maps', to: 'maps#index'

Expand Down

0 comments on commit dc2c90e

Please sign in to comment.