Class: WebHooks::DestroyService

Inherits:
Object
  • Object
show all
Includes:
Services::ReturnServiceResponses
Defined in:
app/services/web_hooks/destroy_service.rb

Overview

Destroy a hook, and schedule the logs for deletion.

Direct Known Subclasses

AdminDestroyService

Constant Summary collapse

DENIED =
'Insufficient permissions'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Services::ReturnServiceResponses

#error, #success

Constructor Details

#initialize(current_user) ⇒ DestroyService

Returns a new instance of DestroyService.



12
13
14
# File 'app/services/web_hooks/destroy_service.rb', line 12

def initialize(current_user)
  @current_user = current_user
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



8
9
10
# File 'app/services/web_hooks/destroy_service.rb', line 8

def current_user
  @current_user
end

Instance Method Details

#execute(web_hook) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/web_hooks/destroy_service.rb', line 16

def execute(web_hook)
  return error(DENIED, 401) unless authorized?(web_hook)

  hook_id = web_hook.id

  if web_hook.destroy
    WebHooks::LogDestroyWorker.perform_async({ 'hook_id' => hook_id })
    Gitlab::AppLogger.info(log_message(web_hook))

    success({ async: false })
  else
    error("Unable to destroy #{web_hook.model_name.human}", 500)
  end
end