mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: handle cases where we only pass the notification type rather than the notification id when sending user email
This commit is contained in:
@@ -48,13 +48,7 @@ module Jobs
|
|||||||
@skip_context = { type: type, user_id: user_id, to_address: to_address }
|
@skip_context = { type: type, user_id: user_id, to_address: to_address }
|
||||||
end
|
end
|
||||||
|
|
||||||
NOTIFICATIONS_SENT_BY_MAILING_LIST ||= Set.new [
|
NOTIFICATIONS_SENT_BY_MAILING_LIST ||= Set.new %w{posted replied mentioned group_mentioned quoted}
|
||||||
Notification.types[:posted],
|
|
||||||
Notification.types[:replied],
|
|
||||||
Notification.types[:mentioned],
|
|
||||||
Notification.types[:group_mentioned],
|
|
||||||
Notification.types[:quoted],
|
|
||||||
]
|
|
||||||
|
|
||||||
def message_for_email(user, post, type, notification,
|
def message_for_email(user, post, type, notification,
|
||||||
notification_type=nil, notification_data_hash=nil,
|
notification_type=nil, notification_data_hash=nil,
|
||||||
@@ -84,6 +78,13 @@ module Jobs
|
|||||||
email_args[:notification_type] ||= notification_type || notification.try(:notification_type)
|
email_args[:notification_type] ||= notification_type || notification.try(:notification_type)
|
||||||
email_args[:notification_data_hash] ||= notification_data_hash || notification.try(:data_hash)
|
email_args[:notification_data_hash] ||= notification_data_hash || notification.try(:data_hash)
|
||||||
|
|
||||||
|
unless String === email_args[:notification_type]
|
||||||
|
if Numeric === email_args[:notification_type]
|
||||||
|
email_args[:notification_type] = Notification.types[email_args[:notification_type]]
|
||||||
|
end
|
||||||
|
email_args[:notification_type] = email_args[:notification_type].to_s
|
||||||
|
end
|
||||||
|
|
||||||
if user.mailing_list_mode? &&
|
if user.mailing_list_mode? &&
|
||||||
!post.topic.private_message? &&
|
!post.topic.private_message? &&
|
||||||
NOTIFICATIONS_SENT_BY_MAILING_LIST.include?(email_args[:notification_type])
|
NOTIFICATIONS_SENT_BY_MAILING_LIST.include?(email_args[:notification_type])
|
||||||
|
|||||||
@@ -195,7 +195,10 @@ describe Jobs::UserEmail do
|
|||||||
it "doesn't send the mail if the user is using mailing list mode" do
|
it "doesn't send the mail if the user is using mailing list mode" do
|
||||||
Email::Sender.any_instance.expects(:send).never
|
Email::Sender.any_instance.expects(:send).never
|
||||||
user.update_column(:mailing_list_mode, true)
|
user.update_column(:mailing_list_mode, true)
|
||||||
|
# sometimes, we pass the notification_id
|
||||||
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
||||||
|
# other times, we only pass the type of notification
|
||||||
|
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_type: "posted", post_id: post.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't send the email if the post has been user deleted" do
|
it "doesn't send the email if the post has been user deleted" do
|
||||||
|
|||||||
Reference in New Issue
Block a user