FIX: Empty post reviewable ignore bundle causing client errors (#29932)
We ran into an edge case where it was possible for a ReviewableFlaggedPost to end up in a state where it was hidden and the topic was already deleted. This meant that the Ignore action bundle for the reviewable ended up empty, with no associated actions. This commit fixes the server-side issue where this was ending up empty. A further commit will aim to make the client more resilient to these issues by gracefully failing if a reviewable action bundle is detected with no associated actions.
This commit is contained in:
parent
15a61a0c1f
commit
c7e471d35a
|
@ -109,6 +109,13 @@ class ReviewableFlaggedPost < Reviewable
|
|||
build_action(actions, :disagree, icon: "thumbs-down")
|
||||
end
|
||||
|
||||
post_visible_or_system_user = !post.hidden? || guardian.user.is_system_user?
|
||||
can_delete_post_or_topic = guardian.can_delete_post_or_topic?(post)
|
||||
|
||||
# We must return early in this case otherwise we can end up with a bundle
|
||||
# with no associated actions, which is not valid on the client.
|
||||
return if !can_delete_post_or_topic && !post_visible_or_system_user
|
||||
|
||||
ignore =
|
||||
actions.add_bundle(
|
||||
"#{id}-ignore",
|
||||
|
@ -116,10 +123,10 @@ class ReviewableFlaggedPost < Reviewable
|
|||
label: "reviewables.actions.ignore.title",
|
||||
)
|
||||
|
||||
if !post.hidden? || guardian.user.is_system_user?
|
||||
if post_visible_or_system_user
|
||||
build_action(actions, :ignore_and_do_nothing, icon: "up-right-from-square", bundle: ignore)
|
||||
end
|
||||
if guardian.can_delete_post_or_topic?(post)
|
||||
if can_delete_post_or_topic
|
||||
build_action(actions, :delete_and_ignore, icon: "trash-can", bundle: ignore)
|
||||
if post.reply_count > 0
|
||||
build_action(
|
||||
|
|
|
@ -83,6 +83,17 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
|
|||
expect(reviewable.actions_for(guardian).has?(:agree_and_suspend)).to eq(false)
|
||||
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!
|
||||
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
|
||||
|
||||
context "when flagged as potential_spam" do
|
||||
before { reviewable.update!(potential_spam: true) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue