Class: Users::RejectService

Inherits:
BaseService show all
Defined in:
app/services/users/reject_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#params, #project

Instance Method Summary collapse

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(current_user) ⇒ RejectService

Returns a new instance of RejectService.



5
6
7
# File 'app/services/users/reject_service.rb', line 5

def initialize(current_user)
  @current_user = current_user
end

Instance Method Details

#execute(user) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/users/reject_service.rb', line 9

def execute(user)
  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?

  user.delete_async(deleted_by: current_user, params: { hard_delete: true })

  after_reject_hook(user)

  NotificationService.new.user_admin_rejection(user.name, user.email)

  log_event(user)

  success(message: 'Success', http_status: :ok)
end