webhook.rb 712 B

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