mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- 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>
20 lines
797 B
Ruby
20 lines
797 B
Ruby
# Profile → API tokens: personal tokens for the REST API (docs/api.md). The
|
|
# token is shown once, on the page right after it's made (not kept in the
|
|
# flash or anywhere else).
|
|
class ApiTokensController < ApplicationController
|
|
def create
|
|
@token = current_user.api_tokens.new(name: params.dig(:api_token, :name), kind: "personal",
|
|
scopes: Array(params.dig(:api_token, :scopes)) & ApiToken::SCOPES.keys)
|
|
if @token.save
|
|
render :created
|
|
else
|
|
redirect_to edit_profile_path(anchor: "api"), alert: @token.errors.full_messages.to_sentence
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
current_user.api_tokens.personal.active.find(params[:id]).revoke!
|
|
redirect_to edit_profile_path(anchor: "api"), notice: t("flash.api_tokens.revoked")
|
|
end
|
|
end
|