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.
This commit is contained in:
Daniel Uber 2021-10-21 12:34:06 -04:00 committed by GitHub
parent a69a97b023
commit c10d582e2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)