mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Support designating multiple groups as mods on category (#28655)
Currently, categories support designating only 1 group as a moderation group on the category. This commit removes the one group limitation and makes it possible to designate multiple groups as mods on a category. Internal topic: t/124648.
This commit is contained in:
@@ -20,23 +20,18 @@ class Jobs::NotifyReviewable < ::Jobs::Base
|
||||
|
||||
all_updates[:admins][r.id] = payload
|
||||
all_updates[:moderators][r.id] = payload if r.reviewable_by_moderator?
|
||||
all_updates[r.reviewable_by_group_id][r.id] = payload if r.reviewable_by_group_id
|
||||
|
||||
if SiteSetting.enable_category_group_moderation? && r.category.present?
|
||||
r
|
||||
.category
|
||||
.moderating_groups
|
||||
.pluck(:id)
|
||||
.each { |group_id| all_updates[group_id][r.id] = payload }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
DistributedMutex.synchronize("notify_reviewable_job", validity: 120) do
|
||||
counts = Hash.new(0)
|
||||
Reviewable
|
||||
.default_visible
|
||||
.pending
|
||||
.group(:reviewable_by_moderator, :reviewable_by_group_id)
|
||||
.pluck(:reviewable_by_moderator, :reviewable_by_group_id, "count(*)")
|
||||
.each do |reviewable_by_moderator, reviewable_by_group_id, count|
|
||||
counts[:admins] += count
|
||||
counts[:moderators] += count if reviewable_by_moderator
|
||||
counts[reviewable_by_group_id] += count if reviewable_by_group_id
|
||||
end
|
||||
|
||||
notify_users(User.real.admins, all_updates[:admins])
|
||||
|
||||
if reviewable.reviewable_by_moderator?
|
||||
@@ -46,16 +41,21 @@ class Jobs::NotifyReviewable < ::Jobs::Base
|
||||
)
|
||||
end
|
||||
|
||||
if SiteSetting.enable_category_group_moderation? && (group = reviewable.reviewable_by_group)
|
||||
users = group.users.includes(:group_users).where("users.id NOT IN (?)", @contacted)
|
||||
if SiteSetting.enable_category_group_moderation? && reviewable.category.present?
|
||||
users =
|
||||
User
|
||||
.includes(:group_users)
|
||||
.joins(:group_users)
|
||||
.joins(
|
||||
"INNER JOIN category_moderation_groups ON category_moderation_groups.group_id = group_users.group_id",
|
||||
)
|
||||
.where("category_moderation_groups.category_id": reviewable.category.id)
|
||||
.where("users.id NOT IN (?)", @contacted)
|
||||
.distinct
|
||||
|
||||
users.find_each do |user|
|
||||
count = 0
|
||||
updates = {}
|
||||
user.group_users.each do |gu|
|
||||
updates.merge!(all_updates[gu.group_id])
|
||||
count += counts[gu.group_id]
|
||||
end
|
||||
user.group_users.each { |gu| updates.merge!(all_updates[gu.group_id]) }
|
||||
|
||||
notify_user(user, updates)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user