A platform for community discussion. Free, open, simple.
Don't require password to create users with previous authentication (#32201)
Chris Alberti375a36e2ef25
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex dffca3503c8..b062f642c1b 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -756,11 +756,6 @@ class UsersController < ApplicationControlleractivation = UserActivator.new(user, request, session, cookies)activation.start- # just assign a password if we have an authenticator and no password- # this is the case for Twitter- user.password = SecureRandom.hex if user.password_required? && user.password.blank? &&- (authentication.has_authenticator? || associations.present?)-if user.saveauthentication.finishactivation.finishdiff --git a/app/services/user_authenticator.rb b/app/services/user_authenticator.rbindex c0ce7ef3d94..2a91ff2d64e 100644--- a/app/services/user_authenticator.rb+++ b/app/services/user_authenticator.rb@@ -20,10 +20,9 @@ class UserAuthenticatorif authenticated?@user.active = true@auth_result.apply_user_attributes!- elsif @require_password- @user.password_required!end+ @user.password_required! if !@auth_result && @require_password@user.skip_email_validation = true if @auth_result && @auth_result.skip_email_validationenddiff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex 85e5e09fff2..1bb93d6e8f7 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -942,10 +942,16 @@ RSpec.describe UsersController doproviderend- before { DiscoursePluginRegistry.register_auth_provider(plugin_auth_provider) }+ before do+ DiscoursePluginRegistry.register_auth_provider(plugin_auth_provider)+ # Tell UserAuthenticator our user authenticated previously.+ allow(UserAuthenticator).to receive(:new).and_wrap_original do |original_method, user|+ authenticated_session = { authentication: { email: "foo" } }+ original_method.call(user, authenticated_session)+ end+ endafter { DiscoursePluginRegistry.reset! }-it "creates User record" doparams = {username: "foobar",