mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 07:38:01 +08:00
FEATURE: Notify flaggers when flagged post is edited by author
This commit is contained in:
parent
0e9ec237a2
commit
62aacce8f4
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user