Skip to content
代码片段 群组 项目
提交 4c34be70 编辑于 作者: imand3r's avatar imand3r
浏览文件

Refactor Users::AutoBanService to use Users::BanService

上级 cbfc6bed
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
module Users
class AutoBanService < BaseService
class AutoBanService
Error = Class.new(StandardError)
def initialize(user:, reason:)
@user = user
@reason = reason
end
def execute
if user.ban
record_custom_attribute
ban_duplicate_users
success
else
messages = user.errors.full_messages
error(messages.uniq.join('. '))
end
ban_user
end
def execute!
user.ban!
record_custom_attribute
ban_duplicate_users
success
result = ban_user
raise Error, result[:message] if result[:status] == :error
end
private
attr_reader :user, :reason
def ban_user
result = ::Users::BanService.new(admin_bot).execute(user)
record_custom_attribute if result[:status] == :success
result
end
def admin_bot
Users::Internal.admin_bot
end
def ban_duplicate_users
AntiAbuse::BanDuplicateUsersWorker.perform_async(user.id)
end
......
......@@ -68,7 +68,7 @@ def mock_rate_limit(limit_name, method, result, scope: nil)
do_request
expect(Gitlab::AppLogger).to have_received(:info).with(a_hash_including(logger_args))
expect(Gitlab::AppLogger).to have_received(:info).with(hash_including(logger_args))
tracking_args = {
category: message,
......
......@@ -51,7 +51,7 @@
response = execute
expect(response[:status]).to eq(:error)
expect(response[:message]).to match('State cannot transition via "ban"')
expect(response[:message]).to match('You cannot ban blocked users.')
end
it 'does not modify the BannedUser record or user state' do
......@@ -76,7 +76,7 @@
end
it 'raises an error and does not ban the user', :aggregate_failures do
expect { execute! }.to raise_error(StateMachines::InvalidTransition)
expect { execute! }.to raise_error(described_class::Error)
.and not_change { Users::BannedUser.count }
.and not_change { user.state }
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册