FIX: Discourse Connect fixes for full page login (#29915)

This commit is contained in:
Jan Cernik 2024-11-25 18:06:14 -03:00 committed by GitHub
parent 5e734516db
commit a964e62cd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 106 additions and 10 deletions

View File

@ -116,8 +116,15 @@ export default class LoginPageController extends Controller {
return getURL("/u/admin-login");
}
get shouldTriggerRouteAction() {
return (
!this.siteSettings.experimental_full_page_login ||
this.siteSettings.enable_discourse_connect
);
}
@action
showLoginPage() {
showFullPageLogin() {
this.showLogin = true;
}

View File

@ -54,12 +54,6 @@ export default class SignupPageController extends Controller.extend(
}
this.fetchConfirmationValue();
if (this.skipConfirmation) {
this.performAccountCreation().finally(() =>
this.set("skipConfirmation", false)
);
}
}
@bind
@ -342,6 +336,14 @@ export default class SignupPageController extends Controller.extend(
return this._hpPromise;
}
handleSkipConfirmation() {
if (this.skipConfirmation) {
this.performAccountCreation().finally(() =>
this.set("skipConfirmation", false)
);
}
}
performAccountCreation() {
if (
!this._challengeDate ||

View File

@ -146,6 +146,7 @@ export default {
Object.keys(createAccountProps || {}).forEach((key) => {
signupController.set(key, createAccountProps[key]);
});
signupController.handleSkipConfirmation();
});
} else {
modal.show(CreateAccount, { model: createAccountProps });

View File

@ -11,7 +11,8 @@ export default class LoginRoute extends DiscourseRoute {
beforeModel() {
if (
!this.siteSettings.login_required &&
!this.siteSettings.experimental_full_page_login
(!this.siteSettings.experimental_full_page_login ||
this.siteSettings.enable_discourse_connect)
) {
this.router
.replaceWith(`/${defaultHomepage()}`)

View File

@ -161,9 +161,9 @@
<DButton
@action={{if
this.siteSettings.experimental_full_page_login
this.showLoginPage
this.shouldTriggerRouteAction
(route-action "showLogin")
this.showFullPageLogin
}}
@icon="user"
@label="log_in"

View File

@ -98,6 +98,18 @@ module PageObjects
has_valid_password?
end
def has_disabled_email?
find(".create-account-email").has_css?("input[disabled]")
end
def has_disabled_name?
find(".create-account__fullname").has_css?("input[disabled]")
end
def has_disabled_username?
find(".create-account__username").has_css?("input[disabled]")
end
def click_social_button(provider)
click(".btn-social.#{provider}")
end

View File

@ -98,6 +98,18 @@ module PageObjects
has_valid_password?
end
def has_disabled_email?
find(".create-account-email").has_css?("input[disabled]")
end
def has_disabled_name?
find(".create-account__fullname").has_css?("input[disabled]")
end
def has_disabled_username?
find(".create-account__username").has_css?("input[disabled]")
end
def click_social_button(provider)
click(".btn-social.#{provider}")
end

View File

@ -171,6 +171,67 @@ shared_examples "social authentication scenarios" do |signup_page_object, login_
expect(page).to have_css(".header-dropdown-toggle.current-user")
end
end
# These tests use Google, but they should be the same for all providers
context "when opening the external auth from /login" do
before { SiteSetting.enable_google_oauth2_logins = true }
after { reset_omniauth_config(:google_oauth2) }
it "fills the signup form" do
mock_google_auth
visit("/")
signup_form.open.click_social_button("google_oauth2")
expect(signup_form).to be_open
expect(signup_form).to have_no_password_input
expect(signup_form).to have_valid_username
expect(signup_form).to have_valid_email
signup_form.click_create_account
expect(page).to have_css(".header-dropdown-toggle.current-user")
end
end
context "when overriding local fields" do
before do
SiteSetting.enable_google_oauth2_logins = true
SiteSetting.auth_overrides_name = true
SiteSetting.auth_overrides_username = true
end
after { reset_omniauth_config(:google_oauth2) }
it "fills the signup form and disables the inputs" do
mock_google_auth
visit("/")
signup_form.open.click_social_button("google_oauth2")
expect(signup_form).to be_open
expect(signup_form).to have_no_password_input
expect(signup_form).to have_valid_username
expect(signup_form).to have_valid_email
expect(signup_form).to have_disabled_username
expect(signup_form).to have_disabled_email
expect(signup_form).to have_disabled_name
signup_form.click_create_account
expect(page).to have_css(".header-dropdown-toggle.current-user")
end
end
context "when skipping the signup form" do
before do
SiteSetting.enable_google_oauth2_logins = true
SiteSetting.auth_skip_create_confirm = true
end
after { reset_omniauth_config(:google_oauth2) }
it "creates the account directly" do
mock_google_auth
visit("/")
signup_form.open.click_social_button("google_oauth2")
expect(page).to have_css(".header-dropdown-toggle.current-user")
end
end
end
context "when user exists" do