mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Keep user in same context after login (#31314)
This fixes the destination of the auth process in the following scenarios: - when landing on a PM or a topic as an anonymous user and then loggin in - when landing on a public topic, hitting Reply or Like and then logging in
This commit is contained in:
@@ -88,9 +88,6 @@ shared_examples "login scenarios" do |login_page_object|
|
||||
|
||||
# TODO: prefill username when fullpage
|
||||
if find("#username-or-email").value.blank?
|
||||
if page.has_css?("html.mobile-view", wait: 0)
|
||||
expect(page).to have_no_css(".d-modal.is-animating")
|
||||
end
|
||||
find("#username-or-email").fill_in(with: user.username)
|
||||
end
|
||||
|
||||
@@ -126,6 +123,60 @@ shared_examples "login scenarios" do |login_page_object|
|
||||
login_form.fill(username: "john", password: "supersecurepassword").click_login
|
||||
expect(page).to have_css(".header-dropdown-toggle.current-user")
|
||||
end
|
||||
|
||||
it "redirects to a PM after login" do
|
||||
EmailToken.confirm(Fabricate(:email_token, user: user).token)
|
||||
|
||||
group = Fabricate(:group, publish_read_state: true)
|
||||
Fabricate(:group_user, group: group, user: user)
|
||||
pm = Fabricate(:private_message_topic, allowed_groups: [group])
|
||||
Fabricate(:post, topic: pm, user: user, reads: 2, created_at: 1.day.ago)
|
||||
Fabricate(:group_private_message_topic, user: user, recipient_group: group)
|
||||
|
||||
visit "/t/#{pm.id}"
|
||||
find(".login-welcome .login-button").click
|
||||
login_form.fill(username: "john", password: "supersecurepassword").click_login
|
||||
|
||||
expect(page).to have_css(".header-dropdown-toggle.current-user")
|
||||
expect(page).to have_css("#topic-title")
|
||||
expect(page).to have_css(".private_message")
|
||||
end
|
||||
end
|
||||
|
||||
context "when login is not required" do
|
||||
before { SiteSetting.login_required = false }
|
||||
|
||||
it "redirects to a PM after authentication" do
|
||||
EmailToken.confirm(Fabricate(:email_token, user: user).token)
|
||||
group = Fabricate(:group, publish_read_state: true)
|
||||
Fabricate(:group_user, group: group, user: user)
|
||||
pm = Fabricate(:private_message_topic, allowed_groups: [group])
|
||||
Fabricate(:post, topic: pm, user: user, reads: 2, created_at: 1.day.ago)
|
||||
Fabricate(:group_private_message_topic, user: user, recipient_group: group)
|
||||
|
||||
visit "/t/#{pm.id}"
|
||||
find(".btn.login-button").click
|
||||
|
||||
login_form.fill(username: "john", password: "supersecurepassword").click_login
|
||||
expect(page).to have_css(".header-dropdown-toggle.current-user")
|
||||
|
||||
expect(page).to have_css("#topic-title")
|
||||
expect(page).to have_css(".private_message")
|
||||
end
|
||||
|
||||
it "redirects to a public topic when hitting Reply then logging in" do
|
||||
EmailToken.confirm(Fabricate(:email_token, user: user).token)
|
||||
topic = Fabricate(:topic)
|
||||
Fabricate(:post, topic: topic, created_at: 1.day.ago)
|
||||
|
||||
visit "/t/#{topic.id}"
|
||||
find(".topic-footer-main-buttons .btn-primary").click
|
||||
|
||||
login_form.fill(username: "john", password: "supersecurepassword").click_login
|
||||
expect(page).to have_css(".header-dropdown-toggle.current-user")
|
||||
|
||||
expect(page).to have_css("#topic-title")
|
||||
end
|
||||
end
|
||||
|
||||
context "with two-factor authentication" do
|
||||
|
||||
Reference in New Issue
Block a user