Use better method for querying moderation reports on posts and topics
- Also moved the control logic out of the views and into the models
This commit is contained in:
@@ -49,6 +49,7 @@ class Post < ApplicationRecord
|
||||
has_many :votes, :class_name => "PostVote", :dependent => :destroy
|
||||
has_many :notes, :dependent => :destroy
|
||||
has_many :comments, -> {order("comments.id")}, :dependent => :destroy
|
||||
has_many :moderation_reports, through: :comments
|
||||
has_many :children, -> {order("posts.id")}, :class_name => "Post", :foreign_key => "parent_id"
|
||||
has_many :approvals, :class_name => "PostApproval", :dependent => :destroy
|
||||
has_many :disapprovals, :class_name => "PostDisapproval", :dependent => :destroy
|
||||
@@ -1812,10 +1813,7 @@ class Post < ApplicationRecord
|
||||
save
|
||||
end
|
||||
|
||||
def moderation_reports
|
||||
@moderation_reports ||= begin
|
||||
comments_with_reports = comments.joins(:moderation_reports).includes(:moderation_reports).distinct
|
||||
comments_with_reports.reduce([]) {|arr,comment| arr + comment.moderation_reports}
|
||||
end
|
||||
def viewable_moderation_reports
|
||||
CurrentUser.is_moderator? ? moderation_reports : []
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user