discourse/app/services/user/action/suspend_all.rb
Loïc Guitaut 05b8ff436c DEV: Introduce a Service::ActionBase class for service actions
This will help to enforce a consistent pattern for creating service
actions.

This patch also namespaces actions and policies, making everything
related to a service available directly in
`app/services/<concept-name>`, making things more consistent at that
level too.
2024-09-18 17:02:46 +02:00

31 lines
687 B
Ruby

# frozen_string_literal: true
class User::Action::SuspendAll < Service::ActionBase
option :users, []
option :actor
option :contract
delegate :message, :post_id, :suspend_until, :reason, to: :contract, private: true
def call
suspended_users.first.try(:user_history).try(:details)
end
private
def suspended_users
users.map do |user|
UserSuspender.new(
user,
suspended_till: suspend_until,
reason: reason,
by_user: actor,
message: message,
post_id: post_id,
).tap(&:suspend)
rescue => err
Discourse.warn_exception(err, message: "failed to suspend user with ID #{user.id}")
end
end
end