Skip to content

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

FEATURE: in result.rb don't use email for username suggestions until enabled in settings (#15586)

Andrei Prigorshnev404f882e5cff
diff --git a/lib/auth/result.rb b/lib/auth/result.rb
index 1a3efcf3031..09298af2d4e 100644
--- a/lib/auth/result.rb
+++ b/lib/auth/result.rb
@@ -196,7 +196,9 @@ class Auth::Result
end
def username_suggester_attributes
- [username, name, email]
+ attributes = [username, name]
+ attributes << email if SiteSetting.use_email_for_username_and_name_suggestions
+ attributes
end
def authenticator
diff --git a/spec/requests/omniauth_callbacks_controller_spec.rb b/spec/requests/omniauth_callbacks_controller_spec.rb
index 46f81b1d997..4378c4bd4f6 100644
--- a/spec/requests/omniauth_callbacks_controller_spec.rb
+++ b/spec/requests/omniauth_callbacks_controller_spec.rb
@@ -241,6 +241,32 @@ RSpec.describe Users::OmniauthCallbacksController do
expect(data["associate_url"]).to eq(nil)
end
+ it 'does not use email for username suggestions if disabled in settings' do
+ SiteSetting.use_email_for_username_and_name_suggestions = false
+ username = ""
+ name = ""
+ email = "[email protected]"
+ mock_auth(email, username, name)
+
+ get "/auth/google_oauth2/callback.json"
+ data = JSON.parse(cookies[:authentication_data])
+
+ expect(data["username"]).to eq("user1") # not "billmailbox" that can be extracted from email
+ end
+
+ it 'uses email for username suggestions if enabled in settings' do
+ SiteSetting.use_email_for_username_and_name_suggestions = true
+ username = ""
+ name = ""
+ email = "[email protected]"
+ mock_auth(email, username, name)
+
+ get "/auth/google_oauth2/callback.json"
+ data = JSON.parse(cookies[:authentication_data])
+
+ expect(data["username"]).to eq("billmailbox")
+ end
+
describe 'when site is invite_only' do
before do
SiteSetting.invite_only = true