docbrown/app/models/webhook/endpoint.rb
rhymes 10efa25c0a
Add missing presence validators to models (#10495)
* Add missing presence validator for Tag

* Add missing presence validators to Follow

* Add missing presence validators to ProfileField

* Add missing presence validators to Comment

* Add missing presence validators to Profile

* Add missing presence validators to Organization

* Add missing presence validators to Badge

* Add missing presence validators to Webhook::Endpoint

* Add missing presence validators to NotificationSubscription

* Add missing presence validators to PodcastEpisode

* Add missing presence validators to Sponsorship

* Add missing presence validators to PollOption

* Add missing presence validators to Poll

* Add missing presence validators to Article

* Add missing presence validators to EmailAuthorization

* Add missing presence validators to AuditLog

* Add missing presence validators to DataUpdateScript

* Add missing presence validators to User

* Add missing presence validators to SiteConfig

* Fix specs
2020-10-01 16:15:32 +02:00

27 lines
940 B
Ruby

module Webhook
class Endpoint < ApplicationRecord
belongs_to :user, inverse_of: :webhook_endpoints
belongs_to :oauth_application, optional: true,
class_name: "Doorkeeper::Application",
inverse_of: :webhook_endpoints
validates :events, presence: true
validates :source, presence: true
validates :target_url, presence: true, uniqueness: true, url: { schemes: %w[https] }
validates :user_id, presence: true
attribute :events, :string, array: true, default: []
scope :for_events, ->(events) { where("events @> ARRAY[?]::varchar[]", Array(events)) }
scope :for_app, ->(app_id) { where(oauth_application_id: app_id) }
def self.table_name_prefix
"webhook_"
end
def events=(events)
events = Array(events).map { |event| event.to_s.underscore }
super(Webhook::Event::EVENT_TYPES & events)
end
end
end