Skip to content

A platform for community discussion. Free, open, simple.

DEV: Put back the `model` step in HandleCategoryUpdated service

Loïc Guitautf11f2b983f18
diff --git a/plugins/chat/app/services/chat/auto_remove/handle_category_updated.rb b/plugins/chat/app/services/chat/auto_remove/handle_category_updated.rb
index 030f2da38d9..fff835bc986 100644
--- a/plugins/chat/app/services/chat/auto_remove/handle_category_updated.rb
+++ b/plugins/chat/app/services/chat/auto_remove/handle_category_updated.rb
@@ -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,
)