mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
DEV: Put back the model
step in HandleCategoryUpdated service
Now that `ActiveRecord` relations are properly handled in a `model` step, putting this step back will allow the service to stops its execution if there are no users to be removed without calling the pretty big SQL query contained in the `CalculateMembershipsForRemoval` action.
This commit is contained in:
parent
9d367cc9a1
commit
f11f2b983f
|
@ -19,6 +19,7 @@ module Chat
|
|||
policy :chat_enabled
|
||||
model :category
|
||||
model :category_channel_ids
|
||||
model :users
|
||||
step :remove_users_without_channel_permission
|
||||
step :publish
|
||||
|
||||
|
@ -46,18 +47,21 @@ module Chat
|
|||
Chat::Channel.where(chatable: category).pluck(:id)
|
||||
end
|
||||
|
||||
def remove_users_without_channel_permission(category_channel_ids:)
|
||||
def fetch_users(category_channel_ids:)
|
||||
User
|
||||
.real
|
||||
.activated
|
||||
.not_suspended
|
||||
.not_staged
|
||||
.joins(:user_chat_channel_memberships)
|
||||
.where("user_chat_channel_memberships.chat_channel_id IN (?)", category_channel_ids)
|
||||
.where("NOT admin AND NOT moderator")
|
||||
end
|
||||
|
||||
def remove_users_without_channel_permission(users:, category_channel_ids:)
|
||||
memberships_to_remove =
|
||||
Chat::Action::CalculateMembershipsForRemoval.call(
|
||||
scoped_users_query:
|
||||
User
|
||||
.real
|
||||
.activated
|
||||
.not_suspended
|
||||
.not_staged
|
||||
.joins(:user_chat_channel_memberships)
|
||||
.where("user_chat_channel_memberships.chat_channel_id IN (?)", category_channel_ids)
|
||||
.where("NOT admin AND NOT moderator"),
|
||||
scoped_users_query: users,
|
||||
channel_ids: category_channel_ids,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user