0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/app/services/user_suspender.rb
Sam cf59f5e026
FEATURE: Anonymous shadow sessions can outlive suspension of the master account (#40156)
When suspending a main account also suspend anonymous shadow account.

This avoids double work for moderators.

Co-authored-by: discourse-patch-triage
<272280883+discourse-patch-triage[bot]@users.noreply.github.com>

---------

Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>
2026-05-20 12:07:56 +08:00

65 lines
1.3 KiB
Ruby
Vendored

# frozen_string_literal: true
class UserSuspender
attr_reader :user_history
def initialize(
user,
suspended_till:,
reason:,
by_user:,
message: nil,
post_id: nil,
reviewable_id: nil
)
@user = user
@suspended_till = suspended_till
@reason = reason
@by_user = by_user
@message = message
@post_id = post_id
@reviewable_id = reviewable_id
end
def suspend
suspended_at = DateTime.now
@user.suspended_till = @suspended_till
@user.suspended_at = suspended_at
@user.transaction do
@user.save!
@user_history =
StaffActionLogger.new(@by_user).log_user_suspend(
@user,
@reason,
message: @message,
post_id: @post_id,
reviewable_id: @reviewable_id,
)
end
@user.log_out!
if @message.present?
Jobs.enqueue(
Jobs::CriticalUserEmail,
type: "account_suspended",
user_id: @user.id,
user_history_id: @user_history.id,
)
end
DiscourseEvent.trigger(
:user_suspended,
user: @user,
reason: @reason,
message: @message,
user_history: @user_history,
post_id: @post_id,
suspended_till: @suspended_till,
suspended_at: suspended_at,
)
nil
end
end