mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 16:38:10 +08:00
BUGFIX: emails sent from "2 replies" as opposed to correct user
This commit is contained in:
parent
176bf41efd
commit
5267e5bea6
app
spec
@ -41,6 +41,7 @@ module Jobs
|
||||
return if seen_recently && !user.suspended?
|
||||
|
||||
# Load the post if present
|
||||
email_args[:post] ||= Post.where(id: notification.data_hash[:original_post_id].to_i).first
|
||||
email_args[:post] ||= notification.post
|
||||
email_args[:notification] = notification
|
||||
|
||||
|
@ -127,7 +127,7 @@ class UserNotifications < ActionMailer::Base
|
||||
return unless @notification = opts[:notification]
|
||||
return unless @post = opts[:post]
|
||||
|
||||
username = @notification.data_hash[:display_username]
|
||||
username = @notification.data_hash[:original_username]
|
||||
notification_type = opts[:notification_type] || Notification.types[@notification.notification_type].to_s
|
||||
|
||||
context = ""
|
||||
|
@ -140,6 +140,7 @@ class PostAlertObserver < ActiveRecord::Observer
|
||||
end
|
||||
|
||||
original_post = post
|
||||
original_username = opts[:display_username] || post.username
|
||||
|
||||
if collapsed
|
||||
post = first_unread_post(user,post.topic) || post
|
||||
@ -155,6 +156,8 @@ class PostAlertObserver < ActiveRecord::Observer
|
||||
post_number: post.post_number,
|
||||
post_action_id: opts[:post_action_id],
|
||||
data: { topic_title: post.topic.title,
|
||||
original_post_id: original_post.id,
|
||||
original_username: original_username,
|
||||
display_username: opts[:display_username] || post.user.username }.to_json)
|
||||
end
|
||||
|
||||
|
@ -101,7 +101,16 @@ describe Jobs::UserEmail do
|
||||
|
||||
context 'notification' do
|
||||
let(:post) { Fabricate(:post, user: user) }
|
||||
let!(:notification) { Fabricate(:notification, user: user, topic: post.topic, post_number: post.post_number)}
|
||||
let!(:notification) {
|
||||
Fabricate(:notification,
|
||||
user: user,
|
||||
topic: post.topic,
|
||||
post_number: post.post_number,
|
||||
data: {
|
||||
original_post_id: post.id
|
||||
}.to_json
|
||||
)
|
||||
}
|
||||
|
||||
it 'passes a notification as an argument when a notification_id is present' do
|
||||
Email::Sender.any_instance.expects(:send)
|
||||
@ -131,11 +140,17 @@ describe Jobs::UserEmail do
|
||||
before do
|
||||
@pm_from_staff = Fabricate(:post, user: Fabricate(:moderator))
|
||||
@pm_from_staff.topic.topic_allowed_users.create!(user_id: suspended.id)
|
||||
@pm_notification = Fabricate(:notification, user: suspended, topic: @pm_from_staff.topic, post_number: @pm_from_staff.post_number)
|
||||
@pm_notification = Fabricate(:notification,
|
||||
user: suspended,
|
||||
topic: @pm_from_staff.topic,
|
||||
post_number: @pm_from_staff.post_number,
|
||||
data: { original_post_id: @pm_from_staff.id }.to_json
|
||||
)
|
||||
UserNotifications.expects(:user_private_message).with(suspended, notification: @pm_notification, post: @pm_from_staff).returns(mailer)
|
||||
end
|
||||
|
||||
subject(:execute_user_email_job) { Jobs::UserEmail.new.execute(type: :user_private_message, user_id: suspended.id, notification_id: @pm_notification.id) }
|
||||
subject(:execute_user_email_job) {
|
||||
Jobs::UserEmail.new.execute(type: :user_private_message, user_id: suspended.id, notification_id: @pm_notification.id) }
|
||||
|
||||
it "sends an email" do
|
||||
execute_user_email_job
|
||||
|
@ -123,7 +123,7 @@ describe UserNotifications do
|
||||
topic: post.topic,
|
||||
notification_type: Notification.types[notification_type],
|
||||
post_number: post.post_number,
|
||||
data: {display_username: username}.to_json )
|
||||
data: {original_username: username}.to_json )
|
||||
end
|
||||
|
||||
describe '.user_mentioned' do
|
||||
|
@ -173,14 +173,14 @@ describe Notification do
|
||||
user_id: user.id,
|
||||
topic_id: 2,
|
||||
post_number: 1,
|
||||
data: '[]',
|
||||
data: {}.to_json,
|
||||
notification_type: Notification.types[:private_message])
|
||||
|
||||
other = Notification.create!(read: false,
|
||||
user_id: user.id,
|
||||
topic_id: 2,
|
||||
post_number: 1,
|
||||
data: '[]',
|
||||
data: {}.to_json,
|
||||
notification_type: Notification.types[:mentioned])
|
||||
|
||||
|
||||
@ -197,9 +197,9 @@ describe Notification do
|
||||
user = Fabricate(:user)
|
||||
|
||||
(1..3).map do |i|
|
||||
Notification.create!(read: false, user_id: user.id, topic_id: 2, post_number: i, data: '[]', notification_type: 1)
|
||||
Notification.create!(read: false, user_id: user.id, topic_id: 2, post_number: i, data: '{}', notification_type: 1)
|
||||
end
|
||||
Notification.create!(read: true, user_id: user.id, topic_id: 2, post_number: 4, data: '[]', notification_type: 1)
|
||||
Notification.create!(read: true, user_id: user.id, topic_id: 2, post_number: 4, data: '{}', notification_type: 1)
|
||||
|
||||
Notification.mark_posts_read(user,2,[1,2,3,4]).should == 3
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user