blob: fa3b738b4cd3c40ffcbf73373e55ccc619f20155 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# frozen_string_literal: true
module Users
class AutoBanService < BaseService
def initialize(user:, reason:)
@user = user
@reason = reason
end
def execute
if user.ban
record_custom_attribute
success
else
messages = user.errors.full_messages
error(messages.uniq.join('. '))
end
end
private
attr_reader :user, :reason
def record_custom_attribute
custom_attribute = {
user_id: user.id,
key: UserCustomAttribute::AUTO_BANNED_BY,
value: reason
}
UserCustomAttribute.upsert_custom_attributes([custom_attribute])
end
end
end
|