Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Notify flaggers when flagged post is edited by author

Gerhard Schlager62aacce8f4c3
diff --git a/app/services/post_action_notifier.rb b/app/services/post_action_notifier.rb
index f5e5a7f2a40..b9d19979969 100644
--- a/app/services/post_action_notifier.rb
+++ b/app/services/post_action_notifier.rb
@@ -109,4 +109,17 @@ class PostActionNotifier
)
end
+ def self.after_post_unhide(post, flaggers)
+ return if @disabled || post.last_editor.blank? || flaggers.blank?
+
+ flaggers.each do |flagger|
+ alerter.create_notification(
+ flagger,
+ Notification.types[:edited],
+ post,
+ display_username: post.last_editor.username,
+ acting_user_id: post.last_editor.id
+ )
+ end
+ end
end
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index 5a5af07376a..3a1a55d3f12 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -405,10 +405,15 @@ class PostRevisor
def remove_flags_and_unhide_post
return unless editing_a_flagged_and_hidden_post?
+
+ flaggers = []
@post.post_actions.where(post_action_type_id: PostActionType.flag_types_without_custom.values).each do |action|
+ flaggers << action.user if action.user
action.remove_act!(Discourse.system_user)
end
+
@post.unhide!
+ PostActionNotifier.after_post_unhide(@post, flaggers)
end
def editing_a_flagged_and_hidden_post?
diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb
index 8682d72811b..5743c64ca3e 100644
--- a/spec/services/post_alerter_spec.rb
+++ b/spec/services/post_alerter_spec.rb
@@ -21,6 +21,8 @@ RSpec::Matchers.define :add_notification do |user, notification_type|
supports_block_expectations
end
+RSpec::Matchers.define_negated_matcher :not_add_notification, :add_notification
+
describe PostAlerter do
let!(:evil_trout) { Fabricate(:evil_trout) }
@@ -115,6 +117,46 @@ describe PostAlerter do
expect(Notification.where(post_number: 1, topic_id: post.topic_id).count).to eq(3)
end
+
+ it 'notifies flaggers when flagged post gets unhidden by edit' do
+ post = create_post
+ walterwhite = Fabricate(:walter_white)
+ coding_horror = Fabricate(:coding_horror)
+
+ PostActionNotifier.enable
+ SiteSetting.flags_required_to_hide_post = 2
+
+ PostAction.act(evil_trout, post, PostActionType.types[:spam])
+ PostAction.act(walterwhite, post, PostActionType.types[:spam])
+
+ post.reload
+ expect(post.hidden).to eq(true)
+
+ expect {
+ post.revise(post.user, raw: post.raw + " ha I edited it ")
+ }.to add_notification(evil_trout, :edited)
+ .and add_notification(walterwhite, :edited)
+
+ post.reload
+ expect(post.hidden).to eq(false)
+
+ notification = walterwhite.notifications.last
+ expect(notification.topic_id).to eq(post.topic.id)
+ expect(notification.post_number).to eq(post.post_number)
+ expect(notification.data_hash["display_username"]).to eq(post.user.username)
+
+ PostAction.act(coding_horror, post, PostActionType.types[:spam])
+ PostAction.act(walterwhite, post, PostActionType.types[:off_topic])
+
+ post.reload
+ expect(post.hidden).to eq(true)
+
+ expect {
+ post.revise(post.user, raw: post.raw + " ha I edited it again ")
+ }.to not_add_notification(evil_trout, :edited)
+ .and not_add_notification(coding_horror, :edited)
+ .and not_add_notification(walterwhite, :edited)
+ end
end
context 'likes' do