mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
#38125 attempted to do the entire performance update to group add users in one go, this is Pt 1 for splitting it into multiple, easier to digest PRs. The main goal for this PR is to change any additions to group members through one place. GroupUser callbacks intentionally left in place for this PR to not break the paths that create GroupUser directly. ### Details - Add new `GroupManager` class that will be the single source of truth for adding members to a group. - Modify the `bulk_add` and `bulk_remove` methods to handle all side-effects from the original callbacks. - Add other bulk methods in needed places (group_user, category_user, tag_user, group_action_logger) - Add tests for all the new paths - Fix tests that relied on group being saved before a member could be added (were using `Fabricate.build` and manually saving later) --------- Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>
24 lines
673 B
Ruby
Vendored
24 lines
673 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class BulkGrantTrustLevel < ::Jobs::Base
|
|
def execute(args)
|
|
user_ids = args[:user_ids]
|
|
trust_level = args[:trust_level]
|
|
recalculate = args[:recalculate]
|
|
|
|
raise Discourse::InvalidParameters.new(:user_ids) if user_ids.blank?
|
|
raise Discourse::InvalidParameters.new(:trust_level) if trust_level.blank? && !recalculate
|
|
|
|
User
|
|
.where(id: user_ids)
|
|
.find_each do |user|
|
|
if recalculate
|
|
Promotion.recalculate(user, use_previous_trust_level: true)
|
|
else
|
|
TrustLevelGranter.grant(trust_level, user)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|