Class: UserSuspender
- Inherits:
-
Object
- Object
- UserSuspender
- Defined in:
- app/services/user_suspender.rb
Instance Attribute Summary collapse
-
#user_history ⇒ Object
readonly
Returns the value of attribute user_history.
Instance Method Summary collapse
-
#initialize(user, suspended_till:, reason:, by_user:, message: nil, post_id: nil) ⇒ UserSuspender
constructor
A new instance of UserSuspender.
- #suspend ⇒ Object
Constructor Details
#initialize(user, suspended_till:, reason:, by_user:, message: nil, post_id: nil) ⇒ UserSuspender
Returns a new instance of UserSuspender.
6 7 8 9 10 11 12 13 |
# File 'app/services/user_suspender.rb', line 6 def initialize(user, suspended_till:, reason:, by_user:, message: nil, post_id: nil) @user = user @suspended_till = suspended_till @reason = reason @by_user = by_user @message = @post_id = post_id end |
Instance Attribute Details
#user_history ⇒ Object (readonly)
Returns the value of attribute user_history.
4 5 6 |
# File 'app/services/user_suspender.rb', line 4 def user_history @user_history end |
Instance Method Details
#suspend ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/services/user_suspender.rb', line 15 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, ) end @user.logged_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 |