From c10d582e2a16570664f907ec30c8fee538152cfe Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Thu, 21 Oct 2021 12:34:06 -0400 Subject: [PATCH] Ensure shown vomit reactions have reactable (#15153) This is the counter-argument to #15152 - filter in the controller rather than adding lots of conditional logic to the view to handle the case where there was a vomit reaction left for a deleted user causing the moderation reports page to fail to load. --- .../admin/feedback_messages_controller.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/feedback_messages_controller.rb b/app/controllers/admin/feedback_messages_controller.rb index e550b046e..a269fc7d4 100644 --- a/app/controllers/admin/feedback_messages_controller.rb +++ b/app/controllers/admin/feedback_messages_controller.rb @@ -78,16 +78,21 @@ module Admin private def get_vomits + status, limit = case params[:status] + when "Open", ->(s) { s.blank? } + ["valid", nil] + when "Resolved" + ["confirmed", 10] + else + ["invalid", 10] + end q = Reaction.includes(:user, :reactable) + .where(category: "vomit", status: status) .select(:id, :user_id, :reactable_type, :reactable_id) .order(updated_at: :desc) - if params[:status] == "Open" || params[:status].blank? - q.where(category: "vomit", status: "valid") - elsif params[:status] == "Resolved" - q.where(category: "vomit", status: "confirmed").limit(10) - else - q.where(category: "vomit", status: "invalid").limit(10) - end + .limit(limit) + # don't show reactions where the reactable was not found + q.select(&:reactable) end def send_slack_message(params)