mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:51:07 +08:00
FIX: Redirect user to topic they were invited to (#16298)
This did not work properly everytime because the destination URL was saved in a cookie and that can be lost for various reasons. This commit redirects the user to invited topic if it exists.
This commit is contained in:
@ -1065,10 +1065,27 @@ class UsersController < ApplicationController
|
||||
@user.enqueue_welcome_message('welcome_user') if @user.send_welcome_message
|
||||
log_on_user(@user)
|
||||
|
||||
# invites#perform_accept_invitation already sets destination_url, but
|
||||
# sometimes it is lost (user changes browser, uses incognito, etc)
|
||||
#
|
||||
# The code below checks if the user was invited and redirects them to
|
||||
# the topic they were originally invited to.
|
||||
destination_url = cookies.delete(:destination_url)
|
||||
if destination_url.blank?
|
||||
topic = Invite
|
||||
.joins(:invited_users)
|
||||
.find_by(invited_users: { user_id: @user.id })
|
||||
&.topics
|
||||
&.first
|
||||
|
||||
if @user.guardian.can_see?(topic)
|
||||
destination_url = path(topic.relative_url)
|
||||
end
|
||||
end
|
||||
|
||||
if Wizard.user_requires_completion?(@user)
|
||||
return redirect_to(wizard_path)
|
||||
elsif destination_url = cookies[:destination_url]
|
||||
cookies[:destination_url] = nil
|
||||
elsif destination_url.present?
|
||||
return redirect_to(destination_url)
|
||||
elsif SiteSetting.enable_discourse_connect_provider && payload = cookies.delete(:sso_payload)
|
||||
return redirect_to(session_sso_provider_url + "?" + payload)
|
||||
|
Reference in New Issue
Block a user