FIX: don't send post edit notification when hidden tags are changed

Create a hidden revision so staff can see the changed, but don't send
notifications to non-staff.
This commit is contained in:
Neil Lalonde 2019-06-04 15:48:06 -04:00
parent dd1a034e7b
commit 1cf0b549ab
3 changed files with 25 additions and 1 deletions

View File

@ -10,6 +10,8 @@ module Jobs
ActiveRecord::Base.transaction do
User.where(id: args[:user_ids]).find_each do |user|
next if post_revision.hidden && !user.staff?
PostActionNotifier.alerter.create_notification(
user,
Notification.types[:edited],

View File

@ -462,7 +462,8 @@ class PostRevisor
user_id: @post.last_editor_id,
post_id: @post.id,
number: @post.version,
modifications: modifications
modifications: modifications,
hidden: only_hidden_tags_changed?
)
end

View File

@ -753,6 +753,27 @@ describe PostRevisor do
expect(result).to eq(true)
}.to_not change { topic.reload.bumped_at }
end
it "doesn't bump topic if only staff-only tags are removed and there are no tags left" do
topic.tags = Tag.where(name: ['important', 'secret']).to_a
expect {
result = subject.revise!(Fabricate(:admin), raw: post.raw, tags: [])
expect(result).to eq(true)
}.to_not change { topic.reload.bumped_at }
end
it "creates a hidden revision" do
subject.revise!(Fabricate(:admin), raw: post.raw, tags: topic.tags.map(&:name) + ['secret'])
expect(post.reload.revisions.first.hidden).to eq(true)
end
it "doesn't notify topic owner about hidden tags" do
PostActionNotifier.enable
Jobs.run_immediately!
expect {
subject.revise!(Fabricate(:admin), raw: post.raw, tags: topic.tags.map(&:name) + ['secret'])
}.not_to change { Notification.where(notification_type: Notification.types[:edited]).count }
end
end
end