2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
RSpec.describe ReviewableFlaggedPost, type: :model do
|
|
|
|
def pending_count
|
|
|
|
ReviewableFlaggedPost.default_visible.pending.count
|
|
|
|
end
|
|
|
|
|
2023-12-13 17:18:42 +08:00
|
|
|
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:post)
|
2023-12-13 17:18:42 +08:00
|
|
|
fab!(:moderator) { Fabricate(:moderator, refresh_auto_groups: true) }
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
it "sets `potential_spam` when a spam flag is added" do
|
|
|
|
reviewable = PostActionCreator.off_topic(user, post).reviewable
|
|
|
|
expect(reviewable.potential_spam?).to eq(false)
|
2023-12-13 17:18:42 +08:00
|
|
|
PostActionCreator.spam(Fabricate(:user, refresh_auto_groups: true), post)
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(reviewable.reload.potential_spam?).to eq(true)
|
|
|
|
end
|
|
|
|
|
2024-11-27 17:23:57 +08:00
|
|
|
it "sets `potentially_illegal` when an illegal flag is added" do
|
|
|
|
reviewable = PostActionCreator.off_topic(user, post).reviewable
|
|
|
|
expect(reviewable.potentially_illegal?).to eq(false)
|
|
|
|
PostActionCreator.illegal(Fabricate(:user, refresh_auto_groups: true), post)
|
|
|
|
expect(reviewable.reload.potentially_illegal?).to eq(true)
|
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
describe "actions" do
|
|
|
|
let!(:result) { PostActionCreator.spam(user, post) }
|
|
|
|
let(:reviewable) { result.reviewable }
|
|
|
|
let(:score) { result.reviewable_score }
|
|
|
|
let(:guardian) { Guardian.new(moderator) }
|
|
|
|
|
|
|
|
describe "actions_for" do
|
|
|
|
it "returns appropriate defaults" do
|
|
|
|
actions = reviewable.actions_for(guardian)
|
|
|
|
expect(actions.has?(:agree_and_hide)).to eq(true)
|
|
|
|
expect(actions.has?(:agree_and_keep)).to eq(true)
|
2024-05-24 02:21:42 +08:00
|
|
|
expect(actions.has?(:agree_and_edit)).to eq(true)
|
2019-08-01 23:23:23 +08:00
|
|
|
expect(actions.has?(:agree_and_keep_hidden)).to eq(false)
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(actions.has?(:agree_and_silence)).to eq(true)
|
|
|
|
expect(actions.has?(:agree_and_suspend)).to eq(true)
|
2021-06-15 23:35:45 +08:00
|
|
|
expect(actions.has?(:delete_user)).to eq(true)
|
|
|
|
expect(actions.has?(:delete_user_block)).to eq(true)
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(actions.has?(:disagree)).to eq(true)
|
2023-03-02 23:40:53 +08:00
|
|
|
expect(actions.has?(:ignore_and_do_nothing)).to eq(true)
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(actions.has?(:delete_and_ignore)).to eq(true)
|
2019-04-05 03:51:36 +08:00
|
|
|
expect(actions.has?(:delete_and_ignore_replies)).to eq(false)
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(actions.has?(:delete_and_agree)).to eq(true)
|
2019-04-05 03:51:36 +08:00
|
|
|
expect(actions.has?(:delete_and_replies)).to eq(false)
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
expect(actions.has?(:disagree_and_restore)).to eq(false)
|
|
|
|
end
|
|
|
|
|
2019-05-31 04:42:59 +08:00
|
|
|
it "doesn't include deletes for category topics" do
|
2019-08-06 18:26:54 +08:00
|
|
|
c = Fabricate(:category_with_definition)
|
2019-05-31 04:42:59 +08:00
|
|
|
flag = PostActionCreator.spam(user, c.topic.posts.first).reviewable
|
|
|
|
actions = flag.actions_for(guardian)
|
|
|
|
expect(actions.has?(:delete_and_ignore)).to eq(false)
|
|
|
|
expect(actions.has?(:delete_and_ignore_replies)).to eq(false)
|
|
|
|
expect(actions.has?(:delete_and_agree)).to eq(false)
|
|
|
|
expect(actions.has?(:delete_and_replies)).to eq(false)
|
|
|
|
end
|
|
|
|
|
2019-08-01 23:23:23 +08:00
|
|
|
it "changes `agree_and_keep` to `agree_and_keep_hidden` if it's been hidden" do
|
|
|
|
post.hidden = true
|
|
|
|
actions = reviewable.actions_for(guardian)
|
|
|
|
expect(actions.has?(:agree_and_keep)).to eq(false)
|
2024-05-24 02:21:42 +08:00
|
|
|
expect(actions.has?(:agree_and_edit)).to eq(false)
|
2019-08-01 23:23:23 +08:00
|
|
|
expect(actions.has?(:agree_and_keep_hidden)).to eq(true)
|
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
it "returns `agree_and_restore` if the post is user deleted" do
|
|
|
|
post.update(user_deleted: true)
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:agree_and_restore)).to eq(true)
|
|
|
|
end
|
|
|
|
|
2019-04-05 03:51:36 +08:00
|
|
|
it "returns delete replies options if there are replies" do
|
|
|
|
post.update(reply_count: 3)
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_and_agree_replies)).to eq(true)
|
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
it "returns appropriate actions for a hidden post" do
|
|
|
|
post.update(hidden: true, hidden_at: Time.now)
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:agree_and_hide)).to eq(false)
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:disagree_and_restore)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "won't return the penalty options if the user is not regular" do
|
|
|
|
post.user.update(moderator: true)
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:agree_and_silence)).to eq(false)
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:agree_and_suspend)).to eq(false)
|
|
|
|
end
|
2022-11-29 00:32:57 +08:00
|
|
|
|
2024-11-26 14:18:32 +08:00
|
|
|
it "doesn't end up with an empty ignore bundle when the post is already hidden and deleted" do
|
|
|
|
post.update!(hidden: true)
|
|
|
|
post.topic.trash!
|
|
|
|
post.trash!
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:ignore_and_do_nothing)).to eq(false)
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_and_ignore)).to eq(false)
|
|
|
|
expect(
|
|
|
|
reviewable.actions_for(guardian).bundles.find { |bundle| bundle.id.include?("-ignore") },
|
|
|
|
).to be_blank
|
|
|
|
end
|
|
|
|
|
2022-11-29 00:32:57 +08:00
|
|
|
context "when flagged as potential_spam" do
|
2024-11-27 17:23:57 +08:00
|
|
|
before { reviewable.update!(potential_spam: true, potentially_illegal: false) }
|
|
|
|
|
|
|
|
it "excludes delete action if the reviewer cannot delete the user" do
|
|
|
|
post.user.user_stat.update!(
|
|
|
|
first_post_created_at: 1.year.ago,
|
|
|
|
post_count: User::MAX_STAFF_DELETE_POST_COUNT + 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_user)).to be false
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_user_block)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes delete actions if the reviewer can delete the user" do
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_user)).to be true
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_user_block)).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when flagged as illegal" do
|
|
|
|
before { reviewable.update(potential_spam: false, potentially_illegal: true) }
|
2022-11-29 00:32:57 +08:00
|
|
|
|
|
|
|
it "excludes delete action if the reviewer cannot delete the user" do
|
|
|
|
post.user.user_stat.update!(
|
|
|
|
first_post_created_at: 1.year.ago,
|
|
|
|
post_count: User::MAX_STAFF_DELETE_POST_COUNT + 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_user)).to be false
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_user_block)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes delete actions if the reviewer can delete the user" do
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_user)).to be true
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:delete_user_block)).to be true
|
|
|
|
end
|
|
|
|
end
|
2024-01-02 18:32:50 +08:00
|
|
|
|
|
|
|
context "for ignore_and_do_nothing" do
|
|
|
|
it "does not return `ignore_and_do_nothing` when post is hidden" do
|
|
|
|
post.update(hidden: true)
|
|
|
|
|
|
|
|
expect(reviewable.actions_for(guardian).has?(:ignore_and_do_nothing)).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns `ignore_and_do_nothing` if the acting user is system" do
|
|
|
|
post.update(hidden: true)
|
|
|
|
system_guardian = Guardian.new(Discourse.system_user)
|
|
|
|
|
|
|
|
expect(reviewable.actions_for(system_guardian).has?(:ignore_and_do_nothing)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "agree_and_keep agrees with the flags and keeps the post" do
|
|
|
|
reviewable.perform(moderator, :agree_and_keep)
|
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post).not_to be_hidden
|
|
|
|
end
|
|
|
|
|
2024-05-24 02:21:42 +08:00
|
|
|
it "agree_and_keep agrees with the flags and edits the post" do
|
|
|
|
reviewable.perform(moderator, :agree_and_keep)
|
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post).not_to be_hidden
|
|
|
|
end
|
|
|
|
|
2020-03-25 05:57:44 +08:00
|
|
|
describe "with reviewable claiming enabled" do
|
|
|
|
fab!(:claimed) { Fabricate(:reviewable_claimed_topic, topic: post.topic, user: moderator) }
|
|
|
|
it "clears the claimed topic on resolve" do
|
|
|
|
SiteSetting.reviewable_claiming = "required"
|
|
|
|
reviewable.perform(moderator, :agree_and_keep)
|
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post).not_to be_hidden
|
|
|
|
expect(ReviewableClaimedTopic.where(topic_id: post.topic.id).exists?).to eq(false)
|
|
|
|
expect(
|
|
|
|
post
|
|
|
|
.topic
|
|
|
|
.reviewables
|
|
|
|
.first
|
|
|
|
.history
|
|
|
|
.where(reviewable_history_type: ReviewableHistory.types[:unclaimed])
|
|
|
|
.size,
|
|
|
|
).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
it "agree_and_suspend agrees with the flags and keeps the post" do
|
|
|
|
reviewable.perform(moderator, :agree_and_suspend)
|
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post).not_to be_hidden
|
|
|
|
end
|
|
|
|
|
|
|
|
it "agree_and_silence agrees with the flags and keeps the post" do
|
|
|
|
reviewable.perform(moderator, :agree_and_silence)
|
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post).not_to be_hidden
|
|
|
|
end
|
|
|
|
|
|
|
|
it "agree_and_hide agrees with the flags and hides the post" do
|
|
|
|
reviewable.perform(moderator, :agree_and_hide)
|
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post).to be_hidden
|
|
|
|
end
|
|
|
|
|
|
|
|
it "agree_and_restore agrees with the flags and restores the post" do
|
|
|
|
post.update(user_deleted: true)
|
|
|
|
reviewable.perform(moderator, :agree_and_restore)
|
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post.user_deleted?).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "supports deleting a spammer" do
|
2021-06-15 23:35:45 +08:00
|
|
|
reviewable.perform(moderator, :delete_user_block)
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post.reload.deleted_at).to be_present
|
|
|
|
expect(User.find_by(id: reviewable.target_created_by_id)).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores the flags" do
|
2023-03-02 23:40:53 +08:00
|
|
|
reviewable.perform(moderator, :ignore_and_do_nothing)
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(reviewable).to be_ignored
|
|
|
|
expect(score.reload).to be_ignored
|
|
|
|
end
|
|
|
|
|
2019-04-05 03:51:36 +08:00
|
|
|
it "delete_and_ignore ignores the flags and deletes post" do
|
2019-01-04 01:03:01 +08:00
|
|
|
reviewable.perform(moderator, :delete_and_ignore)
|
|
|
|
expect(reviewable).to be_ignored
|
|
|
|
expect(score.reload).to be_ignored
|
|
|
|
expect(post.reload.deleted_at).to be_present
|
|
|
|
end
|
|
|
|
|
2019-04-05 03:51:36 +08:00
|
|
|
it "delete_and_ignore_replies ignores the flags and deletes post + replies" do
|
2020-02-18 00:30:33 +08:00
|
|
|
reply = create_reply(post)
|
|
|
|
nested_reply = create_reply(reply)
|
2019-04-05 03:51:36 +08:00
|
|
|
post.reload
|
|
|
|
|
|
|
|
reviewable.perform(moderator, :delete_and_ignore_replies)
|
|
|
|
expect(reviewable).to be_ignored
|
|
|
|
expect(score.reload).to be_ignored
|
|
|
|
expect(post.reload.deleted_at).to be_present
|
|
|
|
expect(reply.reload.deleted_at).to be_present
|
2019-05-01 00:54:53 +08:00
|
|
|
expect(nested_reply.reload.deleted_at).to be_present
|
2019-04-05 03:51:36 +08:00
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
it "delete_and_agree agrees with the flags and deletes post" do
|
|
|
|
reviewable.perform(moderator, :delete_and_agree)
|
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post.reload.deleted_at).to be_present
|
|
|
|
end
|
|
|
|
|
2019-04-05 03:51:36 +08:00
|
|
|
it "delete_and_agree_replies agrees w/ the flags and deletes post + replies" do
|
2020-02-18 00:30:33 +08:00
|
|
|
reply = create_reply(post)
|
|
|
|
nested_reply = create_reply(reply)
|
2019-04-05 03:51:36 +08:00
|
|
|
post.reload
|
|
|
|
|
|
|
|
reviewable.perform(moderator, :delete_and_agree_replies)
|
|
|
|
expect(reviewable).to be_approved
|
|
|
|
expect(score.reload).to be_agreed
|
|
|
|
expect(post.reload.deleted_at).to be_present
|
|
|
|
expect(reply.reload.deleted_at).to be_present
|
2019-05-01 00:54:53 +08:00
|
|
|
expect(nested_reply.reload.deleted_at).to be_present
|
2019-04-05 03:51:36 +08:00
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
it "disagrees with the flags" do
|
|
|
|
reviewable.perform(moderator, :disagree)
|
|
|
|
expect(reviewable).to be_rejected
|
|
|
|
expect(score.reload).to be_disagreed
|
|
|
|
end
|
|
|
|
|
|
|
|
it "disagrees with the flags and restores the post" do
|
|
|
|
post.update(hidden: true, hidden_at: Time.now)
|
|
|
|
reviewable.perform(moderator, :disagree_and_restore)
|
|
|
|
expect(reviewable).to be_rejected
|
|
|
|
expect(score.reload).to be_disagreed
|
|
|
|
expect(post.user_deleted?).to eq(false)
|
2019-04-12 04:21:00 +08:00
|
|
|
expect(post.hidden?).to eq(false)
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "pending count" do
|
|
|
|
it "increments the numbers correctly" do
|
|
|
|
expect(pending_count).to eq(0)
|
|
|
|
|
|
|
|
result = PostActionCreator.off_topic(user, post)
|
|
|
|
expect(pending_count).to eq(1)
|
|
|
|
|
|
|
|
result.reviewable.perform(Discourse.system_user, :disagree)
|
|
|
|
expect(pending_count).to eq(0)
|
|
|
|
end
|
|
|
|
|
2019-05-08 01:25:11 +08:00
|
|
|
it "respects `reviewable_default_visibility`" do
|
|
|
|
Reviewable.set_priorities(high: 7.5)
|
|
|
|
SiteSetting.reviewable_default_visibility = "high"
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(pending_count).to eq(0)
|
|
|
|
|
|
|
|
PostActionCreator.off_topic(user, post)
|
|
|
|
expect(pending_count).to eq(0)
|
|
|
|
|
|
|
|
PostActionCreator.spam(moderator, post)
|
|
|
|
expect(pending_count).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should reset counts when a topic is deleted" do
|
|
|
|
PostActionCreator.off_topic(user, post)
|
|
|
|
expect(pending_count).to eq(1)
|
|
|
|
|
|
|
|
PostDestroyer.new(moderator, post).destroy
|
|
|
|
expect(pending_count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not review non-human users" do
|
|
|
|
post = create_post(user: Discourse.system_user)
|
|
|
|
reviewable = PostActionCreator.off_topic(user, post).reviewable
|
|
|
|
expect(reviewable).to be_blank
|
|
|
|
expect(pending_count).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should ignore handled flags" do
|
|
|
|
post = create_post
|
|
|
|
reviewable = PostActionCreator.off_topic(user, post).reviewable
|
|
|
|
expect(post.hidden).to eq(false)
|
|
|
|
expect(post.hidden_at).to be_blank
|
|
|
|
|
2023-03-02 23:40:53 +08:00
|
|
|
reviewable.perform(moderator, :ignore_and_do_nothing)
|
2019-01-04 01:03:01 +08:00
|
|
|
expect(pending_count).to eq(0)
|
|
|
|
|
|
|
|
post.reload
|
|
|
|
expect(post.hidden).to eq(false)
|
|
|
|
expect(post.hidden_at).to be_blank
|
|
|
|
|
|
|
|
post.hide!(PostActionType.types[:off_topic])
|
|
|
|
|
|
|
|
post.reload
|
|
|
|
expect(post.hidden).to eq(true)
|
|
|
|
expect(post.hidden_at).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-30 21:27:52 +08:00
|
|
|
describe "#perform_delete_and_agree" do
|
|
|
|
it "notifies the user about the flagged post deletion" do
|
|
|
|
reviewable = Fabricate(:reviewable_flagged_post)
|
|
|
|
reviewable.add_score(
|
|
|
|
moderator,
|
|
|
|
PostActionType.types[:spam],
|
|
|
|
created_at: reviewable.created_at,
|
|
|
|
)
|
|
|
|
|
|
|
|
reviewable.perform(moderator, :delete_and_agree)
|
|
|
|
|
|
|
|
assert_pm_creation_enqueued(reviewable.post.user_id, "flags_agreed_and_post_deleted")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-18 00:30:33 +08:00
|
|
|
describe "#perform_delete_and_agree_replies" do
|
2021-11-24 23:28:20 +08:00
|
|
|
let(:flagged_post) { Fabricate(:reviewable_flagged_post) }
|
|
|
|
let!(:reply) { create_reply(flagged_post.target) }
|
|
|
|
|
2020-02-18 00:30:33 +08:00
|
|
|
before { flagged_post.target.update(reply_count: 1) }
|
|
|
|
|
2021-11-24 23:28:20 +08:00
|
|
|
it "ignore flagged replies" do
|
|
|
|
flagged_reply = Fabricate(:reviewable_flagged_post, target: reply)
|
2020-02-18 00:30:33 +08:00
|
|
|
flagged_post.perform(moderator, :delete_and_agree_replies)
|
|
|
|
|
2021-12-09 01:12:24 +08:00
|
|
|
expect(flagged_reply.reload).to be_ignored
|
2020-02-18 00:30:33 +08:00
|
|
|
end
|
2021-11-24 23:28:20 +08:00
|
|
|
|
2022-01-08 01:53:31 +08:00
|
|
|
it "notifies users that responded to flagged post" do
|
2021-11-24 23:28:20 +08:00
|
|
|
SiteSetting.notify_users_after_responses_deleted_on_flagged_post = true
|
|
|
|
flagged_post.perform(moderator, :delete_and_agree_replies)
|
|
|
|
|
|
|
|
expect(Jobs::SendSystemMessage.jobs.size).to eq(2)
|
|
|
|
expect(Jobs::SendSystemMessage.jobs.last["args"].first["message_type"]).to eq(
|
|
|
|
"flags_agreed_and_post_deleted_for_responders",
|
|
|
|
)
|
|
|
|
end
|
2022-01-08 01:53:31 +08:00
|
|
|
|
2022-11-30 01:18:07 +08:00
|
|
|
it "skips responders notification when the score type doesn't match any post action flag type" do
|
|
|
|
flagged_post.reviewable_scores.first.update!(
|
|
|
|
reviewable_score_type: ReviewableScore.types[:needs_approval],
|
|
|
|
)
|
|
|
|
|
|
|
|
expect { flagged_post.perform(moderator, :delete_and_agree_replies) }.not_to change(
|
|
|
|
Jobs::SendSystemMessage.jobs,
|
|
|
|
:size,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2022-01-08 01:53:31 +08:00
|
|
|
it "ignores flagged responses" do
|
|
|
|
SiteSetting.notify_users_after_responses_deleted_on_flagged_post = true
|
|
|
|
flagged_reply = Fabricate(:reviewable_flagged_post, target: reply)
|
2023-03-02 23:40:53 +08:00
|
|
|
Fabricate(
|
|
|
|
:post,
|
|
|
|
reply_to_post_number: flagged_reply.target.post_number,
|
|
|
|
topic: flagged_reply.target.topic,
|
|
|
|
)
|
2022-01-08 01:53:31 +08:00
|
|
|
flagged_post.perform(moderator, :delete_and_agree_replies)
|
|
|
|
|
2021-12-09 01:12:24 +08:00
|
|
|
expect(flagged_reply.reload).to be_ignored
|
2022-01-08 01:53:31 +08:00
|
|
|
end
|
2020-02-18 00:30:33 +08:00
|
|
|
end
|
|
|
|
|
2019-10-02 05:33:53 +08:00
|
|
|
describe "#perform_disagree_and_restore" do
|
2019-08-30 21:27:52 +08:00
|
|
|
it "notifies the user about the flagged post being restored" do
|
|
|
|
reviewable = Fabricate(:reviewable_flagged_post)
|
|
|
|
reviewable.post.update(
|
|
|
|
hidden: true,
|
|
|
|
hidden_at: Time.zone.now,
|
|
|
|
hidden_reason_id: PostActionType.types[:spam],
|
|
|
|
)
|
|
|
|
|
2019-10-02 05:33:53 +08:00
|
|
|
reviewable.perform(moderator, :disagree_and_restore)
|
2019-08-30 21:27:52 +08:00
|
|
|
|
|
|
|
assert_pm_creation_enqueued(reviewable.post.user_id, "flags_disagreed")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-11 01:09:04 +08:00
|
|
|
describe "recalculating the reviewable score" do
|
|
|
|
let(:expected_score) { 8 }
|
|
|
|
let(:reviewable) { Fabricate(:reviewable_flagged_post, score: expected_score) }
|
|
|
|
|
|
|
|
it "doesn't recalculate the score after ignore" do
|
2023-03-02 23:40:53 +08:00
|
|
|
reviewable.perform(moderator, :ignore_and_do_nothing)
|
2021-05-11 01:09:04 +08:00
|
|
|
|
|
|
|
expect(reviewable.score).to eq(expected_score)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't recalculate the score after disagree" do
|
|
|
|
reviewable.perform(moderator, :disagree)
|
|
|
|
|
|
|
|
expect(reviewable.score).to eq(expected_score)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-30 21:27:52 +08:00
|
|
|
def assert_pm_creation_enqueued(user_id, pm_type)
|
|
|
|
expect(Jobs::SendSystemMessage.jobs.length).to eq(1)
|
2022-11-30 01:18:07 +08:00
|
|
|
job = Jobs::SendSystemMessage.jobs[0]
|
|
|
|
expect(job["args"][0]["user_id"]).to eq(user_id)
|
|
|
|
expect(job["args"][0]["message_type"]).to eq(pm_type)
|
2019-08-30 21:27:52 +08:00
|
|
|
end
|
2020-02-18 00:30:33 +08:00
|
|
|
|
|
|
|
def create_reply(post)
|
|
|
|
PostCreator.create(
|
|
|
|
Fabricate(:user),
|
|
|
|
raw: "this is the reply text",
|
|
|
|
reply_to_post_number: post.post_number,
|
|
|
|
topic_id: post.topic,
|
|
|
|
)
|
|
|
|
end
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|