FIX: notifications inconsistencies + never notify system user

This commit is contained in:
Régis Hanol 2015-04-01 11:55:59 +02:00
parent 6137a5f00b
commit eec1921ba9
4 changed files with 9 additions and 17 deletions

View File

@ -188,7 +188,7 @@ class PostAction < ActiveRecord::Base
return if staff_already_replied?(related_post.topic)
message_key = "flags_dispositions.#{disposition}"
message_key << "_and_deleted" if delete_post
related_post.topic.add_moderator_post(moderator, I18n.t(message_key), skip_notifications: true)
related_post.topic.add_moderator_post(moderator, I18n.t(message_key))
end
def staff_already_replied?(topic)

View File

@ -10,14 +10,14 @@ class PostAlerter
def after_create_post(post)
if post.topic.private_message?
# If it's a private message, notify the topic_allowed_users
post.topic.all_allowed_users.reject{ |user| user.id == post.user_id }.each do |user|
next if user.blank?
post.topic.all_allowed_users.reject do |user|
user.blank? ||
user.id == Discourse::SYSTEM_USER_ID ||
user.id == post.user_id
end.each do |user|
if TopicUser.get(post.topic, user).try(:notification_level) == TopicUser.notification_levels[:tracking]
next unless post.reply_to_post_number
next unless post.reply_to_post.user_id == user.id
next unless post.reply_to_post_number || post.reply_to_post.user_id == user.id
end
create_notification(user, Notification.types[:private_message], post)
end
elsif post.post_type != Post.types[:moderator_action]
@ -82,6 +82,7 @@ class PostAlerter
def create_notification(user, type, post, opts={})
return if user.blank?
return if user.id == Discourse::SYSTEM_USER_ID
# Make sure the user can see the post
return unless Guardian.new(user).can_see?(post)

View File

@ -97,7 +97,7 @@ class PostCreator
if @post && @post.errors.empty?
publish
PostAlerter.post_created(@post) unless @opts[:import_mode] || @opts[:skip_notifications]
PostAlerter.post_created(@post) unless @opts[:import_mode]
track_latest_on_category
enqueue_jobs

View File

@ -507,15 +507,6 @@ describe PostAction do
expect(topic.posts.count).to eq(1)
end
it "should not generate a notification for auto-message" do
post = create_post
PostAction.act(moderator, post, PostActionType.types[:spam], message: "WAT")
PostAlerter.expects(:post_created).never
PostAction.agree_flags!(post, admin)
end
end
end