Made recommended changes to moderator reports (see #4267)

This commit is contained in:
BrokenEagle
2020-01-21 01:26:52 +00:00
parent 29e8b89c93
commit 5f746c1a34
13 changed files with 21 additions and 17 deletions

View File

@@ -184,6 +184,6 @@ class ForumTopic < ApplicationRecord
end
def viewable_moderation_reports
CurrentUser.is_moderator? ? moderation_reports : []
CurrentUser.is_moderator? ? moderation_reports.recent : []
end
end

View File

@@ -2,9 +2,13 @@ class ModerationReport < ApplicationRecord
belongs_to :model, polymorphic: true
belongs_to_creator
validates :reason, presence: true
after_create :create_forum_post!
scope :user, -> { where(model_type: "User") }
scope :comment, -> { where(model_type: "Comment") }
scope :forum_post, -> { where(model_type: "ForumPost") }
scope :recent, -> { where("moderation_reports.created_at >= ?", 1.week.ago) }
def forum_topic_title
"Reports requiring moderation"
@@ -54,8 +58,4 @@ class ModerationReport < ApplicationRecord
q.apply_default_order(params)
end
def self.prune!
where("created_at < ?", 1.week.ago).delete_all
end
end

View File

@@ -1814,6 +1814,6 @@ class Post < ApplicationRecord
end
def viewable_moderation_reports
CurrentUser.is_moderator? ? moderation_reports : []
CurrentUser.is_moderator? ? moderation_reports.recent : []
end
end

View File

@@ -814,6 +814,6 @@ class User < ApplicationRecord
end
def viewable_moderation_reports
!is_moderator? && CurrentUser.is_moderator? ? moderation_reports : []
CurrentUser.is_moderator? ? moderation_reports.recent : []
end
end