debian-mirror-gitlab/app/services/users/reject_service.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
module Users
class RejectService < BaseService
def initialize(current_user)
@current_user = current_user
end
def execute(user)
2021-11-11 11:23:49 +05:30
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?
2021-02-22 17:27:13 +05:30
user.delete_async(deleted_by: current_user, params: { hard_delete: true })
2021-03-11 19:13:27 +05:30
after_reject_hook(user)
2021-02-22 17:27:13 +05:30
NotificationService.new.user_admin_rejection(user.name, user.email)
2021-03-11 19:13:27 +05:30
log_event(user)
2021-11-11 11:23:49 +05:30
success(message: 'Success', http_status: :ok)
2021-02-22 17:27:13 +05:30
end
private
attr_reader :current_user
def allowed?
can?(current_user, :reject_user)
end
2021-03-11 19:13:27 +05:30
def after_reject_hook(user)
# overridden by EE module
end
def log_event(user)
2023-03-04 22:38:38 +05:30
Gitlab::AppLogger.info(message: "User instance access request rejected", user: user.username.to_s, email: user.email.to_s, rejected_by: current_user.username.to_s, ip_address: current_user.current_sign_in_ip.to_s)
2021-03-11 19:13:27 +05:30
end
2021-02-22 17:27:13 +05:30
end
end
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
Users::RejectService.prepend_mod_with('Users::RejectService')