summaryrefslogtreecommitdiff
path: root/app/services/web_hooks/destroy_service.rb
blob: ecb530f0d2a23b32d935936ae126dc3e73551434 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module WebHooks
  class DestroyService
    attr_accessor :current_user

    def initialize(current_user)
      @current_user = current_user
    end

    # Destroy the hook immediately, schedule the logs for deletion
    def execute(web_hook)
      hook_id = web_hook.id

      if web_hook.destroy
        WebHooks::LogDestroyWorker.perform_async({ 'hook_id' => hook_id })
        Gitlab::AppLogger.info("User #{current_user&.id} scheduled a deletion of logs for hook ID #{hook_id}")

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

    # Backwards compatibility with WebHooks::DestroyWorker
    alias_method :sync_destroy, :execute
  end
end