mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 08:43:25 +08:00
FEATURE: Add fallback to suggested value when auth_overrides_username (#16612)
If the identity provider does not provide a precise username value, then we should use our UserNameSuggester to generate one and use it for the override. This makes the override consistent with initial account creation.
This commit is contained in:
parent
a35837dc0b
commit
485fc4636a
|
@ -83,8 +83,8 @@ class Auth::Result
|
|||
|
||||
def apply_user_attributes!
|
||||
change_made = false
|
||||
if (SiteSetting.auth_overrides_username? || overrides_username) && username.present?
|
||||
change_made = UsernameChanger.override(user, username)
|
||||
if (SiteSetting.auth_overrides_username? || overrides_username) && (resolved_username = resolve_username).present?
|
||||
change_made = UsernameChanger.override(user, resolved_username)
|
||||
end
|
||||
|
||||
if (SiteSetting.auth_overrides_email || overrides_email || user&.email&.ends_with?(".invalid")) &&
|
||||
|
@ -213,6 +213,6 @@ class Auth::Result
|
|||
end
|
||||
end
|
||||
|
||||
UserNameSuggester.suggest(*username_suggester_attributes)
|
||||
UserNameSuggester.suggest(*username_suggester_attributes, current_username: user&.username)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,6 +51,15 @@ describe Auth::Result do
|
|||
expect(user.name).to eq(new_name)
|
||||
end
|
||||
|
||||
it "overrides username with suggested value if missing" do
|
||||
SiteSetting.auth_overrides_username = true
|
||||
|
||||
result.username = nil
|
||||
result.apply_user_attributes!
|
||||
|
||||
expect(user.username).to eq("New_Name")
|
||||
end
|
||||
|
||||
it "updates the user's email if currently invalid" do
|
||||
user.update!(email: "someemail@discourse.org")
|
||||
expect { result.apply_user_attributes! }.not_to change { user.email }
|
||||
|
|
Loading…
Reference in New Issue
Block a user