FEATURE: New site setting min_flags_staff_visibility

When set higher than 1, flags won't show up for staff in the admin
section unless the minimum threshold of flags on a post is reached.
This commit is contained in:
Robin Ward
2018-05-07 15:14:18 -04:00
parent 84cc52d8fc
commit ac60a84329
6 changed files with 99 additions and 9 deletions

View File

@@ -52,13 +52,22 @@ class PostAction < ActiveRecord::Base
end
def self.update_flagged_posts_count
posts_flagged_count = PostAction.active
flagged_relation = PostAction.active
.flags
.joins(post: :topic)
.where('posts.deleted_at' => nil)
.where('topics.deleted_at' => nil)
.where('posts.user_id > 0')
.count('DISTINCT posts.id')
.group("posts.id")
if SiteSetting.min_flags_staff_visibility > 1
flagged_relation = flagged_relation
.having("count(*) >= ?", SiteSetting.min_flags_staff_visibility)
end
posts_flagged_count = flagged_relation
.pluck("posts.id")
.count
$redis.set('posts_flagged_count', posts_flagged_count)
user_ids = User.staff.pluck(:id)