mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- POST /aircraft/:id/draft_batches turns a visit's work items into one unsigned entry per logbook, signed in the app (by a user with a certificate, or a mechanic through a returned or emailed invitation link). - The squawks they resolve and inspections they complete (with their result) are held until every entry is signed, then applied, attributed to the last signer; draft_batch.completed webhook. A draft never clears a squawk alone. - Drafts are for owners (integrations act for one, drafts:write scope); unsigned drafts can be withdrawn; lookup by external_ref. - The signing and entry pages show where a draft came from and what signing will do. - The suggested recordkeeping procedures describe the API once it's in use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1000 B
Ruby
29 lines
1000 B
Ruby
# Where an integration wants to hear about changes (squawks, signed entries):
|
|
# SAM posts JSON there, signed with the shared secret (see WebhookDeliveryJob).
|
|
class WebhookEndpoint < ApplicationRecord
|
|
EVENTS = LabelSet.new("webhook_endpoint.events", %w[squawk.created squawk.updated squawk.resolved entry.signed draft_batch.completed])
|
|
|
|
belongs_to :api_token
|
|
has_many :deliveries, class_name: "WebhookDelivery", dependent: :delete_all
|
|
|
|
encrypts :secret
|
|
|
|
normalizes :url, with: ->(u) { u.to_s.strip }
|
|
validates :url, presence: true, format: { with: %r{\Ahttps?://[^\s/]+(:\d+)?(/\S*)?\z}i }
|
|
validates :secret, presence: true, length: { minimum: 16 }
|
|
validate :events_known
|
|
|
|
scope :enabled, -> { where(enabled: true) }
|
|
|
|
def self.new_secret = SecureRandom.hex(32)
|
|
|
|
def subscribed?(event) = events.include?(event.to_s)
|
|
|
|
private
|
|
|
|
def events_known
|
|
errors.add(:events, :blank) if events.blank?
|
|
errors.add(:events, :inclusion) if (Array(events) - EVENTS.keys).any?
|
|
end
|
|
end
|