Skip to content

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

FIX: Keep deleted posts unchanged when resolving flags

Régis Hanol29f1391b63f4
diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb
index 8f4309e6750..eb1a9c49c95 100644
--- a/app/models/reviewable_flagged_post.rb
+++ b/app/models/reviewable_flagged_post.rb
@@ -14,6 +14,7 @@ class ReviewableFlaggedPost < Reviewable
agree_and_suspend: :agree_and_keep,
agree_and_edit: :agree_and_keep,
disagree_and_restore: :disagree,
+ disagree_and_keep_deleted: :disagree,
ignore_and_do_nothing: :ignore,
delete_user_block: :delete_and_block_user, # legacy name mapped to concern method
}
@@ -55,29 +56,25 @@ class ReviewableFlaggedPost < Reviewable
agree_bundle =
actions.add_bundle("#{id}-agree", icon: "thumbs-up", label: "reviewables.actions.agree.title")
- if post.user_deleted?
+ if post.user_deleted? || post.trashed?
build_action(actions, :agree_and_keep_deleted, icon: "far-eye-slash", bundle: agree_bundle)
+ elsif post.hidden?
+ build_action(actions, :agree_and_keep_hidden, icon: "far-eye-slash", bundle: agree_bundle)
else
- if !post.hidden?
- build_action(actions, :agree_and_hide, icon: "far-eye-slash", bundle: agree_bundle)
- end
-
- if post.hidden?
- build_action(actions, :agree_and_keep_hidden, icon: "far-eye-slash", bundle: agree_bundle)
- else
- build_action(actions, :agree_and_keep, icon: "far-eye", bundle: agree_bundle)
- build_action(
- actions,
- :agree_and_edit,
- icon: "pencil",
- bundle: agree_bundle,
- client_action: "edit",
- )
- end
+ build_action(actions, :agree_and_hide, icon: "far-eye-slash", bundle: agree_bundle)
+ build_action(actions, :agree_and_keep, icon: "far-eye", bundle: agree_bundle)
+ build_action(
+ actions,
+ :agree_and_edit,
+ icon: "pencil",
+ bundle: agree_bundle,
+ client_action: "edit",
+ )
end
can_delete_post_or_topic = guardian.can_delete_post_or_topic?(post)
- can_delete_existing_post_or_topic = can_delete_post_or_topic && !post.user_deleted?
+ can_delete_existing_post_or_topic =
+ can_delete_post_or_topic && !post.user_deleted? && !post.trashed?
if can_delete_existing_post_or_topic
build_action(actions, :delete_and_agree, icon: "trash-can", bundle: agree_bundle)
@@ -104,27 +101,19 @@ class ReviewableFlaggedPost < Reviewable
delete_user_actions(actions, agree_bundle)
end
- if post.user_deleted? && !user_penalized_for_deleted_post?
+ if post.user_deleted? && !post.trashed? && !user_penalized_for_deleted_post?
build_action(actions, :agree_and_restore, icon: "far-eye", bundle: agree_bundle)
end
- post_visible_or_system_user = !post.hidden? || guardian.user.is_system_user?
- if can_delete_post_or_topic || post_visible_or_system_user || !post.hidden?
- build_disagree_bundle(
- actions,
- can_delete_existing_post_or_topic:,
- post_visible_or_system_user:,
- )
+ can_ignore = post.trashed? || !post.hidden? || guardian.user.is_system_user?
+ if can_delete_post_or_topic || can_ignore
+ build_disagree_bundle(actions, can_delete_existing_post_or_topic:, can_ignore:)
end
build_unsilence_action(actions, guardian)
end
- def build_disagree_bundle(
- actions,
- can_delete_existing_post_or_topic:,
- post_visible_or_system_user:
- )
+ def build_disagree_bundle(actions, can_delete_existing_post_or_topic:, can_ignore:)
disagree_bundle =
actions.add_bundle(
"#{id}-disagree",
@@ -140,14 +129,21 @@ class ReviewableFlaggedPost < Reviewable
bundle: disagree_bundle,
)
elsif !user_penalized_for_deleted_post?
- if post.hidden?
+ if post.trashed?
+ build_action(
+ actions,
+ :disagree_and_keep_deleted,
+ icon: "far-eye-slash",
+ bundle: disagree_bundle,
+ )
+ elsif post.hidden?
build_action(actions, :disagree_and_restore, icon: "far-eye", bundle: disagree_bundle)
else
build_action(actions, :disagree, icon: "far-eye", bundle: disagree_bundle)
end
end
- if post_visible_or_system_user || user_penalized_for_deleted_post?
+ if can_ignore || user_penalized_for_deleted_post?
build_action(actions, :ignore_and_do_nothing, icon: "xmark", bundle: disagree_bundle)
end
if can_delete_existing_post_or_topic
@@ -208,7 +204,7 @@ class ReviewableFlaggedPost < Reviewable
end
def disagree_lifts_silence?
- post&.hidden? && author_silenced? && UserSilencer.was_silenced_for?(post)
+ post&.hidden? && !post.trashed? && author_silenced? && UserSilencer.was_silenced_for?(post)
end
def penalty_effect_for(action_id)
@@ -311,7 +307,7 @@ class ReviewableFlaggedPost < Reviewable
end
# Undo hide/silence if applicable
- if post&.hidden?
+ if post&.hidden? && !post.trashed?
notify_poster(performed_by)
post.acting_user = performed_by
post.unhide!
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 41130d2b156..c64df40e405 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -6411,6 +6411,10 @@ en:
title: "Restore post"
description: "Disagree with flag and restore post"
complete: "Post restored."
+ disagree_and_keep_deleted:
+ title: "Keep post deleted"
+ description: "Disagree with flag and keep the post deleted."
+ complete: "Post kept deleted."
disagree_bundle:
title: "No"
disagree:
diff --git a/spec/models/reviewable_flagged_post_spec.rb b/spec/models/reviewable_flagged_post_spec.rb
index 4f4b56ff0b2..d4d87f73376 100644
--- a/spec/models/reviewable_flagged_post_spec.rb
+++ b/spec/models/reviewable_flagged_post_spec.rb
@@ -29,6 +29,18 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
let(:score) { result.reviewable_score }
let(:guardian) { Guardian.new(moderator) }
+ it "disagrees with flags without restoring a soft-deleted post" do
+ post.update!(hidden: true)
+ post.trash!
+
+ reviewable.perform(moderator, :disagree_and_keep_deleted)
+
+ expect(reviewable.reload).to be_rejected
+ expect(score.reload).to be_disagreed
+ expect(post.reload).to be_trashed
+ expect(post).to be_hidden
+ end
+
describe "actions_for" do
it "returns appropriate defaults" do
actions = reviewable.actions_for(guardian)
@@ -149,15 +161,25 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
expect(actions.has?(:agree_and_silence)).to eq(true)
end
- 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!
+ it "offers flag resolution without visibility or delete actions for soft-deleted posts" do
+ post.update!(reply_count: 3)
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
+
+ [false, true].each do |hidden|
+ post.update!(hidden: hidden)
+
+ actions = reviewable.actions_for(guardian)
+
+ expect(actions.to_a.map(&:server_action)).to contain_exactly(
+ "agree_and_keep_deleted",
+ "disagree_and_keep_deleted",
+ "ignore_and_do_nothing",
+ "agree_and_silence",
+ "agree_and_suspend",
+ "delete_user",
+ "delete_user_block",
+ )
+ end
end
context "when flagged as potential_spam" do