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

@ -21,12 +21,16 @@ module FlagQuery
total_rows = actions.count
post_ids = actions.limit(per_page)
post_ids_relation = actions.limit(per_page)
.offset(offset)
.group(:post_id)
.order('MIN(post_actions.created_at) DESC')
.pluck(:post_id)
.uniq
if opts[:filter] != "old" && SiteSetting.min_flags_staff_visibility > 1
post_ids_relation = post_ids_relation.having("count(*) >= ?", SiteSetting.min_flags_staff_visibility)
end
post_ids = post_ids_relation.pluck(:post_id).uniq
posts = SqlBuilder.new("
SELECT p.id,
@ -182,18 +186,25 @@ module FlagQuery
ft_by_id = {}
users_by_id = {}
topics_by_id = {}
counts_by_post = {}
results.each do |pa|
if pa.post.present? && pa.post.topic.present?
ft = ft_by_id[pa.post.topic.id] ||= OpenStruct.new(
topic_id = pa.post.topic.id
ft = ft_by_id[topic_id] ||= OpenStruct.new(
topic: pa.post.topic,
flag_counts: {},
user_ids: [],
last_flag_at: pa.created_at
last_flag_at: pa.created_at,
meets_minimum: false
)
topics_by_id[pa.post.topic.id] = pa.post.topic
counts_by_post[pa.post.id] ||= 0
sum = counts_by_post[pa.post.id] += 1
ft.meets_minimum = true if sum >= SiteSetting.min_flags_staff_visibility
topics_by_id[topic_id] = pa.post.topic
ft.flag_counts[pa.post_action_type_id] ||= 0
ft.flag_counts[pa.post_action_type_id] += 1
@ -204,9 +215,11 @@ module FlagQuery
end
end
flagged_topics = ft_by_id.values.select { |ft| ft.meets_minimum }
Topic.preload_custom_fields(topics_by_id.values, TopicList.preloaded_custom_fields)
{ flagged_topics: ft_by_id.values, users: users_by_id.values }
{ flagged_topics: flagged_topics, users: users_by_id.values }
end
private