2020-10-07 05:09:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module WebHooks
|
|
|
|
class DestroyService
|
2022-06-01 23:08:40 -04:00
|
|
|
attr_accessor :current_user
|
2020-10-07 05:09:13 -04:00
|
|
|
|
|
|
|
def initialize(current_user)
|
|
|
|
@current_user = current_user
|
|
|
|
end
|
|
|
|
|
2022-06-01 23:08:40 -04:00
|
|
|
# Destroy the hook immediately, schedule the logs for deletion
|
2020-10-07 05:09:13 -04:00
|
|
|
def execute(web_hook)
|
2022-06-01 23:08:40 -04:00
|
|
|
hook_id = web_hook.id
|
2020-10-07 05:09:13 -04:00
|
|
|
|
2022-06-01 23:08:40 -04:00
|
|
|
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}")
|
2020-10-07 05:09:13 -04:00
|
|
|
|
2022-06-01 23:08:40 -04:00
|
|
|
ServiceResponse.success(payload: { async: false })
|
2020-10-07 05:09:13 -04:00
|
|
|
else
|
2022-06-01 23:08:40 -04:00
|
|
|
ServiceResponse.error(message: "Unable to destroy #{web_hook.model_name.human}")
|
2020-10-07 05:09:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|