2020-12-03 00:09:53 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Users
|
|
|
|
class RejectService < BaseService
|
|
|
|
def initialize(current_user)
|
|
|
|
@current_user = current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(user)
|
2021-09-09 09:11:16 +00:00
|
|
|
return error(_('You are not allowed to reject a user'), :forbidden) unless allowed?
|
|
|
|
return error(_('User does not have a pending request'), :conflict) unless user.blocked_pending_approval?
|
2020-12-03 00:09:53 +00:00
|
|
|
|
|
|
|
user.delete_async(deleted_by: current_user, params: { hard_delete: true })
|
|
|
|
|
2021-01-28 06:08:59 +00:00
|
|
|
after_reject_hook(user)
|
|
|
|
|
2020-12-03 00:09:53 +00:00
|
|
|
NotificationService.new.user_admin_rejection(user.name, user.email)
|
|
|
|
|
2021-01-29 21:09:34 +00:00
|
|
|
log_event(user)
|
|
|
|
|
2021-09-09 09:11:16 +00:00
|
|
|
success(message: 'Success', http_status: :ok)
|
2020-12-03 00:09:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :current_user
|
|
|
|
|
|
|
|
def allowed?
|
|
|
|
can?(current_user, :reject_user)
|
|
|
|
end
|
2021-01-28 06:08:59 +00:00
|
|
|
|
|
|
|
def after_reject_hook(user)
|
|
|
|
# overridden by EE module
|
|
|
|
end
|
2021-01-29 21:09:34 +00:00
|
|
|
|
|
|
|
def log_event(user)
|
|
|
|
Gitlab::AppLogger.info(message: "User instance access request rejected", user: "#{user.username}", email: "#{user.email}", rejected_by: "#{current_user.username}", ip_address: "#{current_user.current_sign_in_ip}")
|
|
|
|
end
|
2020-12-03 00:09:53 +00:00
|
|
|
end
|
|
|
|
end
|
2021-01-28 06:08:59 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
Users::RejectService.prepend_mod_with('Users::RejectService')
|