A platform for community discussion. Free, open, simple.
FIX: Attribute invitation emails to the actual inviter (#43799)
Natalie Taydd0c1c122928
diff --git a/app/models/topic.rb b/app/models/topic.rbindex 7ef0ab9bb85..e527d204efe 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -2182,8 +2182,8 @@ class Topic < ActiveRecord::Basedata: {topic_title: title,display_username: invited_by.username,- original_user_id: user.id,- original_username: user.username,+ original_user_id: invited_by.id,+ original_username: invited_by.username,}.to_json,)enddiff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rbindex f3f620ee7d1..cbe63f65d20 100644--- a/spec/mailers/user_notifications_spec.rb+++ b/spec/mailers/user_notifications_spec.rb@@ -1443,6 +1443,39 @@ RSpec.describe UserNotifications doendend+ describe "invitation email attribution" do+ fab!(:inviter) { Fabricate(:user, trust_level: TrustLevel[2], name: "Message Inviter") }+ fab!(:invitee, :user)++ %i[private_message topic].each do |destination|+ it "identifies the inviter when another user started the #{destination}" do+ SiteSetting.enable_names = true+ SiteSetting.display_name_on_email_from = true+ post =+ if destination == :private_message+ Fabricate(:private_message_post, recipient: inviter)+ else+ Fabricate(:post)+ end++ post.topic.invite(inviter, invitee.username)+ notification = invitee.notifications.find_by!(topic_id: post.topic_id)+ notification_type = "invited_to_#{destination}"+ mail =+ UserNotifications.public_send(+ "user_#{notification_type}",+ invitee,+ notification_type: notification_type,+ notification_data_hash: notification.data_hash,+ post: notification.post,+ )++ expect(mail.text_part.body.decoded).to include("#{inviter.username} invited you")+ expect(mail[:from].display_names).to eq([inviter.name])+ end+ end+ end+describe "user invited to a private message" doinclude_examples "notification email building" dolet(:notification_type) { :invited_to_private_message }