when creating a staged account, use the display name provided in the email

This commit is contained in:
Régis Hanol 2015-12-10 23:52:20 +01:00
parent 93d1cc6294
commit 323e3cee22
2 changed files with 10 additions and 6 deletions

View File

@ -47,7 +47,10 @@ module Email
@message = message
@body = body
user_email = @message.from.first
from = @message[:from].address_list.addresses.first
user_email = "#{from.local}@#{from.domain}"
user_name = from.display_name
@user = User.find_by_email(user_email)
case dest_info[:type]
@ -56,7 +59,7 @@ module Email
if @user.blank?
if SiteSetting.allow_staged_accounts
@user = create_staged_account(user_email)
@user = create_staged_account(user_email, user_name)
else
wrap_body_in_quote(user_email)
@user = Discourse.system_user
@ -97,12 +100,12 @@ module Email
raise EmailUnparsableError.new(e)
end
def create_staged_account(email)
def create_staged_account(email, name=nil)
User.create(
email: email,
username: UserNameSuggester.suggest(email),
name: User.suggest_name(email),
staged: true
username: UserNameSuggester.suggest(name.presence || email),
name: name.presence || User.suggest_name(email),
staged: true,
)
end

View File

@ -643,6 +643,7 @@ greatest show ever created. Everyone should watch it.
staged_account = User.find_by_email(user_email)
expect(staged_account).to be
expect(staged_account.name).to eq("Jake the Dog")
expect(staged_account.staged).to be(true)
post = staged_account.posts.order(id: :desc).first