mirror of
https://github.com/discourse/discourse.git
synced 2024-12-13 08:03:44 +08:00
b806dce13d
- fetch models inside services - validate `user_id` in contracts - use policy objects - extract more logic to actions - write specs for services and action
41 lines
938 B
Ruby
41 lines
938 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Action
|
|
module User
|
|
class SuspendAll
|
|
attr_reader :users, :actor, :contract
|
|
|
|
delegate :message, :post_id, :suspend_until, :reason, to: :contract, private: true
|
|
|
|
def initialize(users:, actor:, contract:)
|
|
@users, @actor, @contract = users, actor, contract
|
|
end
|
|
|
|
def self.call(...)
|
|
new(...).call
|
|
end
|
|
|
|
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
|
|
end
|
|
end
|