mirror of
https://github.com/discourse/discourse.git
synced 2024-12-17 19:53:43 +08:00
05b8ff436c
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.
42 lines
957 B
Ruby
42 lines
957 B
Ruby
# frozen_string_literal: true
|
|
|
|
class User::Action::SilenceAll < Service::ActionBase
|
|
option :users, []
|
|
option :actor
|
|
option :contract
|
|
|
|
delegate :message, :post_id, :silenced_till, :reason, to: :contract, private: true
|
|
|
|
def call
|
|
silenced_users.first.try(:user_history).try(:details)
|
|
end
|
|
|
|
private
|
|
|
|
def silenced_users
|
|
users.map do |user|
|
|
UserSilencer
|
|
.new(
|
|
user,
|
|
actor,
|
|
message_body: message,
|
|
keep_posts: true,
|
|
silenced_till:,
|
|
reason:,
|
|
post_id:,
|
|
)
|
|
.tap do |silencer|
|
|
next unless silencer.silence
|
|
Jobs.enqueue(
|
|
:critical_user_email,
|
|
type: "account_silenced",
|
|
user_id: user.id,
|
|
user_history_id: silencer.user_history.id,
|
|
)
|
|
end
|
|
rescue => err
|
|
Discourse.warn_exception(err, message: "failed to silence user with ID #{user.id}")
|
|
end
|
|
end
|
|
end
|