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

This commit is contained in:
Andrei Prigorshnev 2022-02-07 13:02:26 +01:00 committed by GitHub
parent 357186ab7e
commit 404f882e5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -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

View File

@ -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 = "billmailbox@test.com"
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 = "billmailbox@test.com"
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