2021-02-23 14:52:16 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class Webhook < ApplicationModel
|
|
|
|
include ChecksClientNotification
|
|
|
|
include ChecksLatestChangeObserved
|
|
|
|
include HasCollectionUpdate
|
|
|
|
|
2021-03-16 07:25:55 +00:00
|
|
|
before_destroy Webhook::EnsureNoRelatedObjects
|
2021-02-23 14:52:16 +00:00
|
|
|
|
|
|
|
validates :name, presence: true
|
2021-03-16 07:50:12 +00:00
|
|
|
validate :validate_endpoint
|
2021-02-23 14:52:16 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_endpoint
|
|
|
|
uri = URI.parse(endpoint)
|
2021-03-16 07:50:12 +00:00
|
|
|
|
|
|
|
errors.add(:endpoint, 'Invalid endpoint (no http/https)!') if !uri.is_a?(URI::HTTP)
|
|
|
|
errors.add(:endpoint, 'Invalid endpoint (no hostname)!') if uri.host.nil?
|
2021-02-23 14:52:16 +00:00
|
|
|
rescue URI::InvalidURIError
|
2021-03-16 07:50:12 +00:00
|
|
|
errors.add :endpoint, 'Invalid endpoint!'
|
2021-02-23 14:52:16 +00:00
|
|
|
end
|
|
|
|
end
|