webhook.rb 807 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2023 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. validates :note, length: { maximum: 500 }
  10. sanitized_html :note
  11. private
  12. def validate_endpoint
  13. uri = URI.parse(endpoint)
  14. errors.add(:endpoint, __('The provided endpoint is invalid, no http or https protocol was specified.')) if !uri.is_a?(URI::HTTP)
  15. errors.add(:endpoint, __('The provided endpoint is invalid, no hostname was specified.')) if uri.host.blank?
  16. rescue URI::InvalidURIError
  17. errors.add :endpoint, __('The provided endpoint is invalid.')
  18. end
  19. end