A platform for community discussion. Free, open, simple.
FIX: Show inviter name in email's from field (#13141)
Dan Ungureanua5273b37f707
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rbindex fa99a5309fd..bfbce4e4aba 100644--- a/app/mailers/user_notifications.rb+++ b/app/mailers/user_notifications.rb@@ -422,7 +422,7 @@ class UserNotifications < ActionMailer::Baseuser_name = notification_data[:original_username]if post && SiteSetting.enable_names && SiteSetting.display_name_on_email_from- name = User.where(id: post.user_id).pluck_first(:name)+ name = User.where(id: notification_data[:original_user_id] || post.user_id).pluck_first(:name)user_name = name unless name.blank?enddiff --git a/app/models/topic.rb b/app/models/topic.rbindex 35ca0a1de54..c19d34d1452 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -1695,7 +1695,9 @@ class Topic < ActiveRecord::Basepost_number: 1,data: {topic_title: self.title,- display_username: username+ display_username: username,+ original_user_id: user.id,+ original_username: user.username}.to_json)enddiff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rbindex 605511ea893..3edb1f3b331 100644--- a/spec/mailers/user_notifications_spec.rb+++ b/spec/mailers/user_notifications_spec.rb@@ -972,12 +972,53 @@ describe UserNotifications doenddescribe "user invited to a topic" do+ let(:notification_type) { :invited_to_topic }+include_examples "notification email building" do- let(:notification_type) { :invited_to_topic }include_examples "respect for private_email"include_examples "no reply by email"include_examples "sets user locale"end++ context "shows the right name in 'From' field" do+ let(:inviter) { Fabricate(:user) }+ let(:invitee) { Fabricate(:user) }++ let(:notification) do+ Fabricate(:notification,+ notification_type: Notification.types[:invited_to_topic],+ user: invitee,+ topic: post.topic,+ post_number: post.post_number,+ data: {+ topic_title: post.topic.title,+ display_username: inviter.username,+ original_user_id: inviter.id,+ original_username: inviter.username+ }.to_json+ )+ end++ let(:mailer) do+ UserNotifications.public_send(+ "user_invited_to_topic",+ invitee,+ notification_type: Notification.types[notification.notification_type],+ notification_data_hash: notification.data_hash,+ post: notification.post+ )+ end++ it "sends the email as the inviter" do+ SiteSetting.enable_names = false++ expect(mailer.message.to_s).to include("From: #{inviter.username} via #{SiteSetting.title} <#{SiteSetting.notification_email}>")+ end++ it "sends the email as the inviter" do+ expect(mailer.message.to_s).to include("From: #{inviter.name} via #{SiteSetting.title} <#{SiteSetting.notification_email}>")+ end+ endenddescribe "watching first post" do