2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-27 06:08:57 -04:00
|
|
|
module HooksExecution
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-10-07 05:09:13 -04:00
|
|
|
def destroy_hook(hook)
|
|
|
|
result = WebHooks::DestroyService.new(current_user).execute(hook)
|
|
|
|
|
|
|
|
if result[:status] == :success
|
|
|
|
flash[:notice] =
|
|
|
|
if result[:async]
|
|
|
|
_("%{hook_type} was scheduled for deletion") % { hook_type: hook.model_name.human }
|
|
|
|
else
|
|
|
|
_("%{hook_type} was deleted") % { hook_type: hook.model_name.human }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
flash[:alert] = result[:message]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-20 11:12:06 -04:00
|
|
|
def set_hook_execution_notice(result)
|
|
|
|
http_status = result[:http_status]
|
|
|
|
message = result[:message]
|
|
|
|
|
|
|
|
if http_status && http_status >= 200 && http_status < 400
|
|
|
|
flash[:notice] = "Hook executed successfully: HTTP #{http_status}"
|
|
|
|
elsif http_status
|
|
|
|
flash[:alert] = "Hook executed successfully but returned HTTP #{http_status} #{message}"
|
2017-04-27 06:08:57 -04:00
|
|
|
else
|
|
|
|
flash[:alert] = "Hook execution failed: #{message}"
|
|
|
|
end
|
|
|
|
end
|
2020-08-28 11:10:21 -04:00
|
|
|
|
|
|
|
def create_rate_limit(key, scope)
|
|
|
|
if rate_limiter.throttled?(key, scope: [scope, current_user])
|
|
|
|
rate_limiter.log_request(request, "#{key}_request_limit".to_sym, current_user)
|
|
|
|
|
|
|
|
render plain: _('This endpoint has been requested too many times. Try again later.'), status: :too_many_requests
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rate_limiter
|
|
|
|
::Gitlab::ApplicationRateLimiter
|
|
|
|
end
|
2017-04-27 06:08:57 -04:00
|
|
|
end
|