Skip to content

A platform for community discussion. Free, open, simple.

FIX: Redirect to wizard when setting up new instance using Discourse ID (#36993)

Penar Musaraje787072e1f9e
diff --git a/app/controllers/finish_installation_controller.rb b/app/controllers/finish_installation_controller.rb
index 579fd1130dd..6f4dd95e064 100644
--- a/app/controllers/finish_installation_controller.rb
+++ b/app/controllers/finish_installation_controller.rb
@@ -59,7 +59,7 @@ class FinishInstallationController < ApplicationController
# This gets cleared when an admin successfully actives their account
SiteSetting.global_notice = I18n.t("finish_installation.discourse_id.global_notice")
- redirect_to("/auth/discourse_id")
+ redirect_to("#{Discourse.base_path}/auth/discourse_id?origin=#{wizard_path}")
end
protected
diff --git a/spec/system/finish_installation_spec.rb b/spec/system/finish_installation_spec.rb
index 0d1eab36b8e..bc2a3b3a58d 100644
--- a/spec/system/finish_installation_spec.rb
+++ b/spec/system/finish_installation_spec.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
RSpec.describe "Finish Installation", type: :system do
+ include OmniauthHelpers
+
let(:finish_installation_page) { PageObjects::Pages::FinishInstallation.new }
context "when has_login_hint is false" do
@@ -68,6 +70,51 @@ RSpec.describe "Finish Installation", type: :system do
expect(User.count).to eq(initial_user_count)
end
+
+ it "lands the first admin user on wizard" do
+ OmniAuth.config.test_mode = true
+ OmniAuth.config.mock_auth[:discourse_id] = OmniAuth::AuthHash.new(
+ provider: "discourse_id",
+ uid: "12345",
+ info: OmniAuth::AuthHash::InfoHash.new(email: "[email protected]", nickname: "dev1"),
+ )
+
+ finish_installation_page.visit_page
+ finish_installation_page.click_login_with_discourse_id
+
+ expect(page).to have_current_path("/wizard")
+ ensure
+ reset_omniauth_config(:discourse_id)
+ end
+
+ context "when installed in a subfolder" do
+ before do
+ set_subfolder "/discuss"
+
+ stub_request(:post, "https://id.discourse.com/challenge").to_return(
+ status: 200,
+ body: {
+ domain: Discourse.current_hostname,
+ path: Discourse.base_path,
+ token: "test_token",
+ }.to_json,
+ )
+ end
+
+ it "logs in the first admin user and lands them on the wizard" do
+ OmniAuth.config.test_mode = true
+ OmniAuth.config.mock_auth[:discourse_id] = OmniAuth::AuthHash.new(
+ provider: "discourse_id",
+ uid: "12345",
+ info: OmniAuth::AuthHash::InfoHash.new(email: "[email protected]", nickname: "dev1"),
+ )
+ finish_installation_page.visit("/discuss/finish-installation")
+ finish_installation_page.click_login_with_discourse_id
+ expect(page).to have_current_path("/discuss/wizard")
+ ensure
+ reset_omniauth_config(:discourse_id)
+ end
+ end
end
context "when developer_emails is empty" do
@@ -191,6 +238,32 @@ RSpec.describe "Finish Installation", type: :system do
.submit
}.not_to change { Jobs::CriticalUserEmail.jobs.size }
end
+
+ it "redirects to the wizard after admin confirms their email" do
+ Jobs.run_immediately!
+
+ finish_installation_page
+ .visit_register
+ .select_email("[email protected]")
+ .fill_username("newadmin")
+ .fill_password("supersecurepassword")
+ .submit
+
+ expect(finish_installation_page).to be_redirected_to_confirm_email
+
+ user = User.find_by(username: "newadmin")
+ user.grant_admin!
+
+ mail = ActionMailer::Base.deliveries.first
+ expect(mail.to).to contain_exactly("[email protected]")
+ activation_link = mail.body.to_s[%r{/u/activate-account/\S+}]
+
+ activate_account_page = PageObjects::Pages::ActivateAccount.new
+ visit activation_link
+ activate_account_page.click_activate_account
+
+ expect(page).to have_current_path("/wizard")
+ end
end
end
end