webhook.rb 761 B

12345678910111213141516171819202122232425
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class Webhook < ApplicationModel
  3. include ChecksClientNotification
  4. include ChecksHtmlSanitized
  5. include HasCollectionUpdate
  6. before_destroy Webhook::EnsureNoRelatedObjects
  7. validates :name, presence: true
  8. validate :validate_endpoint
  9. sanitized_html :note
  10. private
  11. def validate_endpoint
  12. uri = URI.parse(endpoint)
  13. errors.add(:endpoint, __('The provided endpoint is invalid, no http or https protocol was specified.')) if !uri.is_a?(URI::HTTP)
  14. errors.add(:endpoint, __('The provided endpoint is invalid, no hostname was specified.')) if uri.host.nil?
  15. rescue URI::InvalidURIError
  16. errors.add :endpoint, __('The provided endpoint is invalid.')
  17. end
  18. end