webhook.rb 645 B

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