mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
REST API v1: tokens, read endpoints, squawks, webhooks
- Personal tokens (Profile → API tokens) act as their owner; integration tokens (Admin → Integrations) reach chosen aircraft and scopes, and their writes name the person they're for (SAM-On-Behalf-Of). Tokens are stored hashed, shown once, revocable, with last use recorded. - GET aircraft, components, due list, inspections, ADs, logbook entries and squawks; POST/PATCH squawks with external_ref links to the other system. - Idempotency-Key for safe retries, paging, JSON errors, rate limits. - Record history keeps the token with each change (in the hashed payload). - Webhooks (squawk created/updated/resolved, entry signed), HMAC-signed, retried, never sent to the server itself; deliveries listed for admins. - The outbound address check is shared by AirTrail and webhooks; reporting a squawk is announced the same way from the form and the API. - docs/guide/api.md: the API reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec0f43019f
commit
bffdea937c
45 files changed
+1577
-51
No files matched your search
@@ -0,0 +1,32 @@
|
||||
<%= form_with model: integration, url: (integration.persisted? ? admin_integration_path(integration) : admin_integrations_path), scope: :api_token,
|
||||
class: "card card-body max-w-2xl space-y-5", data: { turbo: false } do |f| %>
|
||||
<%= f.errors_summary %>
|
||||
<% if endpoint&.errors&.any? %><div class="rounded-md bg-red-50 p-3 text-sm text-red-700"><%= endpoint.errors.full_messages.to_sentence %></div><% end %>
|
||||
<%= f.field :name, hint: t(".name_hint") %>
|
||||
<fieldset>
|
||||
<legend class="label"><%= t(".scopes") %></legend>
|
||||
<% ApiToken::SCOPES.each do |key, label| %>
|
||||
<label class="flex items-start gap-2 text-sm"><%= check_box_tag "api_token[scopes][]", key, integration.scopes.include?(key), id: "scope_#{key.parameterize}", class: "mt-1" %> <span><%= label %></span></label>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend class="label"><%= t(".aircraft") %></legend>
|
||||
<p class="hint mb-1"><%= t(".aircraft_hint") %></p>
|
||||
<% Aircraft.ordered.each do |a| %>
|
||||
<label class="mr-4 inline-flex items-center gap-2 text-sm"><%= check_box_tag "api_token[aircraft_ids][]", a.id, Array(integration.aircraft_ids).include?(a.id), id: "aircraft_#{a.id}" %> <%= a.tail_number %></label>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
<fieldset class="space-y-2 border-t border-slate-200 pt-4">
|
||||
<legend class="label"><%= t(".webhook") %></legend>
|
||||
<p class="hint"><%= t(".webhook_hint") %></p>
|
||||
<%= url_field_tag "webhook[url]", endpoint&.url, class: "input", placeholder: "https://redmine.example.com/sam/webhook", "aria-label": t(".webhook_url") %>
|
||||
<% WebhookEndpoint::EVENTS.each do |key, label| %>
|
||||
<label class="flex items-start gap-2 text-sm"><%= check_box_tag "webhook[events][]", key, Array(endpoint&.events).include?(key), id: "event_#{key.parameterize}", class: "mt-1" %> <span><%= label %> <code class="text-xs text-slate-500"><%= key %></code></span></label>
|
||||
<% end %>
|
||||
<% if endpoint&.persisted? %>
|
||||
<%= hidden_field_tag "webhook[enabled]", "0", id: nil %>
|
||||
<label class="flex items-center gap-2 text-sm"><%= check_box_tag "webhook[enabled]", "1", endpoint.enabled %> <%= t(".webhook_enabled") %></label>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
<%= f.submit integration.persisted? ? t(".save") : t(".create"), class: "btn-primary" %>
|
||||
<% end %>
|
||||
@@ -0,0 +1,15 @@
|
||||
<% content_for :title, @integration.name %>
|
||||
<section class="card card-body max-w-xl space-y-3">
|
||||
<h1 class="card-title"><%= @integration.name %></h1>
|
||||
<p class="text-sm text-slate-600"><%= t(".copy_now") %></p>
|
||||
<% if @integration.token %>
|
||||
<label class="label" for="integration_token"><%= t(".token") %></label>
|
||||
<input id="integration_token" class="input font-mono text-sm" value="<%= @integration.token %>" readonly>
|
||||
<% end %>
|
||||
<% if @secret %>
|
||||
<label class="label" for="webhook_secret"><%= t(".webhook_secret") %></label>
|
||||
<input id="webhook_secret" class="input font-mono text-sm" value="<%= @secret %>" readonly>
|
||||
<p class="hint"><%= t(".secret_hint") %></p>
|
||||
<% end %>
|
||||
<p><%= link_to t(".done"), admin_integration_path(@integration), class: "btn-primary" %></p>
|
||||
</section>
|
||||
@@ -0,0 +1,3 @@
|
||||
<% content_for :title, @integration.name %>
|
||||
<h1 class="mb-4 text-2xl font-bold"><%= @integration.name %></h1>
|
||||
<%= render "form", integration: @integration, endpoint: @endpoint %>
|
||||
@@ -0,0 +1,17 @@
|
||||
<% content_for :title, t(".integrations") %>
|
||||
<div class="mb-4 flex items-center justify-between"><h1 class="text-2xl font-bold"><%= t(".integrations") %></h1><%= link_to t(".new_integration"), new_admin_integration_path, class: "btn-primary" %></div>
|
||||
<p class="mb-4 max-w-3xl text-sm text-slate-600"><%= t(".what_html", docs: link_to(t(".api_docs"), help_page_path("api"), class: "link")) %></p>
|
||||
<% if @integrations.any? %>
|
||||
<section class="card"><table class="table">
|
||||
<thead><tr><th><%= t(".name") %></th><th><%= t(".aircraft") %></th><th><%= t(".webhook") %></th><th><%= t(".last_used") %></th></tr></thead>
|
||||
<tbody><% @integrations.each do |i| %><tr>
|
||||
<td><%= link_to i.name, admin_integration_path(i), class: "link font-medium" %> <% if i.revoked? %><span class="badge-red"><%= t(".revoked") %></span><% end %>
|
||||
<div class="text-xs text-slate-500"><code><%= i.token_hint %>…</code></div></td>
|
||||
<td class="text-xs"><%= Aircraft.where(id: Array(i.aircraft_ids)).order(:tail_number).pluck(:tail_number).join(", ").presence || "—" %></td>
|
||||
<td class="text-xs"><%= (e = i.webhook_endpoints.first) ? e.url : "—" %></td>
|
||||
<td class="text-xs text-slate-500"><%= i.last_used_at ? t(".ago", ago: time_ago_in_words(i.last_used_at)) : t(".never") %></td>
|
||||
</tr><% end %></tbody>
|
||||
</table></section>
|
||||
<% else %>
|
||||
<%= empty_state t(".none_yet") %>
|
||||
<% end %>
|
||||
@@ -0,0 +1,3 @@
|
||||
<% content_for :title, t(".new_integration") %>
|
||||
<h1 class="mb-4 text-2xl font-bold"><%= t(".new_integration") %></h1>
|
||||
<%= render "form", integration: @integration, endpoint: @endpoint %>
|
||||
@@ -0,0 +1,49 @@
|
||||
<% content_for :title, @integration.name %>
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<h1 class="text-2xl font-bold"><%= @integration.name %> <% if @integration.revoked? %><span class="badge-red align-middle text-sm"><%= t(".revoked") %></span><% end %></h1>
|
||||
<% unless @integration.revoked? %>
|
||||
<div class="flex gap-2">
|
||||
<%= link_to t(".edit"), edit_admin_integration_path(@integration), class: "btn-secondary" %>
|
||||
<%= button_to t(".revoke"), admin_integration_path(@integration), method: :delete, class: "btn-danger",
|
||||
form: { data: { turbo_confirm: t(".revoke_confirm", name: @integration.name) } } %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="grid max-w-5xl items-start gap-5 lg:grid-cols-2">
|
||||
<section class="card card-body">
|
||||
<h2 class="card-title"><%= t(".token") %></h2>
|
||||
<dl class="mt-2 grid gap-y-2 text-sm">
|
||||
<div class="detail-row"><dt><%= t(".hint") %></dt><dd><code><%= @integration.token_hint %>…</code></dd></div>
|
||||
<div class="detail-row"><dt><%= t(".scopes") %></dt><dd><%= @integration.scopes.map { ApiToken::SCOPES[_1] }.to_sentence %></dd></div>
|
||||
<div class="detail-row"><dt><%= t(".aircraft") %></dt><dd><%= Aircraft.where(id: Array(@integration.aircraft_ids)).order(:tail_number).pluck(:tail_number).join(", ").presence || "—" %></dd></div>
|
||||
<div class="detail-row"><dt><%= t(".created") %></dt><dd><%= fmt_time(@integration.created_at) %> · <%= @integration.user.display_name %></dd></div>
|
||||
<div class="detail-row"><dt><%= t(".last_used") %></dt><dd><%= @integration.last_used_at ? "#{fmt_time(@integration.last_used_at)} · #{@integration.last_used_ip}" : t(".never") %></dd></div>
|
||||
</dl>
|
||||
</section>
|
||||
<section class="card card-body">
|
||||
<h2 class="card-title"><%= t(".webhook") %></h2>
|
||||
<% if @endpoint %>
|
||||
<dl class="mt-2 grid gap-y-2 text-sm">
|
||||
<div class="detail-row"><dt><%= t(".url") %></dt><dd class="break-all"><%= @endpoint.url %> <% unless @endpoint.enabled %><span class="badge-gray"><%= t(".paused") %></span><% end %></dd></div>
|
||||
<div class="detail-row"><dt><%= t(".events") %></dt><dd><%= @endpoint.events.map { WebhookEndpoint::EVENTS[_1] }.to_sentence %></dd></div>
|
||||
</dl>
|
||||
<% unless @integration.revoked? %>
|
||||
<div class="mt-3"><%= button_to t(".new_secret"), new_secret_admin_integration_path(@integration), class: "btn-secondary btn-sm",
|
||||
form: { data: { turbo: false, turbo_confirm: t(".new_secret_confirm") } } %></div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p class="mt-1 text-sm text-slate-600"><%= t(".no_webhook") %></p>
|
||||
<% end %>
|
||||
</section>
|
||||
</div>
|
||||
<% if @deliveries.any? %>
|
||||
<section class="card mt-5 max-w-5xl">
|
||||
<div class="card-header"><h2 class="card-title"><%= t(".recent_deliveries") %></h2></div>
|
||||
<table class="table"><thead><tr><th><%= t(".when") %></th><th><%= t(".event") %></th><th><%= t(".result") %></th></tr></thead>
|
||||
<tbody><% @deliveries.each do |d| %><tr>
|
||||
<td class="text-xs"><%= fmt_time(d.created_at) %></td><td><code class="text-xs"><%= d.event %></code></td>
|
||||
<td class="text-xs"><span class="<%= { "delivered" => "badge-green", "failed" => "badge-red" }.fetch(d.status, "badge-gray") %>"><%= t(".status.#{d.status}") %></span>
|
||||
<%= d.response_status %> <%= d.last_error %> <% if d.attempts > 1 %>· <%= t(".attempts", count: d.attempts) %><% end %></td>
|
||||
</tr><% end %></tbody></table>
|
||||
</section>
|
||||
<% end %>
|
||||
Reference in new issue
Block a user