DEV: Avoid duplicating method attributes in `Auth::Result`.

This ensures that within the class, we have a consistent order of
attributes that is passed to `UsernameSuggester`.
This commit is contained in:
Alan Guo Xiang Tan 2021-02-26 09:33:20 +08:00
parent b584222419
commit 3fc72543de
1 changed files with 8 additions and 2 deletions

View File

@ -78,7 +78,7 @@ class Auth::Result
def apply_user_attributes! def apply_user_attributes!
change_made = false change_made = false
if SiteSetting.auth_overrides_username? && username.present? && username != user.username if SiteSetting.auth_overrides_username? && username.present? && username != user.username
user.username = UserNameSuggester.suggest(username || name || email, user.username) user.username = UserNameSuggester.suggest(username_suggester_attributes, user.username)
change_made = true change_made = true
end end
@ -139,7 +139,7 @@ class Auth::Result
result = { result = {
email: email, email: email,
username: UserNameSuggester.suggest(username || name || email), username: UserNameSuggester.suggest(username_suggester_attributes),
auth_provider: authenticator_name, auth_provider: authenticator_name,
email_valid: !!email_valid, email_valid: !!email_valid,
can_edit_username: can_edit_username, can_edit_username: can_edit_username,
@ -155,4 +155,10 @@ class Auth::Result
result result
end end
private
def username_suggester_attributes
username || name || email
end
end end