2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2021-02-23 14:52:16 +00:00
|
|
|
|
|
|
|
class Webhook < ApplicationModel
|
|
|
|
include ChecksClientNotification
|
2021-04-12 09:49:26 +00:00
|
|
|
include ChecksHtmlSanitized
|
2021-02-23 14:52:16 +00:00
|
|
|
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
|
|
|
|
2021-04-12 09:49:26 +00:00
|
|
|
sanitized_html :note
|
|
|
|
|
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
|