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:
Loïc Guitaut 2024-08-22 11:58:55 +02:00 committed by Loïc Guitaut
parent 9d367cc9a1
commit f11f2b983f

View File

@ -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,
)