mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Configurable roles: Owner, Mechanic, Pilot, Viewer and custom roles
What people can do on an aircraft now comes from their role there, and administrators set what each role allows (Admin → Roles). - Roles are installation-wide sets of permissions (31, grouped as flying, squawks and notes, maintenance records, imports and exports, the aircraft, notifications). Seeing an aircraft's records needs none. - Built in: Owner (always every permission, so an aircraft can always be managed), Mechanic (shop maintenance: logbook, signing, components, inspections, ADs, squawks, reminders), Pilot (what pilots could do before) and Viewer (view only). Administrators can change all but Owner's, and add their own; a role can be deleted once nobody has it. - Existing owners and pilots keep exactly what they could do. - Admin → Users → a user lists their role on every aircraft, to change, remove or add. On the aircraft's Access page, anyone who manages people hands out roles, but only an Owner can give or take away Owner, nobody changes their own (except administrators), and an aircraft always keeps an Owner (AircraftAccess). - Controllers declare the permission each action needs; a request that changes something with none declared is refused (and raises in development and tests), and a test walks every route to check. - Weekly reminders and overdue alerts go to roles that get reminders; the DRS reminder also needs Manage ADs. The API follows the person's role; its owners_only error is now not_permitted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d2cd60c6a7
commit
d8cd462194
101 files changed
+1032
-232
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
# search terms used.
|
# search terms used.
|
||||||
class AdAlertsController < ApplicationController
|
class AdAlertsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :manage_ads
|
||||||
before_action :set_alert, only: %i[track dismiss]
|
before_action :set_alert, only: %i[track dismiss]
|
||||||
rate_limit to: 5, within: 1.minute, only: :check, with: -> { redirect_to aircraft_airworthiness_directives_path(@aircraft), alert: t("flash.ad_alerts.try_again_in_a") }
|
rate_limit to: 5, within: 1.minute, only: :check, with: -> { redirect_to aircraft_airworthiness_directives_path(@aircraft), alert: t("flash.ad_alerts.try_again_in_a") }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class AdCompliancesController < ApplicationController
|
class AdCompliancesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :manage_ads
|
||||||
before_action :set_compliance, only: %i[edit update destroy]
|
before_action :set_compliance, only: %i[edit update destroy]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
class AdImportsController < ApplicationController
|
class AdImportsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
include StoredUpload
|
include StoredUpload
|
||||||
before_action :require_owner!
|
requires_permission :manage_ads
|
||||||
|
|
||||||
def new; end
|
def new; end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# The roles people can have on an aircraft and what each allows (Role,
|
||||||
|
# Permission). Owner always has every permission; the other built-in roles
|
||||||
|
# can be changed but not deleted; administrators can add their own.
|
||||||
|
class Admin::RolesController < ApplicationController
|
||||||
|
before_action :require_admin!
|
||||||
|
before_action :set_role, only: %i[edit update destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
Role.ensure_built_in!
|
||||||
|
@roles = Role.ordered
|
||||||
|
@counts = AircraftRole.group(:role_id).count
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@role = Role.new(permissions: Permission::DEFAULTS["viewer"])
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@role = Role.new(role_params)
|
||||||
|
if @role.save
|
||||||
|
redirect_to admin_roles_path, notice: t("flash.admin_roles.created", name: @role.name)
|
||||||
|
else
|
||||||
|
render :new, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit; end
|
||||||
|
|
||||||
|
def update
|
||||||
|
attributes = @role.owner? ? role_params.except(:permissions) : role_params
|
||||||
|
if @role.update(attributes)
|
||||||
|
redirect_to admin_roles_path, notice: t("flash.admin_roles.updated", name: @role.name)
|
||||||
|
else
|
||||||
|
render :edit, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @role.built_in?
|
||||||
|
redirect_to admin_roles_path, alert: t("flash.admin_roles.built_in")
|
||||||
|
elsif @role.aircraft_roles.exists?
|
||||||
|
redirect_to admin_roles_path, alert: t("flash.admin_roles.in_use", name: @role.name, count: @role.aircraft_roles.count)
|
||||||
|
else
|
||||||
|
@role.destroy!
|
||||||
|
redirect_to admin_roles_path, notice: t("flash.admin_roles.deleted", name: @role.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_role = @role = Role.find(params[:id])
|
||||||
|
|
||||||
|
# Unticking every box sends none, so an empty list is always sent too.
|
||||||
|
def role_params
|
||||||
|
params.require(:role).permit(:name, :description, permissions: []).tap { _1[:permissions] = Array(_1[:permissions]).compact_blank }
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# Administrators give people roles on any aircraft (from Admin → Users),
|
||||||
|
# under the same rules as the aircraft's Access page (AircraftAccess).
|
||||||
|
class Admin::UserAircraftRolesController < ApplicationController
|
||||||
|
before_action :require_admin!
|
||||||
|
before_action :set_user
|
||||||
|
|
||||||
|
def create
|
||||||
|
aircraft = Aircraft.find_by(id: params[:aircraft_id])
|
||||||
|
return back(alert: t("services.aircraft_access.not_found")) unless aircraft
|
||||||
|
back_with AircraftAccess.new(aircraft, actor: current_user).add(@user, Role.find_by(id: params[:role_id])),
|
||||||
|
t("flash.admin_users.access_added", tail_number: aircraft.tail_number)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
membership = @user.aircraft_roles.find(params[:id])
|
||||||
|
back_with AircraftAccess.new(membership.aircraft, actor: current_user).change(membership, Role.find_by(id: params[:role_id])),
|
||||||
|
t("flash.admin_users.access_changed", tail_number: membership.aircraft.tail_number)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
membership = @user.aircraft_roles.find(params[:id])
|
||||||
|
back_with AircraftAccess.new(membership.aircraft, actor: current_user).remove(membership),
|
||||||
|
t("flash.admin_users.access_removed", tail_number: membership.aircraft.tail_number)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_user = @user = User.find(params[:user_id])
|
||||||
|
def back(flash) = redirect_to(edit_admin_user_path(@user, anchor: "access"), flash)
|
||||||
|
def back_with(error, notice) = back(error ? { alert: error } : { notice: notice })
|
||||||
|
end
|
||||||
@@ -3,7 +3,7 @@ class Admin::UsersController < ApplicationController
|
|||||||
before_action :set_user, only: %i[edit update destroy disable enable unlock reset_two_factor]
|
before_action :set_user, only: %i[edit update destroy disable enable unlock reset_two_factor]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@users = User.order(:email_address).includes(:certificates, aircraft_roles: :aircraft)
|
@users = User.order(:email_address).includes(:certificates, aircraft_roles: %i[aircraft role])
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Download the aircraft's flights as an AirTrail import file.
|
# Download the aircraft's flights as an AirTrail import file.
|
||||||
class AirTrailExportsController < ApplicationController
|
class AirTrailExportsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
|
requires_permission :log_flights
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@export = build_export
|
@export = build_export
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
class AircraftController < ApplicationController
|
class AircraftController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
skip_before_action :set_aircraft, only: %i[index new create]
|
skip_before_action :set_aircraft, :authorize_permission!, only: %i[index new create]
|
||||||
before_action :require_owner!, only: %i[edit update destroy]
|
requires_permission :edit_aircraft, only: %i[edit update]
|
||||||
|
requires_permission :delete_aircraft, only: :destroy
|
||||||
|
requires_permission :update_hours, only: :update_hours
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@aircraft_list = current_user.accessible_aircraft.ordered.with_attached_picture
|
@aircraft_list = current_user.accessible_aircraft.ordered.with_attached_picture
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Download an aircraft as a .sam.zip archive (owners and admins).
|
# Download an aircraft as a .sam.zip archive (owners and admins).
|
||||||
class AircraftExportsController < ApplicationController
|
class AircraftExportsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :export_data
|
||||||
|
|
||||||
EXPORT_DIR = Rails.root.join("tmp/exports")
|
EXPORT_DIR = Rails.root.join("tmp/exports")
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +1,37 @@
|
|||||||
# Owner-only: manage who can access the aircraft, and its public share links.
|
# Who can access the aircraft, with which role ("manage people"), and its
|
||||||
|
# public share links ("manage sharing", see ShareTokensController). The rules
|
||||||
|
# for changing roles are in AircraftAccess.
|
||||||
class AircraftRolesController < ApplicationController
|
class AircraftRolesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
checks_permission_itself only: :index
|
||||||
|
requires_permission :manage_people, only: %i[create update destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@roles = @aircraft.roles.includes(:user).order(:role, :created_at)
|
return permission_denied unless can?(:manage_people) || can?(:manage_sharing) || can?(:export_data)
|
||||||
|
@access = AircraftAccess.new(@aircraft, actor: current_user)
|
||||||
|
@roles = @aircraft.roles.includes(:user, :role).joins(:role).order("roles.position", :created_at)
|
||||||
@share_tokens = @aircraft.share_tokens.order(created_at: :desc).includes(:created_by)
|
@share_tokens = @aircraft.share_tokens.order(created_at: :desc).includes(:created_by)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
user = User.find_by(email_address: params[:email_address].to_s.strip.downcase)
|
user = User.find_by(email_address: params[:email_address].to_s.strip.downcase)
|
||||||
unless user
|
return back(alert: t("flash.aircraft_roles.no_user_with_that")) unless user
|
||||||
return redirect_to aircraft_aircraft_roles_path(@aircraft),
|
error = access.add(user, Role.find_by(id: params[:role_id]))
|
||||||
alert: t("flash.aircraft_roles.no_user_with_that")
|
back(error ? { alert: error } : { notice: t("flash.aircraft_roles.added", display_name: user.display_name) })
|
||||||
end
|
|
||||||
role = @aircraft.roles.new(user: user, role: params[:role])
|
|
||||||
if role.save
|
|
||||||
log_event("role", t("flash.aircraft_roles.added_as", display_name: user.display_name, role: role.role))
|
|
||||||
redirect_to aircraft_aircraft_roles_path(@aircraft), notice: t("flash.aircraft_roles.added", display_name: user.display_name)
|
|
||||||
else
|
|
||||||
redirect_to aircraft_aircraft_roles_path(@aircraft), alert: role.errors.full_messages.to_sentence
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
role = @aircraft.roles.find(params[:id])
|
error = access.change(@aircraft.roles.find(params[:id]), Role.find_by(id: params[:role_id]))
|
||||||
if demoting_last_owner?(role, params[:role])
|
back(error ? { alert: error } : { notice: t("flash.aircraft_roles.role_updated") })
|
||||||
return redirect_to aircraft_aircraft_roles_path(@aircraft), alert: t("flash.aircraft_roles.an_aircraft_must_keep")
|
|
||||||
end
|
|
||||||
role.update!(role: params[:role])
|
|
||||||
log_event("role", t("flash.aircraft_roles.changed_to", display_name: role.user.display_name, role: role.role))
|
|
||||||
redirect_to aircraft_aircraft_roles_path(@aircraft), notice: t("flash.aircraft_roles.role_updated")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
role = @aircraft.roles.find(params[:id])
|
error = access.remove(@aircraft.roles.find(params[:id]))
|
||||||
if role.user == current_user
|
back(error ? { alert: error } : { notice: t("flash.aircraft_roles.access_removed") })
|
||||||
return redirect_to aircraft_aircraft_roles_path(@aircraft), alert: t("flash.aircraft_roles.you_can_t_remove")
|
|
||||||
end
|
|
||||||
if demoting_last_owner?(role, nil)
|
|
||||||
return redirect_to aircraft_aircraft_roles_path(@aircraft), alert: t("flash.aircraft_roles.an_aircraft_must_keep_2")
|
|
||||||
end
|
|
||||||
role.destroy!
|
|
||||||
log_event("role", t("flash.aircraft_roles.removed", display_name: role.user.display_name))
|
|
||||||
redirect_to aircraft_aircraft_roles_path(@aircraft), notice: t("flash.aircraft_roles.access_removed")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def demoting_last_owner?(role, new_role)
|
def access = AircraftAccess.new(@aircraft, actor: current_user)
|
||||||
role.role == "owner" && new_role != "owner" && @aircraft.roles.owners.count <= 1
|
def back(flash) = redirect_to(aircraft_aircraft_roles_path(@aircraft), flash)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# Flights → Standardize airport codes (owners).
|
# Flights → Standardize airport codes (owners).
|
||||||
class AirportCodesController < ApplicationController
|
class AirportCodesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :edit_any_flight
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@standardizer = AirportCodeStandardizer.new(@aircraft)
|
@standardizer = AirportCodeStandardizer.new(@aircraft)
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
class AirworthinessDirectivesController < ApplicationController
|
class AirworthinessDirectivesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
include Applicability
|
include Applicability
|
||||||
before_action :require_owner!, except: :index
|
requires_permission :manage_ads, except: :index
|
||||||
before_action :set_ad, only: %i[edit update destroy]
|
before_action :set_ad, only: %i[edit update destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@rows = Compliance.ad_rows(@aircraft)
|
@rows = Compliance.ad_rows(@aircraft)
|
||||||
@history = AdCompliance.for_aircraft(@aircraft).recent_first
|
@history = AdCompliance.for_aircraft(@aircraft).recent_first
|
||||||
.includes(:component, :logbook_entry, airworthiness_directive: :document, inspection_record: :inspection_type)
|
.includes(:component, :logbook_entry, airworthiness_directive: :document, inspection_record: :inspection_type)
|
||||||
@attachable = AirworthinessDirective.where.not(id: @aircraft.applicable_ads.select(:id)).ordered if owner?
|
@attachable = AirworthinessDirective.where.not(id: @aircraft.applicable_ads.select(:id)).ordered if can?(:manage_ads)
|
||||||
@alerts = @aircraft.ad_alerts.pending
|
@alerts = @aircraft.ad_alerts.pending
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -70,8 +70,12 @@ module Api
|
|||||||
|
|
||||||
def find_aircraft(id = params[:aircraft_id]) = aircraft_scope.find(id)
|
def find_aircraft(id = params[:aircraft_id]) = aircraft_scope.find(id)
|
||||||
|
|
||||||
def role_on(aircraft) = acting_user&.role_for(aircraft)
|
# What the person it's acting for can do on the aircraft, as in the app (Role).
|
||||||
def owner_of?(aircraft) = role_on(aircraft).in?(%w[admin owner])
|
def can?(permission, aircraft) = acting_user&.can?(permission, aircraft) || false
|
||||||
|
|
||||||
|
def not_permitted(permission)
|
||||||
|
render_error(:forbidden, "not_permitted", "This needs the \"#{Permission.label(permission)}\" permission on the aircraft.")
|
||||||
|
end
|
||||||
|
|
||||||
# ?limit= (1–200, default 50), ?after=<id> to continue, ?updated_since=<ISO time>.
|
# ?limit= (1–200, default 50), ?after=<id> to continue, ?updated_since=<ISO time>.
|
||||||
def paginate(scope)
|
def paginate(scope)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ module Api
|
|||||||
# POST /aircraft/:aircraft_id/draft_batches
|
# POST /aircraft/:aircraft_id/draft_batches
|
||||||
def create
|
def create
|
||||||
@aircraft = find_aircraft
|
@aircraft = find_aircraft
|
||||||
return render_error(:forbidden, "owners_only", "Draft entries are for the aircraft's owners (act for an owner).") unless owner_of?(@aircraft)
|
return not_permitted(:write_logbook) unless can?(:write_logbook, @aircraft)
|
||||||
|
|
||||||
input = params.require(:draft_batch)
|
input = params.require(:draft_batch)
|
||||||
items = Array(input[:items]).map { _1.permit(:log, :text, :external_ref, resolves_squawks: []) }
|
items = Array(input[:items]).map { _1.permit(:log, :text, :external_ref, resolves_squawks: []) }
|
||||||
@@ -54,7 +54,7 @@ module Api
|
|||||||
# DELETE /draft_batches/:id: withdraw it while nothing in it is signed.
|
# DELETE /draft_batches/:id: withdraw it while nothing in it is signed.
|
||||||
def destroy
|
def destroy
|
||||||
batch = find_batch
|
batch = find_batch
|
||||||
return render_error(:forbidden, "owners_only", "Only the aircraft's owners can withdraw a draft.") unless owner_of?(batch.aircraft)
|
return not_permitted(:write_logbook) unless can?(:write_logbook, batch.aircraft)
|
||||||
unless batch.awaiting? && batch.entries.none?(&:signed?)
|
unless batch.awaiting? && batch.entries.none?(&:signed?)
|
||||||
return render_error(:conflict, "signed", "Part of this draft is signed (or it's no longer awaiting signature); correct it in the app instead.")
|
return render_error(:conflict, "signed", "Part of this draft is signed (or it's no longer awaiting signature); correct it in the app instead.")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ module Api
|
|||||||
# POST /aircraft/:aircraft_id/squawks
|
# POST /aircraft/:aircraft_id/squawks
|
||||||
def create
|
def create
|
||||||
aircraft = find_aircraft
|
aircraft = find_aircraft
|
||||||
|
return not_permitted(:report_squawks) unless can?(:report_squawks, aircraft)
|
||||||
squawk = aircraft.squawks.new(create_params.merge(reported_by: acting_user, resolved: false))
|
squawk = aircraft.squawks.new(create_params.merge(reported_by: acting_user, resolved: false))
|
||||||
squawk.component_id = nil unless aircraft.components.exists?(id: squawk.component_id)
|
squawk.component_id = nil unless aircraft.components.exists?(id: squawk.component_id)
|
||||||
squawk.save!
|
squawk.save!
|
||||||
@@ -39,13 +40,13 @@ module Api
|
|||||||
end
|
end
|
||||||
|
|
||||||
# PATCH /squawks/:id: external_ref by anyone who may write; the rest
|
# PATCH /squawks/:id: external_ref by anyone who may write; the rest
|
||||||
# (issue, priority, component, notes) by the aircraft's owners, as in the app.
|
# (issue, priority, component, notes) with "manage squawks", as in the app.
|
||||||
def update
|
def update
|
||||||
squawk = find_squawk
|
squawk = find_squawk
|
||||||
return render_error(:unprocessable_entity, "resolved", "A resolved squawk can't be changed.") if squawk.resolved?
|
return render_error(:unprocessable_entity, "resolved", "A resolved squawk can't be changed.") if squawk.resolved?
|
||||||
attrs = params.require(:squawk).permit(:external_ref, :issue_reported, :priority, :component_id, :notes)
|
attrs = params.require(:squawk).permit(:external_ref, :issue_reported, :priority, :component_id, :notes)
|
||||||
if (attrs.keys - %w[external_ref]).any? && !owner_of?(squawk.aircraft)
|
if (attrs.keys - %w[external_ref]).any? && !can?(:manage_squawks, squawk.aircraft)
|
||||||
return render_error(:forbidden, "owners_only", "Only the aircraft's owners can change a squawk's details.")
|
return not_permitted(:manage_squawks)
|
||||||
end
|
end
|
||||||
attrs[:component_id] = nil if attrs.key?(:component_id) && !squawk.aircraft.components.exists?(id: attrs[:component_id])
|
attrs[:component_id] = nil if attrs.key?(:component_id) && !squawk.aircraft.components.exists?(id: attrs[:component_id])
|
||||||
squawk.update!(attrs)
|
squawk.update!(attrs)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class ComponentsController < ApplicationController
|
class ComponentsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, except: %i[index show]
|
requires_permission :manage_components, except: %i[index show]
|
||||||
before_action :set_component, only: %i[show edit update destroy reset_service]
|
before_action :set_component, only: %i[show edit update destroy reset_service]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -1,16 +1,38 @@
|
|||||||
# Scopes a controller to one aircraft the current user can access and exposes
|
# Scopes a controller to one aircraft the current user can access, and checks
|
||||||
# role helpers. Unknown and inaccessible aircraft both 404 (enumeration-safe).
|
# what their role there allows (Role, Permission). Unknown and inaccessible
|
||||||
|
# aircraft both 404 (enumeration-safe). Administrators can do everything.
|
||||||
#
|
#
|
||||||
# Access matrix (mirrors the original):
|
# Each controller says which permission its actions need:
|
||||||
# admin – everything
|
#
|
||||||
# owner – everything on their aircraft
|
# requires_permission :manage_components, except: %i[index show]
|
||||||
# pilot – view all; update hours; create squawks, notes, oil/fuel, flight logs
|
# requires_permission :report_squawks, only: %i[new create]
|
||||||
|
# checks_permission_itself only: %i[edit update] # decided in the controller
|
||||||
|
#
|
||||||
|
# Looking needs no permission. A request that changes something (anything but
|
||||||
|
# GET/HEAD) with no permission declared for its action is refused, so nothing
|
||||||
|
# is left open by mistake; in development and tests it raises instead.
|
||||||
module AircraftScoped
|
module AircraftScoped
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
SELF_CHECKED = "(checked by the controller)".freeze
|
||||||
|
|
||||||
|
class MissingPermission < StandardError; end
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
class_attribute :permission_rules, instance_accessor: false, default: []
|
||||||
before_action :set_aircraft
|
before_action :set_aircraft
|
||||||
helper_method :current_role, :owner?, :can_write?
|
before_action :authorize_permission!
|
||||||
|
helper_method :current_role, :can?, :owner?
|
||||||
|
end
|
||||||
|
|
||||||
|
class_methods do
|
||||||
|
def requires_permission(permission, only: nil, except: nil)
|
||||||
|
self.permission_rules += [ [ permission.to_s, only && Array(only).map(&:to_s), except && Array(except).map(&:to_s) ] ]
|
||||||
|
end
|
||||||
|
|
||||||
|
def checks_permission_itself(only:)
|
||||||
|
requires_permission(SELF_CHECKED, only: only)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -21,18 +43,34 @@ module AircraftScoped
|
|||||||
@aircraft = current_user.accessible_aircraft.find(aircraft_param)
|
@aircraft = current_user.accessible_aircraft.find(aircraft_param)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Their Role here (nil for an administrator without one).
|
||||||
def current_role
|
def current_role
|
||||||
@current_role ||= current_user.role_for(@aircraft)
|
return @current_role if defined?(@current_role)
|
||||||
|
@current_role = current_user.role_for(@aircraft)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Owner-level write access (admins included).
|
def can?(permission) = current_user.admin? || current_role&.can?(permission) || false
|
||||||
def owner? = current_role.in?(%w[admin owner])
|
|
||||||
alias_method :can_write?, :owner?
|
|
||||||
|
|
||||||
def require_owner!
|
# The Owner role (or an administrator): everything.
|
||||||
return if owner?
|
def owner? = current_user.admin? || current_role&.owner? || false
|
||||||
redirect_back fallback_location: aircraft_path(@aircraft),
|
|
||||||
alert: t("flash.common.only_owners_can_do")
|
def authorize_permission!
|
||||||
|
rules = self.class.permission_rules.select do |_, only, except|
|
||||||
|
(only.nil? || only.include?(action_name)) && (except.nil? || except.exclude?(action_name))
|
||||||
|
end
|
||||||
|
if rules.empty?
|
||||||
|
return if request.get? || request.head?
|
||||||
|
raise MissingPermission, "#{self.class.name}##{action_name} changes data without declaring a permission" if Rails.env.local?
|
||||||
|
return permission_denied
|
||||||
|
end
|
||||||
|
permission_denied unless rules.all? { |permission, *| permission == SELF_CHECKED || can?(permission) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def permission_denied
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_back fallback_location: aircraft_path(@aircraft), alert: t("flash.common.not_allowed") }
|
||||||
|
format.any { head :forbidden }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns id only if it belongs to the given (aircraft-scoped) relation; else nil.
|
# Returns id only if it belongs to the given (aircraft-scoped) relation; else nil.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class ConsumableRecordsController < ApplicationController
|
class ConsumableRecordsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, only: %i[edit update destroy]
|
requires_permission :record_consumables, only: %i[new create]
|
||||||
|
requires_permission :manage_consumables, only: %i[edit update destroy]
|
||||||
before_action :set_record, only: %i[edit update destroy]
|
before_action :set_record, only: %i[edit update destroy]
|
||||||
|
|
||||||
RECORDS_PER_PAGE = 50
|
RECORDS_PER_PAGE = 50
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class DocumentCollectionsController < ApplicationController
|
class DocumentCollectionsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :manage_documents
|
||||||
before_action :set_collection, only: %i[edit update destroy]
|
before_action :set_collection, only: %i[edit update destroy]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class DocumentsController < ApplicationController
|
class DocumentsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, except: %i[index show]
|
requires_permission :manage_documents, except: %i[index show]
|
||||||
before_action :set_document, only: %i[show edit update destroy]
|
before_action :set_document, only: %i[show edit update destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
# who they are again (password, or single sign-on just now), and confirms.
|
# who they are again (password, or single sign-on just now), and confirms.
|
||||||
class EntrySignaturesController < ApplicationController
|
class EntrySignaturesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
|
requires_permission :sign_logbook
|
||||||
include EntrySigning
|
include EntrySigning
|
||||||
before_action :set_entry
|
before_action :set_entry
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
class FlightImportsController < ApplicationController
|
class FlightImportsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
include StoredUpload
|
include StoredUpload
|
||||||
before_action :require_owner!
|
requires_permission :import_flights
|
||||||
|
|
||||||
def new; end
|
def new; end
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
class FlightLogsController < ApplicationController
|
class FlightLogsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, only: :destroy
|
requires_permission :log_flights, only: %i[new create]
|
||||||
|
requires_permission :delete_flights, only: :destroy
|
||||||
|
checks_permission_itself only: %i[edit update attach_engine_data remove_engine_data]
|
||||||
before_action :set_flight_log, only: %i[show edit update engine_data_series attach_engine_data remove_engine_data]
|
before_action :set_flight_log, only: %i[show edit update engine_data_series attach_engine_data remove_engine_data]
|
||||||
before_action :require_flight_editor!, only: %i[edit update]
|
before_action :require_flight_editor!, only: %i[edit update]
|
||||||
helper_method :can_edit_flight?
|
helper_method :can_edit_flight?
|
||||||
@@ -126,7 +128,10 @@ class FlightLogsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def can_edit_flight?(flight) = flight.editable_by?(current_user, role: current_role)
|
# Any flight with "correct any flight"; the ones they logged with "correct own flights".
|
||||||
|
def can_edit_flight?(flight)
|
||||||
|
can?(:edit_any_flight) || (can?(:edit_own_flights) && flight.user_id.present? && flight.user_id == current_user.id)
|
||||||
|
end
|
||||||
|
|
||||||
def require_flight_editor!
|
def require_flight_editor!
|
||||||
return if can_edit_flight?(@flight_log)
|
return if can_edit_flight?(@flight_log)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class InspectionRecordsController < ApplicationController
|
class InspectionRecordsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :manage_inspections
|
||||||
before_action :set_record, only: %i[edit update destroy]
|
before_action :set_record, only: %i[edit update destroy]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class InspectionTypesController < ApplicationController
|
class InspectionTypesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
include Applicability
|
include Applicability
|
||||||
before_action :require_owner!
|
requires_permission :manage_inspections
|
||||||
before_action :set_type, only: %i[edit update destroy]
|
before_action :set_type, only: %i[edit update destroy]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# the loading calculator.
|
# the loading calculator.
|
||||||
class LoadingSetupsController < ApplicationController
|
class LoadingSetupsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :manage_weight_balance
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@setup = @aircraft.loading_setup
|
@setup = @aircraft.loading_setup
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class LogbookEntriesController < ApplicationController
|
class LogbookEntriesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, except: %i[index show]
|
requires_permission :write_logbook, except: %i[index show]
|
||||||
before_action :set_entry, only: %i[show edit update destroy verify]
|
before_action :set_entry, only: %i[show edit update destroy verify]
|
||||||
before_action :require_unsigned, only: %i[edit update destroy]
|
before_action :require_unsigned, only: %i[edit update destroy]
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# entries in the background (LogbookTranscriptionJob).
|
# entries in the background (LogbookTranscriptionJob).
|
||||||
class LogbookImportsController < ApplicationController
|
class LogbookImportsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :import_records
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@collections = @aircraft.document_collections.ordered
|
@collections = @aircraft.document_collections.ordered
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class MajorRecordsController < ApplicationController
|
class MajorRecordsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, except: %i[index show]
|
requires_permission :manage_major_records, except: %i[index show]
|
||||||
before_action :set_record, only: %i[show edit update destroy]
|
before_action :set_record, only: %i[show edit update destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class NotesController < ApplicationController
|
class NotesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, only: %i[edit update destroy]
|
requires_permission :write_notes, only: %i[new create preview]
|
||||||
|
requires_permission :manage_notes, only: %i[edit update destroy]
|
||||||
before_action :set_note, only: %i[edit update destroy]
|
before_action :set_note, only: %i[edit update destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class OilAnalysesController < ApplicationController
|
class OilAnalysesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, only: %i[edit update destroy]
|
requires_permission :record_oil_analyses, only: %i[new create import]
|
||||||
|
requires_permission :manage_oil_analyses, only: %i[edit update destroy]
|
||||||
before_action :set_analysis, only: %i[show edit update destroy]
|
before_action :set_analysis, only: %i[show edit update destroy]
|
||||||
|
|
||||||
COMPARE_SAMPLES = 6 # columns in the trend table, like the lab report's history
|
COMPARE_SAMPLES = 6 # columns in the trend table, like the lab report's history
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Every change to the aircraft's maintenance records (AC 120-78B 3.2.2).
|
# Every change to the aircraft's maintenance records (AC 120-78B 3.2.2).
|
||||||
class RecordVersionsController < ApplicationController
|
class RecordVersionsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, only: :restore
|
requires_permission :restore_history, only: :restore
|
||||||
|
|
||||||
SHARED = { "AirworthinessDirective" => AirworthinessDirective, "InspectionType" => InspectionType }.freeze
|
SHARED = { "AirworthinessDirective" => AirworthinessDirective, "InspectionType" => InspectionType }.freeze
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Download every record of an aircraft in one ZIP (owners).
|
# Download every record of an aircraft in one ZIP (owners).
|
||||||
class RecordsPackagesController < ApplicationController
|
class RecordsPackagesController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :export_data
|
||||||
|
|
||||||
def show
|
def show
|
||||||
package = RecordsPackage.new(@aircraft, source: request.host)
|
package = RecordsPackage.new(@aircraft, source: request.host)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class ShareTokensController < ApplicationController
|
class ShareTokensController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :manage_sharing
|
||||||
|
|
||||||
def create
|
def create
|
||||||
token = @aircraft.share_tokens.new(params.require(:share_token).permit(:label, :privilege, :expires_at))
|
token = @aircraft.share_tokens.new(params.require(:share_token).permit(:label, :privilege, :expires_at))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# An owner asks someone outside the aircraft (a mechanic) to sign an entry.
|
# An owner asks someone outside the aircraft (a mechanic) to sign an entry.
|
||||||
class SigningInvitationsController < ApplicationController
|
class SigningInvitationsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :write_logbook
|
||||||
before_action :set_entry
|
before_action :set_entry
|
||||||
rate_limit to: 10, within: 1.hour, only: :create, with: -> { redirect_back fallback_location: root_path, alert: t("flash.signing_invitations.too_many_invitations_try") }
|
rate_limit to: 10, within: 1.hour, only: :create, with: -> { redirect_back fallback_location: root_path, alert: t("flash.signing_invitations.too_many_invitations_try") }
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ class SquawksController < ApplicationController
|
|||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
# Pilots may create squawks and defer inoperative items (91.213(d) lets the
|
# Pilots may create squawks and defer inoperative items (91.213(d) lets the
|
||||||
# pilot decide); editing and resolving need an owner.
|
# pilot decide); editing and resolving need an owner.
|
||||||
before_action :require_owner!, except: %i[index new create deferral defer]
|
requires_permission :report_squawks, only: %i[new create]
|
||||||
|
requires_permission :defer_squawks, only: %i[deferral defer]
|
||||||
|
requires_permission :manage_squawks, except: %i[index new create deferral defer]
|
||||||
before_action :set_squawk, only: %i[edit update destroy resolution resolve reopen deferral defer undefer]
|
before_action :set_squawk, only: %i[edit update destroy resolution resolve reopen deferral defer undefer]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class StandardInspectionsController < ApplicationController
|
class StandardInspectionsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!
|
requires_permission :manage_inspections
|
||||||
|
|
||||||
def new; end
|
def new; end
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# keep the records and the loading setup).
|
# keep the records and the loading setup).
|
||||||
class WeightBalanceRecordsController < ApplicationController
|
class WeightBalanceRecordsController < ApplicationController
|
||||||
include AircraftScoped
|
include AircraftScoped
|
||||||
before_action :require_owner!, except: :index
|
requires_permission :manage_weight_balance, except: :index
|
||||||
before_action :set_record, only: %i[edit update destroy]
|
before_action :set_record, only: %i[edit update destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -3,11 +3,14 @@ module AircraftHelper
|
|||||||
|
|
||||||
# What the app saves ahead of time for use without signal (see
|
# What the app saves ahead of time for use without signal (see
|
||||||
# offline_prep_controller.js): for each of your aircraft, the Overview, W&B,
|
# offline_prep_controller.js): for each of your aircraft, the Overview, W&B,
|
||||||
# Log Flight and Report Squawk pages, and its photo (at both page sizes).
|
# Log Flight and Report Squawk pages (when their role allows them), and its
|
||||||
|
# photo (at both page sizes).
|
||||||
def offline_pages
|
def offline_pages
|
||||||
current_user.accessible_aircraft.ordered.limit(OFFLINE_AIRCRAFT).map do |a|
|
current_user.accessible_aircraft.ordered.limit(OFFLINE_AIRCRAFT).map do |a|
|
||||||
|
role = current_user.role_for(a)
|
||||||
|
can = ->(permission) { current_user.admin? || role&.can?(permission) }
|
||||||
{ tail: a.tail_number, pages: [ aircraft_path(a), aircraft_weight_balance_records_path(a) ],
|
{ tail: a.tail_number, pages: [ aircraft_path(a), aircraft_weight_balance_records_path(a) ],
|
||||||
flight: new_aircraft_flight_log_path(a), squawk: new_aircraft_squawk_path(a),
|
flight: (new_aircraft_flight_log_path(a) if can.(:log_flights)), squawk: (new_aircraft_squawk_path(a) if can.(:report_squawks)),
|
||||||
pictures: (%i[thumb card].map { url_for(a.picture_for(_1)) }.uniq if a.picture_shown?) }.compact
|
pictures: (%i[thumb card].map { url_for(a.picture_for(_1)) }.uniq if a.picture_shown?) }.compact
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ export default class extends Controller {
|
|||||||
const forms = {}
|
const forms = {}
|
||||||
const paths = [ "/" ]
|
const paths = [ "/" ]
|
||||||
for (const a of this.aircraftValue) {
|
for (const a of this.aircraftValue) {
|
||||||
paths.push(...a.pages, a.flight, a.squawk)
|
paths.push(...a.pages)
|
||||||
forms[a.flight] = { tail: a.tail, kind: "flight" }
|
if (a.flight) { paths.push(a.flight); forms[a.flight] = { tail: a.tail, kind: "flight" } }
|
||||||
forms[a.squawk] = { tail: a.tail, kind: "squawk" }
|
if (a.squawk) { paths.push(a.squawk); forms[a.squawk] = { tail: a.tail, kind: "squawk" } }
|
||||||
}
|
}
|
||||||
const pictures = this.aircraftValue.flatMap((a) => a.pictures || [])
|
const pictures = this.aircraftValue.flatMap((a) => a.pictures || [])
|
||||||
const total = paths.length + 1
|
const total = paths.length + 1
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
# Daily: tells owners about items that have newly become overdue or limit
|
# Daily: tells those who get its reminders (Role "gets reminders") about items that have newly become overdue or limit
|
||||||
# the aircraft (grounded, VFR only…). Each is sent once; one that's fixed and
|
# the aircraft (grounded, VFR only…). Each is sent once; one that's fixed and
|
||||||
# becomes overdue again is sent again.
|
# becomes overdue again is sent again.
|
||||||
class OverdueNotificationJob < ApplicationJob
|
class OverdueNotificationJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
Aircraft.includes(roles: :user).find_each do |aircraft|
|
Aircraft.includes(roles: %i[user role]).find_each do |aircraft|
|
||||||
issues = aircraft.airworthiness.issues.select { _1.severity.in?([ Airworthiness::RED, Airworthiness::LIMITED ]) }
|
issues = aircraft.airworthiness.issues.select { _1.severity.in?([ Airworthiness::RED, Airworthiness::LIMITED ]) }
|
||||||
keys = issues.map { |i| "#{i.category}:#{i.item.class.name}:#{i.item.id}" }
|
keys = issues.map { |i| "#{i.category}:#{i.item.class.name}:#{i.item.id}" }
|
||||||
fresh = issues.reject.with_index { |_, n| aircraft.notified_issue_keys.include?(keys[n]) }
|
fresh = issues.reject.with_index { |_, n| aircraft.notified_issue_keys.include?(keys[n]) }
|
||||||
owners = aircraft.roles.select { _1.role == "owner" }.map(&:user).reject(&:disabled?)
|
recipients = aircraft.roles.select { _1.role.can?(:receive_reminders) }.map(&:user).reject(&:disabled?)
|
||||||
if fresh.any?
|
if fresh.any?
|
||||||
PushNotifier.notify(owners, :overdue, path: Rails.application.routes.url_helpers.aircraft_path(aircraft), tag: "overdue-#{aircraft.id}",
|
PushNotifier.notify(recipients, :overdue, path: Rails.application.routes.url_helpers.aircraft_path(aircraft), tag: "overdue-#{aircraft.id}",
|
||||||
tail: aircraft.tail_number, items: fresh.map(&:title).to_sentence, count: fresh.size)
|
tail: aircraft.tail_number, items: fresh.map(&:title).to_sentence, count: fresh.size)
|
||||||
end
|
end
|
||||||
aircraft.update_column(:notified_issue_keys, keys) if keys.sort != aircraft.notified_issue_keys.sort
|
aircraft.update_column(:notified_issue_keys, keys) if keys.sort != aircraft.notified_issue_keys.sort
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Weekly email to aircraft owners listing what's overdue or coming due
|
# Weekly email to those who get an aircraft's reminders (Role "gets reminders") listing what's overdue or coming due
|
||||||
# (inspections, ADs, components, expiring documents), deferred items, new
|
# (inspections, ADs, components, expiring documents), deferred items, new
|
||||||
# ADs, and the user's own certificates that are about to expire.
|
# ADs, and the user's own certificates that are about to expire.
|
||||||
# Nothing is sent when nothing needs attention, or when email isn't set up.
|
# Nothing is sent when nothing needs attention, or when email isn't set up.
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
class ReminderMailer < ApplicationMailer
|
class ReminderMailer < ApplicationMailer
|
||||||
# [[aircraft, issues, new AD alerts], …] for the aircraft the user owns
|
# Aircraft where the user's role includes the permission.
|
||||||
# that need attention.
|
def self.aircraft_where(user, permission)
|
||||||
|
Aircraft.where(id: AircraftRole.with_permission(permission).where(user_id: user.id).select(:aircraft_id)).ordered
|
||||||
|
end
|
||||||
|
|
||||||
|
# [[aircraft, issues, new AD alerts], …] for the aircraft the user gets
|
||||||
|
# reminders for (their role's "gets reminders") that need attention.
|
||||||
def self.items_for(user)
|
def self.items_for(user)
|
||||||
Aircraft.joins(:roles).where(aircraft_roles: { user_id: user.id, role: "owner" }).ordered
|
aircraft_where(user, :receive_reminders)
|
||||||
.map { [ _1, _1.airworthiness.issues, _1.ad_alerts.pending.to_a ] }.reject { _2.empty? && _3.empty? }
|
.map { [ _1, _1.airworthiness.issues, _1.ad_alerts.pending.to_a ] }.reject { _2.empty? && _3.empty? }
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -10,10 +15,11 @@ class ReminderMailer < ApplicationMailer
|
|||||||
|
|
||||||
def self.audit_due_for?(user) = user.admin? && AuditRun.due_soon?
|
def self.audit_due_for?(user) = user.admin? && AuditRun.due_soon?
|
||||||
|
|
||||||
# Owned aircraft whose AD baseline needs a (new) DRS import: none yet, a
|
# Aircraft they get reminders for and manage the ADs of, whose AD baseline
|
||||||
# year old, or a model never covered.
|
# needs a (new) DRS import: none yet, a year old, or a model never covered.
|
||||||
def self.drs_due_for(user)
|
def self.drs_due_for(user)
|
||||||
Aircraft.joins(:roles).where(aircraft_roles: { user_id: user.id, role: "owner" }).ordered
|
aircraft_where(user, :receive_reminders)
|
||||||
|
.where(id: AircraftRole.with_permission(:manage_ads).where(user_id: user.id).select(:aircraft_id))
|
||||||
.select { DrsImport.renewal_due?(_1) || DrsImport.missing_models(_1).any? }
|
.select { DrsImport.renewal_due?(_1) || DrsImport.missing_models(_1).any? }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
|
# Someone's role on an aircraft (Role), which decides what they can do there.
|
||||||
class AircraftRole < ApplicationRecord
|
class AircraftRole < ApplicationRecord
|
||||||
ROLES = LabelSet.new("aircraft_role.roles", %w[owner pilot])
|
|
||||||
|
|
||||||
belongs_to :aircraft
|
belongs_to :aircraft
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :role
|
||||||
|
|
||||||
validates :role, inclusion: { in: ROLES.keys }
|
|
||||||
validates :user_id, uniqueness: { scope: :aircraft_id, message: "already has a role on this aircraft" }
|
validates :user_id, uniqueness: { scope: :aircraft_id, message: "already has a role on this aircraft" }
|
||||||
|
|
||||||
scope :owners, -> { where(role: "owner") }
|
scope :owners, -> { joins(:role).where(roles: { key: "owner" }) }
|
||||||
|
# Whose role includes a permission (Owner always does).
|
||||||
|
scope :with_permission, ->(permission) {
|
||||||
|
joins(:role).where("roles.key = 'owner' OR EXISTS (SELECT 1 FROM json_each(roles.permissions) WHERE json_each.value = ?)", permission.to_s)
|
||||||
|
}
|
||||||
|
|
||||||
|
# A Role, or a built-in role's key ("owner", "pilot").
|
||||||
|
def role=(value)
|
||||||
|
super(value.is_a?(Role) || value.nil? ? value : Role.for_key(value))
|
||||||
|
end
|
||||||
|
|
||||||
|
def owner? = role&.owner?
|
||||||
end
|
end
|
||||||
@@ -36,11 +36,6 @@ class FlightLog < ApplicationRecord
|
|||||||
aircraft.flight_logs.maximum(:id) == id && (tach_in.nil? || tach_in == aircraft.tach_time)
|
aircraft.flight_logs.maximum(:id) == id && (tach_in.nil? || tach_in == aircraft.tach_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Owners can correct any flight; a pilot, the flights they logged.
|
|
||||||
def editable_by?(user, role:)
|
|
||||||
role.in?(%w[admin owner]) || (user_id.present? && user_id == user.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Reject files the engine data parser can't read, before they're stored.
|
# Reject files the engine data parser can't read, before they're stored.
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# What a role on an aircraft can do (Role#permissions). Grouped the way the
|
||||||
|
# app is laid out; labels and descriptions are in config/locales
|
||||||
|
# (permissions.<key>.label / .description). Seeing an aircraft's records
|
||||||
|
# needs no permission: every role can view everything on its aircraft.
|
||||||
|
module Permission
|
||||||
|
GROUPS = {
|
||||||
|
flying: %w[log_flights update_hours import_flights edit_own_flights edit_any_flight delete_flights],
|
||||||
|
squawks_and_notes: %w[report_squawks defer_squawks manage_squawks write_notes manage_notes record_consumables manage_consumables],
|
||||||
|
maintenance: %w[write_logbook sign_logbook manage_components manage_inspections manage_ads manage_major_records
|
||||||
|
manage_weight_balance manage_documents record_oil_analyses manage_oil_analyses],
|
||||||
|
data: %w[import_records export_data restore_history],
|
||||||
|
aircraft: %w[edit_aircraft delete_aircraft manage_people manage_sharing],
|
||||||
|
notifications: %w[receive_reminders]
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
ALL = GROUPS.values.flatten.freeze
|
||||||
|
|
||||||
|
# The built-in roles' permissions when first created (admins can change all
|
||||||
|
# but Owner's, which always has every permission). Pilot is what pilots
|
||||||
|
# could do before roles were configurable.
|
||||||
|
DEFAULTS = {
|
||||||
|
"pilot" => %w[log_flights update_hours edit_own_flights report_squawks defer_squawks write_notes record_consumables
|
||||||
|
record_oil_analyses sign_logbook],
|
||||||
|
"mechanic" => %w[update_hours report_squawks defer_squawks manage_squawks write_notes manage_notes record_consumables
|
||||||
|
manage_consumables write_logbook sign_logbook manage_components manage_inspections manage_ads
|
||||||
|
manage_major_records manage_weight_balance manage_documents record_oil_analyses manage_oil_analyses
|
||||||
|
receive_reminders],
|
||||||
|
"viewer" => []
|
||||||
|
}.freeze
|
||||||
|
|
||||||
|
def self.label(key) = I18n.t("permissions.#{key}.label")
|
||||||
|
def self.description(key) = I18n.t("permissions.#{key}.description")
|
||||||
|
def self.group_label(group) = I18n.t("permissions.groups.#{group}")
|
||||||
|
end
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
# A role someone can have on an aircraft: a name and a set of permissions
|
||||||
|
# (Permission). Installation-wide; administrators manage them (Admin → Roles).
|
||||||
|
# Four are built in (key set): Owner, which always has every permission so an
|
||||||
|
# aircraft can always be managed, and Mechanic, Pilot and Viewer, whose
|
||||||
|
# permissions can be changed. Administrators can add their own.
|
||||||
|
class Role < ApplicationRecord
|
||||||
|
BUILT_IN = %w[owner mechanic pilot viewer].freeze
|
||||||
|
|
||||||
|
has_many :aircraft_roles, dependent: :restrict_with_error
|
||||||
|
|
||||||
|
normalizes :name, with: ->(name) { name.squish }
|
||||||
|
validates :name, presence: true, uniqueness: { case_sensitive: false }, length: { maximum: 40 }
|
||||||
|
validates :description, length: { maximum: 200 }
|
||||||
|
validates :key, inclusion: { in: BUILT_IN }, uniqueness: true, allow_nil: true
|
||||||
|
before_validation { self.permissions = Array(permissions).map(&:to_s) & Permission::ALL }
|
||||||
|
before_destroy { throw :abort if built_in? }
|
||||||
|
|
||||||
|
scope :ordered, -> { order(Arel.sql("CASE WHEN key IS NULL THEN 1 ELSE 0 END"), :position, :name) }
|
||||||
|
|
||||||
|
# The built-in roles, created when first needed (a new installation, tests).
|
||||||
|
def self.ensure_built_in!
|
||||||
|
BUILT_IN.each_with_index do |key, i|
|
||||||
|
find_or_create_by!(key: key) do |role|
|
||||||
|
role.name = I18n.t("roles.#{key}.name")
|
||||||
|
role.description = I18n.t("roles.#{key}.description")
|
||||||
|
role.permissions = Permission::DEFAULTS.fetch(key, [])
|
||||||
|
role.position = i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.for_key(key) = find_by(key: key.to_s) || (ensure_built_in! && find_by!(key: key.to_s))
|
||||||
|
def self.owner = for_key("owner")
|
||||||
|
|
||||||
|
def built_in? = key.present?
|
||||||
|
def owner? = key == "owner"
|
||||||
|
|
||||||
|
def permissions = owner? ? Permission::ALL : super
|
||||||
|
def can?(permission) = permissions.include?(permission.to_s)
|
||||||
|
end
|
||||||
+7
-3
@@ -114,10 +114,14 @@ class User < ApplicationRecord
|
|||||||
admin? ? Aircraft.all : aircraft
|
admin? ? Aircraft.all : aircraft
|
||||||
end
|
end
|
||||||
|
|
||||||
# 'admin' | 'owner' | 'pilot' | nil
|
# Their Role on the aircraft (nil for none; administrators may have none).
|
||||||
def role_for(aircraft)
|
def role_for(aircraft)
|
||||||
return "admin" if admin?
|
aircraft_roles.includes(:role).find_by(aircraft: aircraft)&.role
|
||||||
aircraft_roles.find_by(aircraft: aircraft)&.role
|
end
|
||||||
|
|
||||||
|
# Administrators can do everything on every aircraft.
|
||||||
|
def can?(permission, aircraft)
|
||||||
|
admin? || role_for(aircraft)&.can?(permission) || false
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_name
|
def display_name
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
# Giving, changing and taking away people's roles on an aircraft, by someone
|
||||||
|
# allowed to (the aircraft's "manage people", or an administrator). The rules,
|
||||||
|
# the same from the aircraft's Access page and Admin → Users:
|
||||||
|
# - only an Owner or an administrator can give or take away the Owner role
|
||||||
|
# (otherwise anyone who manages people could make themselves Owner);
|
||||||
|
# - only an administrator can change or remove their own role;
|
||||||
|
# - an aircraft always keeps at least one Owner.
|
||||||
|
# Each method returns nil when done, or a message saying why not.
|
||||||
|
class AircraftAccess
|
||||||
|
def initialize(aircraft, actor:)
|
||||||
|
@aircraft = aircraft
|
||||||
|
@actor = actor
|
||||||
|
end
|
||||||
|
|
||||||
|
def add(user, role)
|
||||||
|
return t("not_found") unless user && role
|
||||||
|
return t("owner_only") if role.owner? && !actor_owner?
|
||||||
|
membership = @aircraft.roles.new(user: user, role: role)
|
||||||
|
return membership.errors.full_messages.to_sentence unless membership.save
|
||||||
|
@aircraft.log_event!("role", I18n.t("flash.aircraft_roles.added_as", display_name: user.display_name, role: role.name), user: @actor)
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def change(membership, role)
|
||||||
|
return t("not_found") unless role
|
||||||
|
return if membership.role == role
|
||||||
|
return t("own_role") if membership.user == @actor && !@actor.admin?
|
||||||
|
return t("owner_only") if (role.owner? || membership.owner?) && !actor_owner?
|
||||||
|
return t("last_owner") if membership.owner? && !role.owner? && last_owner?
|
||||||
|
membership.update!(role: role)
|
||||||
|
@aircraft.log_event!("role", I18n.t("flash.aircraft_roles.changed_to", display_name: membership.user.display_name, role: role.name), user: @actor)
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove(membership)
|
||||||
|
return t("own_role") if membership.user == @actor && !@actor.admin?
|
||||||
|
return t("owner_only") if membership.owner? && !actor_owner?
|
||||||
|
return t("last_owner") if membership.owner? && last_owner?
|
||||||
|
membership.destroy!
|
||||||
|
@aircraft.log_event!("role", I18n.t("flash.aircraft_roles.removed", display_name: membership.user.display_name), user: @actor)
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# The roles this person can hand out here (Owner only by an Owner).
|
||||||
|
def assignable_roles = Role.ordered.select { |role| !role.owner? || actor_owner? }
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def actor_owner? = @actor.admin? || @actor.role_for(@aircraft)&.owner?
|
||||||
|
def last_owner? = @aircraft.roles.owners.count <= 1
|
||||||
|
def t(key) = I18n.t("services.aircraft_access.#{key}")
|
||||||
|
end
|
||||||
@@ -149,7 +149,7 @@ module AircraftArchive
|
|||||||
import_notes
|
import_notes
|
||||||
import_oil_analyses
|
import_oil_analyses
|
||||||
import_flight_logs
|
import_flight_logs
|
||||||
@aircraft.roles.find_or_create_by!(user: @owner, role: "owner") if @owner
|
@aircraft.roles.find_or_create_by!(user: @owner) { _1.role = Role.owner } if @owner
|
||||||
@aircraft.log_event!("aircraft", "Aircraft imported from a .sam.zip archive",
|
@aircraft.log_event!("aircraft", "Aircraft imported from a .sam.zip archive",
|
||||||
notes: [ @manifest["source_instance"].presence && "Source: #{@manifest['source_instance']}", summary ].compact.join(". "),
|
notes: [ @manifest["source_instance"].presence && "Source: #{@manifest['source_instance']}", summary ].compact.join(". "),
|
||||||
user: @owner)
|
user: @owner)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class RecordsAudit
|
|||||||
(signed + pool.where.not(id: signed.map(&:id)).order(Arel.sql("RANDOM()")).limit(@policy.audit_sample_size - signed.size).to_a).first(@policy.audit_sample_size)
|
(signed + pool.where.not(id: signed.map(&:id)).order(Arel.sql("RANDOM()")).limit(@policy.audit_sample_size - signed.size).to_a).first(@policy.audit_sample_size)
|
||||||
end
|
end
|
||||||
|
|
||||||
def users = User.order(:email_address).includes(:certificates, aircraft_roles: :aircraft)
|
def users = User.order(:email_address).includes(:certificates, aircraft_roles: %i[aircraft role])
|
||||||
|
|
||||||
# Saves the audit from the auditor's answers: { key => { "passed" => "1", "note" => … } }.
|
# Saves the audit from the auditor's answers: { key => { "passed" => "1", "note" => … } }.
|
||||||
def record!(user:, answers:, notes:, sample_ids:)
|
def record!(user:, answers:, notes:, sample_ids:)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<% elsif key == "users" %>
|
<% elsif key == "users" %>
|
||||||
<ul class="ml-6 list-disc text-xs text-slate-600">
|
<ul class="ml-6 list-disc text-xs text-slate-600">
|
||||||
<% @audit.users.each do |u| %><li><%= t(".last_sign_in_html", display_name: u.display_name, email_address: u.email_address, admin: (t(".admin") if u.admin?), any: (" · #{u.aircraft_roles.map { "#{AircraftRole::ROLES[_1.role]} #{_1.aircraft.tail_number}" }.join(', ')}" if u.aircraft_roles.any?), never: (u.last_signed_in_at ? t(".ago", time: time_ago_in_words(u.last_signed_in_at)) : t(".never")), disabled: (t(".disabled") if u.disabled?)) %></li><% end %>
|
<% @audit.users.each do |u| %><li><%= t(".last_sign_in_html", display_name: u.display_name, email_address: u.email_address, admin: (t(".admin") if u.admin?), any: (" · #{u.aircraft_roles.map { "#{_1.role.name} #{_1.aircraft.tail_number}" }.join(', ')}" if u.aircraft_roles.any?), never: (u.last_signed_in_at ? t(".ago", time: time_ago_in_words(u.last_signed_in_at)) : t(".never")), disabled: (t(".disabled") if u.disabled?)) %></li><% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= text_field_tag "answers[#{key}][note]", nil, class: "input", placeholder: t(".note_what_was_checked_or") %>
|
<%= text_field_tag "answers[#{key}][note]", nil, class: "input", placeholder: t(".note_what_was_checked_or") %>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
Locals: policy, number, adopted_at, adopted_by, revisions, summary. %>
|
Locals: policy, number, adopted_at, adopted_by, revisions, summary. %>
|
||||||
<% info = SystemInfo.new %>
|
<% info = SystemInfo.new %>
|
||||||
<% aircraft = Aircraft.ordered.includes(:roles) %>
|
<% aircraft = Aircraft.ordered.includes(:roles) %>
|
||||||
<% users = User.order(:email_address).includes(:certificates, aircraft_roles: :aircraft) %>
|
<% users = User.order(:email_address).includes(:certificates, aircraft_roles: %i[aircraft role]) %>
|
||||||
<% h2 = "mt-6 text-base font-semibold" %>
|
<% h2 = "mt-6 text-base font-semibold" %>
|
||||||
<% p_ = "mt-1 text-sm leading-relaxed" %>
|
<% p_ = "mt-1 text-sm leading-relaxed" %>
|
||||||
<article class="text-slate-900">
|
<article class="text-slate-900">
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
<% users.each do |u| %>
|
<% users.each do |u| %>
|
||||||
<% current = u.certificates.reject(&:expired?) %>
|
<% current = u.certificates.reject(&:expired?) %>
|
||||||
<tr class="border-b border-slate-100 align-top"><td class="py-1"><%= u.display_name %><div class="text-xs text-slate-500"><%= u.email_address %></div></td>
|
<tr class="border-b border-slate-100 align-top"><td class="py-1"><%= u.display_name %><div class="text-xs text-slate-500"><%= u.email_address %></div></td>
|
||||||
<td class="text-xs"><%= [ (t(".administrator") if u.admin?), *u.aircraft_roles.map { "#{_1.role.capitalize}, #{_1.aircraft.tail_number}" } ].compact.join("; ").presence || "—" %><%= t(".disabled") if u.disabled? %></td>
|
<td class="text-xs"><%= [ (t(".administrator") if u.admin?), *u.aircraft_roles.map { "#{_1.role.name}, #{_1.aircraft.tail_number}" } ].compact.join("; ").presence || "—" %><%= t(".disabled") if u.disabled? %></td>
|
||||||
<td class="text-xs"><%= u.certificates.map { "#{_1.short_label} #{_1.number}#{" #{t('.expires_short', date: _1.expires_on)}" if _1.expires_on}" }.join("; ").presence || "—" %></td>
|
<td class="text-xs"><%= u.certificates.map { "#{_1.short_label} #{_1.number}#{" #{t('.expires_short', date: _1.expires_on)}" if _1.expires_on}" }.join("; ").presence || "—" %></td>
|
||||||
<td class="text-xs"><%= if u.disabled? || current.empty? then t(".no")
|
<td class="text-xs"><%= if u.disabled? || current.empty? then t(".no")
|
||||||
elsif current.any?(&:mechanic?) then t(".maintenance_and_inspection_entries")
|
elsif current.any?(&:mechanic?) then t(".maintenance_and_inspection_entries")
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<%# A role's name, description and permissions, grouped as in Permission.
|
||||||
|
Owner's permissions are shown but can't be changed: it always has all. %>
|
||||||
|
<%= form_with model: [:admin, role], class: "card card-body max-w-3xl space-y-5" do |f| %>
|
||||||
|
<%= f.errors_summary %>
|
||||||
|
<div class="grid gap-4 sm:grid-cols-2">
|
||||||
|
<%= f.field :name, required: true %>
|
||||||
|
<%= f.field :description, hint: t(".description_hint") %>
|
||||||
|
</div>
|
||||||
|
<% if role.owner? %><p class="rounded-md bg-sky-50 px-3 py-2 text-sm text-sky-900 ring-1 ring-sky-200"><%= t(".owner_has_everything") %></p><% end %>
|
||||||
|
<%= hidden_field_tag "role[permissions][]", "", id: nil %>
|
||||||
|
<div class="grid gap-5 sm:grid-cols-2">
|
||||||
|
<% Permission::GROUPS.each do |group, keys| %>
|
||||||
|
<fieldset class="space-y-2" <%= "disabled" if role.owner? %>>
|
||||||
|
<legend class="mb-1 text-sm font-semibold"><%= Permission.group_label(group) %></legend>
|
||||||
|
<% keys.each do |key| %>
|
||||||
|
<label class="flex items-start gap-2 text-sm">
|
||||||
|
<%= check_box_tag "role[permissions][]", key, role.can?(key), id: "permission_#{key}", class: "mt-0.5" %>
|
||||||
|
<span><%= Permission.label(key) %><span class="block text-xs text-slate-500"><%= Permission.description(key) %></span></span>
|
||||||
|
</label>
|
||||||
|
<% end %>
|
||||||
|
</fieldset>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<p class="hint"><%= t(".viewing_needs_nothing") %></p>
|
||||||
|
<div class="flex flex-wrap gap-2"><%= f.submit t(".save") %><%= link_to t(".cancel"), admin_roles_path, class: "btn-secondary" %></div>
|
||||||
|
<% end %>
|
||||||
|
<% if role.persisted? && !role.built_in? %><div class="mt-4"><%= delete_button t(".delete_role"), admin_role_path(role), confirm: t(".delete_role_confirm", name: role.name) %></div><% end %>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<% content_for :title, t(".edit_role", name: @role.name_was) %>
|
||||||
|
<h1 class="mb-4 text-2xl font-bold"><%= t(".edit_role", name: @role.name_was) %></h1>
|
||||||
|
<%= render "form", role: @role %>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<% content_for :title, t(".roles") %>
|
||||||
|
<div class="mb-2 flex items-center justify-between"><h1 class="text-2xl font-bold"><%= t(".roles") %></h1><%= link_to t(".new_role"), new_admin_role_path, class: "btn-primary" %></div>
|
||||||
|
<p class="mb-4 text-sm text-slate-600"><%= t(".intro") %></p>
|
||||||
|
<section class="card"><table class="table">
|
||||||
|
<thead><tr><th><%= t(".name") %></th><th><%= t(".can") %></th><th class="text-right"><%= t(".people") %></th><th></th></tr></thead>
|
||||||
|
<tbody><% @roles.each do |role| %><tr class="role-row" id="<%= dom_id(role) %>">
|
||||||
|
<td class="align-top"><span class="font-medium"><%= role.name %></span> <% if role.built_in? %><span class="badge-gray"><%= t(".built_in") %></span><% end %>
|
||||||
|
<% if role.description.present? %><div class="text-xs text-slate-500"><%= role.description %></div><% end %></td>
|
||||||
|
<td class="align-top text-xs text-slate-600" data-label="<%= t(".can") %>">
|
||||||
|
<%= role.owner? ? t(".everything") : (role.permissions.map { Permission.label(_1) }.to_sentence.presence || t(".view_only")) %>
|
||||||
|
</td>
|
||||||
|
<td class="align-top text-right tabular-nums" data-label="<%= t(".people") %>"><%= @counts.fetch(role.id, 0) %></td>
|
||||||
|
<td class="align-top text-right"><%= link_to t(".edit"), edit_admin_role_path(role), class: "btn-secondary btn-sm" %></td>
|
||||||
|
</tr><% end %></tbody>
|
||||||
|
</table></section>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<% content_for :title, t(".new_role") %>
|
||||||
|
<h1 class="mb-4 text-2xl font-bold"><%= t(".new_role") %></h1>
|
||||||
|
<%= render "form", role: @role %>
|
||||||
@@ -1,2 +1,35 @@
|
|||||||
<h1 class="mb-4 text-2xl font-bold"><%= t(".edit_user") %></h1>
|
<h1 class="mb-4 text-2xl font-bold"><%= t(".edit_user") %></h1>
|
||||||
<%= render "form", user: @user %>
|
<%= render "form", user: @user %>
|
||||||
|
|
||||||
|
<%# Their role on each aircraft (same rules as each aircraft's Access page, AircraftAccess). %>
|
||||||
|
<section class="card mt-6 max-w-3xl" id="access">
|
||||||
|
<div class="card-header"><h2 class="card-title"><%= t(".aircraft_access") %></h2></div>
|
||||||
|
<% roles = Role.ordered.to_a %>
|
||||||
|
<% memberships = @user.aircraft_roles.includes(:aircraft, :role).sort_by { _1.aircraft.tail_number } %>
|
||||||
|
<% if memberships.any? %>
|
||||||
|
<table class="table">
|
||||||
|
<tbody>
|
||||||
|
<% memberships.each do |m| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= link_to m.aircraft.tail_number, aircraft_path(m.aircraft), class: "link font-medium" %> <span class="text-xs text-slate-500"><%= [ m.aircraft.make, m.aircraft.model ].compact_blank.join(" ") %></span></td>
|
||||||
|
<td><%= form_with url: admin_user_aircraft_role_path(@user, m), method: :patch do |f| %>
|
||||||
|
<%= f.select :role_id, roles.map { [ _1.name, _1.id ] }, { selected: m.role_id }, class: "input w-36", "aria-label": t(".role_on", tail_number: m.aircraft.tail_number), data: { submit_on_change: true } %>
|
||||||
|
<% end %></td>
|
||||||
|
<td class="text-right"><%= delete_button t(".remove"), admin_user_aircraft_role_path(@user, m), confirm: t(".remove_access", tail_number: m.aircraft.tail_number) %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% else %>
|
||||||
|
<%= empty_state t(".no_aircraft") %>
|
||||||
|
<% end %>
|
||||||
|
<% others = Aircraft.where.not(id: memberships.map(&:aircraft_id)).ordered %>
|
||||||
|
<% if others.any? %>
|
||||||
|
<%= form_with url: admin_user_aircraft_roles_path(@user), class: "flex flex-wrap items-end gap-2 border-t border-slate-100 p-4" do |f| %>
|
||||||
|
<div><%= f.label :aircraft_id, t(".aircraft"), class: "label" %><%= f.select :aircraft_id, others.map { [ _1.tail_number, _1.id ] }, {}, class: "input" %></div>
|
||||||
|
<div><%= f.label :role_id, t(".role"), class: "label" %><%= f.select :role_id, roles.map { [ _1.name, _1.id ] }, { selected: Role.for_key("pilot").id }, class: "input w-36" %></div>
|
||||||
|
<%= f.submit t(".add"), class: "btn-primary" %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<p class="hint px-4 pb-4"><%= t(".roles_hint_html", link: link_to(t(".roles"), admin_roles_path, class: "link")) %></p>
|
||||||
|
</section>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<tbody><% @users.each do |u| %><tr>
|
<tbody><% @users.each do |u| %><tr>
|
||||||
<td><%= u.name %> <% if u.admin? %><span class="badge-blue"><%= t(".admin") %></span><% end %><% if u.sso_uid? %> <span class="badge-gray" title="Signs in with <%= Sso.label %>"><%= Sso.label %></span><% end %><% if u.otp_enabled? %> <span class="badge-green" title="<%= t(".authenticator_app_on") %>"><%= t(".n2fa") %></span><% end %><% if u.locked? %> <span class="badge-red" title="<%= t(".too_many_failed_sign_ins") %>"><%= t(".locked") %></span><% end %></td>
|
<td><%= u.name %> <% if u.admin? %><span class="badge-blue"><%= t(".admin") %></span><% end %><% if u.sso_uid? %> <span class="badge-gray" title="Signs in with <%= Sso.label %>"><%= Sso.label %></span><% end %><% if u.otp_enabled? %> <span class="badge-green" title="<%= t(".authenticator_app_on") %>"><%= t(".n2fa") %></span><% end %><% if u.locked? %> <span class="badge-red" title="<%= t(".too_many_failed_sign_ins") %>"><%= t(".locked") %></span><% end %></td>
|
||||||
<td><%= u.email_address %><% if u.certificates.any? %><div class="text-xs text-slate-500"><%= u.certificates.map { "#{_1.short_label} #{_1.number}" }.join(", ") %></div><% end %></td>
|
<td><%= u.email_address %><% if u.certificates.any? %><div class="text-xs text-slate-500"><%= u.certificates.map { "#{_1.short_label} #{_1.number}" }.join(", ") %></div><% end %></td>
|
||||||
<td class="text-xs"><%= u.aircraft_roles.map { "#{_1.aircraft.tail_number} (#{_1.role})" }.join(", ").presence || "—" %></td>
|
<td class="text-xs"><%= u.aircraft_roles.map { "#{_1.aircraft.tail_number} (#{_1.role.name})" }.join(", ").presence || "—" %></td>
|
||||||
<td class="text-xs text-slate-500"><%= u.last_signed_in_at ? "#{time_ago_in_words(u.last_signed_in_at)} ago" : "never" %></td>
|
<td class="text-xs text-slate-500"><%= u.last_signed_in_at ? "#{time_ago_in_words(u.last_signed_in_at)} ago" : "never" %></td>
|
||||||
<td class="whitespace-nowrap text-right">
|
<td class="whitespace-nowrap text-right">
|
||||||
<% if u.disabled? %><span class="badge-red mr-1"><%= t(".disabled") %></span><%= button_to t(".enable"), enable_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline" } %>
|
<% if u.disabled? %><span class="badge-red mr-1"><%= t(".disabled") %></span><%= button_to t(".enable"), enable_admin_user_path(u), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline" } %>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<div class="grid gap-5 lg:grid-cols-3">
|
<div class="grid gap-5 lg:grid-cols-3">
|
||||||
<div class="space-y-5 lg:col-span-2">
|
<div class="space-y-5 lg:col-span-2">
|
||||||
<% if owner? %><%= render "aircraft/setup", aircraft: @aircraft %><% end %>
|
<% if can?(:edit_aircraft) %><%= render "aircraft/setup", aircraft: @aircraft %><% end %>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= t(".airworthiness") %></h2>
|
<h2 class="card-title"><%= t(".airworthiness") %></h2>
|
||||||
@@ -58,6 +58,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-5">
|
<div class="space-y-5">
|
||||||
|
<% if can?(:update_hours) %>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header"><h2 class="card-title"><%= t(".update_hours") %></h2></div>
|
<div class="card-header"><h2 class="card-title"><%= t(".update_hours") %></h2></div>
|
||||||
<%= form_with url: hours_aircraft_path(@aircraft), method: :patch, class: "card-body space-y-3",
|
<%= form_with url: hours_aircraft_path(@aircraft), method: :patch, class: "card-body space-y-3",
|
||||||
@@ -69,17 +70,18 @@
|
|||||||
<div><%= f.label :hobbs_time, t(".hobbs"), class: "label" %>
|
<div><%= f.label :hobbs_time, t(".hobbs"), class: "label" %>
|
||||||
<%= f.number_field :hobbs_time, value: @aircraft.hobbs_time, step: 0.1, class: "input", data: { hours_confirm_target: "hobbs" } %></div>
|
<%= f.number_field :hobbs_time, value: @aircraft.hobbs_time, step: 0.1, class: "input", data: { hours_confirm_target: "hobbs" } %></div>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint"><%= t(".enter_the_current_meter_readings_html", link: (link_to t(".log_flight"), new_aircraft_flight_log_path(@aircraft), class: "link")) %></p>
|
<p class="hint"><%= can?(:log_flights) ? t(".enter_the_current_meter_readings_html", link: (link_to t(".log_flight"), new_aircraft_flight_log_path(@aircraft), class: "link")) : t(".enter_the_current_meter_readings") %></p>
|
||||||
<%= f.submit t(".update_hours"), class: "btn-primary" %>
|
<%= f.submit t(".update_hours"), class: "btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= render "aircraft/last_flight", aircraft: @aircraft, last_day: @last_day %>
|
<%= render "aircraft/last_flight", aircraft: @aircraft, last_day: @last_day %>
|
||||||
|
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= t(".details") %></h2>
|
<h2 class="card-title"><%= t(".details") %></h2>
|
||||||
<% if owner? %><%= link_to t(".edit"), edit_aircraft_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:edit_aircraft) %><%= link_to t(".edit"), edit_aircraft_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
<dl class="card-body grid grid-cols-2 gap-x-3 gap-y-2 text-sm">
|
<dl class="card-body grid grid-cols-2 gap-x-3 gap-y-2 text-sm">
|
||||||
<dt class="text-slate-500"><%= t(".serial") %></dt><dd><%= @aircraft.serial_number.presence || "—" %></dd>
|
<dt class="text-slate-500"><%= t(".serial") %></dt><dd><%= @aircraft.serial_number.presence || "—" %></dd>
|
||||||
@@ -94,7 +96,7 @@
|
|||||||
|
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header"><h2 class="card-title"><%= t(".notes") %></h2>
|
<div class="card-header"><h2 class="card-title"><%= t(".notes") %></h2>
|
||||||
<%= link_to t(".add"), new_aircraft_note_path(@aircraft), class: "btn-secondary btn-sm" %></div>
|
<% if can?(:write_notes) %><%= link_to t(".add"), new_aircraft_note_path(@aircraft), class: "btn-secondary btn-sm" %><% end %></div>
|
||||||
<% if @notes.any? %>
|
<% if @notes.any? %>
|
||||||
<ul class="divide-y divide-slate-100">
|
<ul class="divide-y divide-slate-100">
|
||||||
<% @notes.each do |note| %>
|
<% @notes.each do |note| %>
|
||||||
|
|||||||
@@ -2,31 +2,45 @@
|
|||||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||||
<h2 class="mb-4 text-lg font-semibold"><%= t(".access_sharing_html") %></h2>
|
<h2 class="mb-4 text-lg font-semibold"><%= t(".access_sharing_html") %></h2>
|
||||||
<div class="grid gap-5 lg:grid-cols-2">
|
<div class="grid gap-5 lg:grid-cols-2">
|
||||||
|
<% if can?(:manage_people) %>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header"><h2 class="card-title"><%= t(".people") %></h2></div>
|
<div class="card-header"><h2 class="card-title"><%= t(".people") %></h2></div>
|
||||||
|
<% roles = @access.assignable_roles %>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @roles.each do |r| %>
|
<% @roles.each do |r| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= r.user.display_name %><div class="text-xs text-slate-500"><%= r.user.email_address %></div></td>
|
<td><%= r.user.display_name %><div class="text-xs text-slate-500"><%= r.user.email_address %></div></td>
|
||||||
<td>
|
<td>
|
||||||
<%= form_with url: aircraft_aircraft_role_path(@aircraft, r), method: :patch do |f| %>
|
<% if roles.include?(r.role) && (r.user != current_user || current_user.admin?) %>
|
||||||
<%= f.select :role, AircraftRole::ROLES.invert, { selected: r.role }, class: "input w-28", data: { submit_on_change: true } %>
|
<%= form_with url: aircraft_aircraft_role_path(@aircraft, r), method: :patch do |f| %>
|
||||||
|
<%= f.select :role_id, roles.map { [ _1.name, _1.id ] }, { selected: r.role_id }, class: "input w-36", "aria-label": t(".role_for", display_name: r.user.display_name), data: { submit_on_change: true } %>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<span class="badge-gray" title="<%= r.role.description %>"><%= r.role.name %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right"><% unless r.user == current_user %><%= delete_button t(".remove"), aircraft_aircraft_role_path(@aircraft, r), confirm: t(".remove_s_access", display_name: r.user.display_name) %><% end %></td>
|
<td class="text-right"><% if r.user != current_user && roles.include?(r.role) %><%= delete_button t(".remove"), aircraft_aircraft_role_path(@aircraft, r), confirm: t(".remove_s_access", display_name: r.user.display_name) %><% end %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<%= form_with url: aircraft_aircraft_roles_path(@aircraft), class: "flex flex-wrap items-end gap-2 border-t border-slate-100 p-4" do |f| %>
|
<%= form_with url: aircraft_aircraft_roles_path(@aircraft), class: "flex flex-wrap items-end gap-2 border-t border-slate-100 p-4" do |f| %>
|
||||||
<div class="flex-1"><%= f.label :email_address, t(".add_by_email"), class: "label" %><%= f.email_field :email_address, class: "input", required: true %></div>
|
<div class="w-full sm:w-auto sm:flex-1"><%= f.label :email_address, t(".add_by_email"), class: "label" %><%= f.email_field :email_address, class: "input", required: true %></div>
|
||||||
<%= f.select :role, AircraftRole::ROLES.invert, { selected: "pilot" }, class: "input w-28" %>
|
<%= f.select :role_id, roles.map { [ _1.name, _1.id ] }, { selected: Role.for_key("pilot").id }, class: "input w-36", "aria-label": t(".role") %>
|
||||||
<%= f.submit t(".add"), class: "btn-primary" %>
|
<%= f.submit t(".add"), class: "btn-primary" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<p class="px-4 pb-4 hint"><%= t(".owners_can_edit_everything_pilots_html") %></p>
|
<details class="px-4 pb-4 text-sm">
|
||||||
|
<summary class="cursor-pointer text-slate-600"><%= t(".what_each_role_can_do") %></summary>
|
||||||
|
<dl class="mt-2 space-y-1">
|
||||||
|
<% Role.ordered.each do |role| %><div><dt class="inline font-semibold"><%= role.name %>:</dt> <dd class="inline text-slate-600"><%= role.description.presence || role.permissions.map { Permission.label(_1) }.to_sentence %></dd></div><% end %>
|
||||||
|
</dl>
|
||||||
|
<p class="hint mt-2"><%= t(".roles_are_set_by_an_administrator") %></p>
|
||||||
|
</details>
|
||||||
</section>
|
</section>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if can?(:manage_sharing) %>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header"><h2 class="card-title"><%= t(".share_links") %></h2></div>
|
<div class="card-header"><h2 class="card-title"><%= t(".share_links") %></h2></div>
|
||||||
<% if @share_tokens.any? %>
|
<% if @share_tokens.any? %>
|
||||||
@@ -59,7 +73,9 @@
|
|||||||
<%= f.submit t(".create_share_link") %>
|
<%= f.submit t(".create_share_link") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if can?(:export_data) %>
|
||||||
<section class="card lg:col-span-2">
|
<section class="card lg:col-span-2">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div>
|
<div>
|
||||||
@@ -76,4 +92,5 @@
|
|||||||
<%= link_to t(".download_records_package"), aircraft_records_package_path(@aircraft), class: "btn-secondary", data: { turbo: false } %>
|
<%= link_to t(".download_records_package"), aircraft_records_package_path(@aircraft), class: "btn-secondary", data: { turbo: false } %>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= t(".airworthiness_directives_bulletins") %></h2>
|
<h2 class="card-title"><%= t(".airworthiness_directives_bulletins") %></h2>
|
||||||
<% if owner? %>
|
<% if can?(:manage_ads) %>
|
||||||
<div class="flex flex-wrap items-center gap-2">
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
<% if @attachable.any? %>
|
<% if @attachable.any? %>
|
||||||
<%= form_with url: attach_aircraft_airworthiness_directives_path(@aircraft), class: "flex gap-2" do |f| %>
|
<%= form_with url: attach_aircraft_airworthiness_directives_path(@aircraft), class: "flex gap-2" do |f| %>
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
<td class="text-xs"><%= [row.next_due_date && l(row.next_due_date, format: :month_year), row.next_due_hours && t(".due_hours", hours: hours(row.next_due_hours), meter: Aircraft::TIME_BASES[@aircraft.time_basis].downcase, left: hours(row.next_due_hours - @aircraft.current_hours))].compact.join(" / ").presence || "—" %></td>
|
<td class="text-xs"><%= [row.next_due_date && l(row.next_due_date, format: :month_year), row.next_due_hours && t(".due_hours", hours: hours(row.next_due_hours), meter: Aircraft::TIME_BASES[@aircraft.time_basis].downcase, left: hours(row.next_due_hours - @aircraft.current_hours))].compact.join(" / ").presence || "—" %></td>
|
||||||
<td><%= compliance_badge(row.status) %></td>
|
<td><%= compliance_badge(row.status) %></td>
|
||||||
<td class="whitespace-nowrap text-right">
|
<td class="whitespace-nowrap text-right">
|
||||||
<% if owner? %>
|
<% if can?(:manage_ads) %>
|
||||||
<%= link_to t(".comply"), new_aircraft_ad_compliance_path(@aircraft, ad_id: ad.id), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".comply"), new_aircraft_ad_compliance_path(@aircraft, ad_id: ad.id), class: "btn-secondary btn-sm" %>
|
||||||
<% if row.status.in?(%w[no_compliance overdue due_soon conditional]) %><%= link_to "N/A", new_aircraft_ad_compliance_path(@aircraft, ad_id: ad.id, not_applicable: 1), class: "btn-secondary btn-sm", title: t(".record_that_this_ad_doesn") %><% end %>
|
<% if row.status.in?(%w[no_compliance overdue due_soon conditional]) %><%= link_to "N/A", new_aircraft_ad_compliance_path(@aircraft, ad_id: ad.id, not_applicable: 1), class: "btn-secondary btn-sm", title: t(".record_that_this_ad_doesn") %><% end %>
|
||||||
<%= link_to t(".edit"), edit_aircraft_airworthiness_directive_path(@aircraft, ad), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".edit"), edit_aircraft_airworthiness_directive_path(@aircraft, ad), class: "btn-secondary btn-sm" %>
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
<h2 class="card-title"><%= t(".ad_baseline_from_faa_drs") %></h2>
|
<h2 class="card-title"><%= t(".ad_baseline_from_faa_drs") %></h2>
|
||||||
<p class="text-xs text-slate-500"><%= t(".the_full_list_comes_from") %></p>
|
<p class="text-xs text-slate-500"><%= t(".the_full_list_comes_from") %></p>
|
||||||
</div>
|
</div>
|
||||||
<% if owner? %><%= link_to t(".import_from_faa_drs"), new_aircraft_ad_import_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:manage_ads) %><%= link_to t(".import_from_faa_drs"), new_aircraft_ad_import_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body space-y-2 text-sm">
|
<div class="card-body space-y-2 text-sm">
|
||||||
<% if last_drs %>
|
<% if last_drs %>
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
<h2 class="card-title"><%= t(".newly_published_ads_that_may") %></h2>
|
<h2 class="card-title"><%= t(".newly_published_ads_that_may") %></h2>
|
||||||
<p class="text-xs text-slate-500"><%= t(".searched_weekly_in_the_federal_html", components: (AdWatch.new(@aircraft).terms.map(&:label).uniq.to_sentence.presence || t(".the_aircraft_and_its_installed")), ad_watch_checked_at: (t(".last_checked_ago", ad_watch_checked_at: (time_ago_in_words(@aircraft.ad_watch_checked_at))) if @aircraft.ad_watch_checked_at)) %></p>
|
<p class="text-xs text-slate-500"><%= t(".searched_weekly_in_the_federal_html", components: (AdWatch.new(@aircraft).terms.map(&:label).uniq.to_sentence.presence || t(".the_aircraft_and_its_installed")), ad_watch_checked_at: (t(".last_checked_ago", ad_watch_checked_at: (time_ago_in_words(@aircraft.ad_watch_checked_at))) if @aircraft.ad_watch_checked_at)) %></p>
|
||||||
</div>
|
</div>
|
||||||
<% if owner? %><%= button_to t(".check_now"), check_aircraft_ad_alerts_path(@aircraft), class: "btn-secondary btn-sm", data: { turbo_submits_with: t(".checking") } %><% end %>
|
<% if can?(:manage_ads) %><%= button_to t(".check_now"), check_aircraft_ad_alerts_path(@aircraft), class: "btn-secondary btn-sm", data: { turbo_submits_with: t(".checking") } %><% end %>
|
||||||
</div>
|
</div>
|
||||||
<% if @alerts.any? %>
|
<% if @alerts.any? %>
|
||||||
<ul class="divide-y divide-slate-100">
|
<ul class="divide-y divide-slate-100">
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
<p class="mt-1 text-xs text-slate-600"><%= alert.abstract.to_s.truncate(400) %></p>
|
<p class="mt-1 text-xs text-slate-600"><%= alert.abstract.to_s.truncate(400) %></p>
|
||||||
<%= link_to t(".read_it_in_the_federal"), alert.html_url, class: "link text-xs", target: "_blank", rel: "noopener" %>
|
<%= link_to t(".read_it_in_the_federal"), alert.html_url, class: "link text-xs", target: "_blank", rel: "noopener" %>
|
||||||
</div>
|
</div>
|
||||||
<% if owner? %>
|
<% if can?(:manage_ads) %>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<%= button_to t(".track"), track_aircraft_ad_alert_path(@aircraft, alert), class: "btn-primary btn-sm", title: t(".add_it_to_this_aircraft") %>
|
<%= button_to t(".track"), track_aircraft_ad_alert_path(@aircraft, alert), class: "btn-primary btn-sm", title: t(".add_it_to_this_aircraft") %>
|
||||||
<%= button_to t(".dismiss"), dismiss_aircraft_ad_alert_path(@aircraft, alert), class: "btn-secondary btn-sm", title: t(".doesn_t_apply") %>
|
<%= button_to t(".dismiss"), dismiss_aircraft_ad_alert_path(@aircraft, alert), class: "btn-secondary btn-sm", title: t(".doesn_t_apply") %>
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
<% else %>
|
<% else %>
|
||||||
<%= empty_state t(".nothing_new_to_review") %>
|
<%= empty_state t(".nothing_new_to_review") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if owner? %>
|
<% if can?(:manage_ads) %>
|
||||||
<%= form_with url: terms_aircraft_ad_alerts_path(@aircraft), method: :patch, class: "flex flex-wrap items-end gap-2 border-t border-slate-100 px-4 py-3" do %>
|
<%= form_with url: terms_aircraft_ad_alerts_path(@aircraft), method: :patch, class: "flex flex-wrap items-end gap-2 border-t border-slate-100 px-4 py-3" do %>
|
||||||
<div class="min-w-0 flex-1">
|
<div class="min-w-0 flex-1">
|
||||||
<%= label_tag :ad_watch_terms, t(".additional_search_terms"), class: "label" %>
|
<%= label_tag :ad_watch_terms, t(".additional_search_terms"), class: "label" %>
|
||||||
@@ -140,7 +140,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right"><% if owner? %><%= link_to t(".edit"), edit_aircraft_ad_compliance_path(@aircraft, c), class: "btn-secondary btn-sm" %><% end %></td>
|
<td class="text-right"><% if can?(:manage_ads) %><%= link_to t(".edit"), edit_aircraft_ad_compliance_path(@aircraft, c), class: "btn-secondary btn-sm" %><% end %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
<%= link_to (@show_disposed ? t(".hide_disposed") : t(".show_disposed")),
|
<%= link_to (@show_disposed ? t(".hide_disposed") : t(".show_disposed")),
|
||||||
aircraft_components_path(@aircraft, disposed: (@show_disposed ? nil : 1)), class: "link text-sm" %>
|
aircraft_components_path(@aircraft, disposed: (@show_disposed ? nil : 1)), class: "link text-sm" %>
|
||||||
<% if owner? %><%= link_to t(".add_component"), new_aircraft_component_path(@aircraft), class: "btn-primary" %><% end %>
|
<% if can?(:manage_components) %><%= link_to t(".add_component"), new_aircraft_component_path(@aircraft), class: "btn-primary" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% if @rows.empty? %>
|
<% if @rows.empty? %>
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td><%= life_badge(c.life_status) %></td>
|
<td><%= life_badge(c.life_status) %></td>
|
||||||
<td class="whitespace-nowrap text-right">
|
<td class="whitespace-nowrap text-right">
|
||||||
<% if owner? %>
|
<% if can?(:manage_components) %>
|
||||||
<%= link_to t(".edit"), edit_aircraft_component_path(@aircraft, c), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".edit"), edit_aircraft_component_path(@aircraft, c), class: "btn-secondary btn-sm" %>
|
||||||
<%= link_to t(".service"), aircraft_component_path(@aircraft, c, anchor: "service"), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".service"), aircraft_component_path(@aircraft, c, anchor: "service"), class: "btn-secondary btn-sm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<section class="card lg:col-span-2">
|
<section class="card lg:col-span-2">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= @component %> <%= life_badge(@component.life_status) %></h2>
|
<h2 class="card-title"><%= @component %> <%= life_badge(@component.life_status) %></h2>
|
||||||
<% if owner? %>
|
<% if can?(:manage_components) %>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<%= link_to t(".sub_component"), new_aircraft_component_path(@aircraft, parent_id: @component.id), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".sub_component"), new_aircraft_component_path(@aircraft, parent_id: @component.id), class: "btn-secondary btn-sm" %>
|
||||||
<%= link_to t(".edit"), edit_aircraft_component_path(@aircraft, @component), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".edit"), edit_aircraft_component_path(@aircraft, @component), class: "btn-secondary btn-sm" %>
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
<% if @component.notes.present? %><div class="border-t border-slate-100 px-4 py-3 text-sm"><%= simple_format @component.notes %></div><% end %>
|
<% if @component.notes.present? %><div class="border-t border-slate-100 px-4 py-3 text-sm"><%= simple_format @component.notes %></div><% end %>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<% if owner? %>
|
<% if can?(:manage_components) %>
|
||||||
<section class="card" id="service">
|
<section class="card" id="service">
|
||||||
<div class="card-header"><h2 class="card-title"><%= t(".service_replace") %></h2></div>
|
<div class="card-header"><h2 class="card-title"><%= t(".service_replace") %></h2></div>
|
||||||
<%= form_with url: reset_service_aircraft_component_path(@aircraft, @component), method: :post, class: "card-body space-y-3",
|
<%= form_with url: reset_service_aircraft_component_path(@aircraft, @component), method: :post, class: "card-body space-y-3",
|
||||||
@@ -53,11 +53,11 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if @inspection_rows.any? || owner? %>
|
<% if @inspection_rows.any? || can?(:manage_inspections) %>
|
||||||
<section class="card mt-5" id="inspections">
|
<section class="card mt-5" id="inspections">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= t(".inspections_of_this_component") %></h2>
|
<h2 class="card-title"><%= t(".inspections_of_this_component") %></h2>
|
||||||
<% if owner? %><%= link_to t(".inspection"), new_aircraft_inspection_type_path(@aircraft, component_id: @component.id), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:manage_inspections) %><%= link_to t(".inspection"), new_aircraft_inspection_type_path(@aircraft, component_id: @component.id), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
<% if @inspection_rows.any? %>
|
<% if @inspection_rows.any? %>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<td class="truncate" data-label="Product"><%= r.consumable_type %></td>
|
<td class="truncate" data-label="Product"><%= r.consumable_type %></td>
|
||||||
<td class="text-right tabular-nums" data-label="Tach"><%= hours(r.flight_hours) %></td>
|
<td class="text-right tabular-nums" data-label="Tach"><%= hours(r.flight_hours) %></td>
|
||||||
<td class="text-xs text-slate-500 break-words"><%= r.notes %><%= t(".excluded_from_average") if r.excluded_from_averages? %></td>
|
<td class="text-xs text-slate-500 break-words"><%= r.notes %><%= t(".excluded_from_average") if r.excluded_from_averages? %></td>
|
||||||
<td class="text-right"><% if owner? %><%= link_to t(".edit"), edit_aircraft_consumable_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %></td>
|
<td class="text-right"><% if can?(:manage_consumables) %><%= link_to t(".edit"), edit_aircraft_consumable_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= stats.oil? ? t(".oil_consumption") : t(".fuel_burn") %></h2>
|
<h2 class="card-title"><%= stats.oil? ? t(".oil_consumption") : t(".fuel_burn") %></h2>
|
||||||
<%= link_to t(stats.oil? ? ".add_oil" : ".add_fuel"), new_aircraft_consumable_record_path(@aircraft, type: stats.record_type), class: "btn-secondary btn-sm" %>
|
<% if can?(:record_consumables) %><%= link_to t(stats.oil? ? ".add_oil" : ".add_fuel"), new_aircraft_consumable_record_path(@aircraft, type: stats.record_type), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="mb-3 flex flex-wrap gap-x-6 gap-y-1 text-sm">
|
<div class="mb-3 flex flex-wrap gap-x-6 gap-y-1 text-sm">
|
||||||
|
|||||||
@@ -8,6 +8,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<%= visibility_badge(doc.effective_visibility) %>
|
<%= visibility_badge(doc.effective_visibility) %>
|
||||||
<% if owner? %><%= link_to t(".edit"), edit_aircraft_document_path(aircraft, doc), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:manage_documents) %><%= link_to t(".edit"), edit_aircraft_document_path(aircraft, doc), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<% content_for :title, t(".documents", tail_number: @aircraft.tail_number) %>
|
<% content_for :title, t(".documents", tail_number: @aircraft.tail_number) %>
|
||||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||||
<div class="mb-4 flex flex-wrap justify-end gap-2">
|
<div class="mb-4 flex flex-wrap justify-end gap-2">
|
||||||
<% if owner? %>
|
<% if can?(:manage_documents) %>
|
||||||
<%= more_menu do %>
|
<%= more_menu do %>
|
||||||
<%= link_to t(".upload_several_files"), new_bulk_aircraft_documents_path(@aircraft), class: "menu-item" %>
|
<%= link_to t(".upload_several_files"), new_bulk_aircraft_documents_path(@aircraft), class: "menu-item" %>
|
||||||
<%= link_to t(".new_collection"), new_aircraft_document_collection_path(@aircraft), class: "menu-item" %>
|
<%= link_to t(".new_collection"), new_aircraft_document_collection_path(@aircraft), class: "menu-item" %>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<%= visibility_badge(col.visibility) %>
|
<%= visibility_badge(col.visibility) %>
|
||||||
<% if owner? %>
|
<% if can?(:manage_documents) %>
|
||||||
<%= link_to t(".document"), new_aircraft_document_path(@aircraft, collection_id: col.id), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".document"), new_aircraft_document_path(@aircraft, collection_id: col.id), class: "btn-secondary btn-sm" %>
|
||||||
<%= link_to t(".edit"), edit_aircraft_document_collection_path(@aircraft, col), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".edit"), edit_aircraft_document_collection_path(@aircraft, col), class: "btn-secondary btn-sm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<%= visibility_badge(@document.effective_visibility) %>
|
<%= visibility_badge(@document.effective_visibility) %>
|
||||||
<% if owner? %><%= link_to t(".edit"), edit_aircraft_document_path(@aircraft, @document), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:manage_documents) %><%= link_to t(".edit"), edit_aircraft_document_path(@aircraft, @document), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= t(".flight_log") %></h2>
|
<h2 class="card-title"><%= t(".flight_log") %></h2>
|
||||||
<%= more_menu do %>
|
<%= more_menu do %>
|
||||||
<% if owner? %><%= link_to t(".import_from_spreadsheet"), new_aircraft_flight_import_path(@aircraft), class: "menu-item" %><% end %>
|
<% if can?(:import_flights) %><%= link_to t(".import_from_spreadsheet"), new_aircraft_flight_import_path(@aircraft), class: "menu-item" %><% end %>
|
||||||
<%= link_to t(".export_for_airtrail"), new_aircraft_air_trail_export_path(@aircraft), class: "menu-item" %>
|
<% if can?(:log_flights) %><%= link_to t(".export_for_airtrail"), new_aircraft_air_trail_export_path(@aircraft), class: "menu-item" %><% end %>
|
||||||
<% if owner? %><%= link_to t(".standardize_airport_codes"), aircraft_airport_codes_path(@aircraft), class: "menu-item" %><% end %>
|
<% if can?(:edit_any_flight) %><%= link_to t(".standardize_airport_codes"), aircraft_airport_codes_path(@aircraft), class: "menu-item" %><% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% if @days.any? %>
|
<% if @days.any? %>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<div class="card-header"><h2 class="card-title"><%= t(".flight_on_html", date: (fmt_date(@flight_log.date))) %></h2>
|
<div class="card-header"><h2 class="card-title"><%= t(".flight_on_html", date: (fmt_date(@flight_log.date))) %></h2>
|
||||||
<div class="flex flex-wrap gap-2">
|
<div class="flex flex-wrap gap-2">
|
||||||
<% if can_edit_flight?(@flight_log) %><%= link_to t(".edit"), edit_aircraft_flight_log_path(@aircraft, @flight_log), class: "btn-secondary btn-sm" %><% end %>
|
<% if can_edit_flight?(@flight_log) %><%= link_to t(".edit"), edit_aircraft_flight_log_path(@aircraft, @flight_log), class: "btn-secondary btn-sm" %><% end %>
|
||||||
<% if owner? %><%= delete_button t(".delete"), aircraft_flight_log_path(@aircraft, @flight_log), confirm: t(".delete_this_flight_log_aircraft") %><% end %>
|
<% if can?(:delete_flights) %><%= delete_button t(".delete"), aircraft_flight_log_path(@aircraft, @flight_log), confirm: t(".delete_this_flight_log_aircraft") %><% end %>
|
||||||
</div></div>
|
</div></div>
|
||||||
<%# One item per row on a phone (label, then value); two columns on wider screens. %>
|
<%# One item per row on a phone (label, then value); two columns on wider screens. %>
|
||||||
<dl class="card-body grid gap-x-8 gap-y-3 text-sm sm:grid-cols-2">
|
<dl class="card-body grid gap-x-8 gap-y-3 text-sm sm:grid-cols-2">
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header"><h2 class="card-title"><%= t(".inspection_status") %></h2>
|
<div class="card-header"><h2 class="card-title"><%= t(".inspection_status") %></h2>
|
||||||
<% if owner? %><div class="flex flex-wrap gap-2"><%= more_menu do %><%= link_to t(".add_standard_inspections"), new_aircraft_standard_inspections_path(@aircraft), class: "menu-item" %><% end %><%= link_to t(".inspection_type"), new_aircraft_inspection_type_path(@aircraft), class: "btn-primary" %></div><% end %></div>
|
<% if can?(:manage_inspections) %><div class="flex flex-wrap gap-2"><%= more_menu do %><%= link_to t(".add_standard_inspections"), new_aircraft_standard_inspections_path(@aircraft), class: "menu-item" %><% end %><%= link_to t(".inspection_type"), new_aircraft_inspection_type_path(@aircraft), class: "btn-primary" %></div><% end %></div>
|
||||||
<% if @rows.any? %>
|
<% if @rows.any? %>
|
||||||
<div class="overflow-x-auto">
|
<div class="overflow-x-auto">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<td class="text-xs"><%= [row.next_due_date&.to_s, row.next_due_hours && "#{hours(row.next_due_hours)} h"].compact.join(" / ").presence || "—" %></td>
|
<td class="text-xs"><%= [row.next_due_date&.to_s, row.next_due_hours && "#{hours(row.next_due_hours)} h"].compact.join(" / ").presence || "—" %></td>
|
||||||
<td><%= compliance_badge(row.status) %></td>
|
<td><%= compliance_badge(row.status) %></td>
|
||||||
<td class="whitespace-nowrap text-right">
|
<td class="whitespace-nowrap text-right">
|
||||||
<% if owner? %>
|
<% if can?(:manage_inspections) %>
|
||||||
<%= link_to t(".record"), new_aircraft_inspection_record_path(@aircraft, inspection_type_id: row.type.id), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".record"), new_aircraft_inspection_record_path(@aircraft, inspection_type_id: row.type.id), class: "btn-secondary btn-sm" %>
|
||||||
<%= link_to t(".edit"), edit_aircraft_inspection_type_path(@aircraft, row.type), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".edit"), edit_aircraft_inspection_type_path(@aircraft, row.type), class: "btn-secondary btn-sm" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
<td><%= r.inspection_type.name %><%= " (#{r.component})" if r.component %></td>
|
<td><%= r.inspection_type.name %><%= " (#{r.component})" if r.component %></td>
|
||||||
<td class="text-right"><%= hours(r.hours_at_inspection) %></td>
|
<td class="text-right"><%= hours(r.hours_at_inspection) %></td>
|
||||||
<td class="text-xs"><%= r.notes %><% if r.logbook_entry %> <%= link_to "logbook", aircraft_logbook_entry_path(@aircraft, r.logbook_entry), class: "link" %><% end %></td>
|
<td class="text-xs"><%= r.notes %><% if r.logbook_entry %> <%= link_to "logbook", aircraft_logbook_entry_path(@aircraft, r.logbook_entry), class: "link" %><% end %></td>
|
||||||
<td class="text-right"><% if owner? %><%= link_to t(".edit"), edit_aircraft_inspection_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %></td>
|
<td class="text-right"><% if can?(:manage_inspections) %><%= link_to t(".edit"), edit_aircraft_inspection_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
<%= link_to t(".help"), help_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
<%= link_to t(".help"), help_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
||||||
<% if current_user.admin? %>
|
<% if current_user.admin? %>
|
||||||
<p class="border-t border-slate-100 px-4 pt-2 pb-1 text-xs font-semibold text-slate-500"><%= t(".admin") %></p>
|
<p class="border-t border-slate-100 px-4 pt-2 pb-1 text-xs font-semibold text-slate-500"><%= t(".admin") %></p>
|
||||||
<% [ [ t(".users"), admin_users_path ], [ t(".integrations"), admin_integrations_path ], [ t(".component_types"), admin_component_types_path ], [ t(".airports"), admin_airports_path ], [ t(".logbook_templates"), admin_logbook_templates_path ], [ t(".settings"), edit_admin_settings_path ], [ t(".off_site_backup"), admin_offsite_backup_path ], [ t(".recordkeeping_procedures"), admin_procedures_path ], [ t(".records_audits"), admin_audits_path ], [ t(".about"), admin_about_path ] ].each do |label, path| %>
|
<% [ [ t(".users"), admin_users_path ], [ t(".roles"), admin_roles_path ], [ t(".integrations"), admin_integrations_path ], [ t(".component_types"), admin_component_types_path ], [ t(".airports"), admin_airports_path ], [ t(".logbook_templates"), admin_logbook_templates_path ], [ t(".settings"), edit_admin_settings_path ], [ t(".off_site_backup"), admin_offsite_backup_path ], [ t(".recordkeeping_procedures"), admin_procedures_path ], [ t(".records_audits"), admin_audits_path ], [ t(".about"), admin_about_path ] ].each do |label, path| %>
|
||||||
<%= link_to label, path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
<%= link_to label, path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
<%= t(".admin") %> <span aria-hidden="true" class="text-xs">▾</span>
|
<%= t(".admin") %> <span aria-hidden="true" class="text-xs">▾</span>
|
||||||
</summary>
|
</summary>
|
||||||
<div class="absolute right-0 z-30 mt-2 w-48 rounded-md bg-surface py-1 text-slate-700 shadow-lg ring-1 ring-slate-200">
|
<div class="absolute right-0 z-30 mt-2 w-48 rounded-md bg-surface py-1 text-slate-700 shadow-lg ring-1 ring-slate-200">
|
||||||
<% [ [ t(".users"), admin_users_path ], [ t(".integrations"), admin_integrations_path ], [ t(".component_types"), admin_component_types_path ], [ t(".airports"), admin_airports_path ], [ t(".logbook_templates"), admin_logbook_templates_path ], [ t(".settings"), edit_admin_settings_path ], [ t(".off_site_backup"), admin_offsite_backup_path ], [ t(".recordkeeping_procedures"), admin_procedures_path ], [ t(".records_audits"), admin_audits_path ], [ t(".about"), admin_about_path ] ].each do |label, path| %>
|
<% [ [ t(".users"), admin_users_path ], [ t(".roles"), admin_roles_path ], [ t(".integrations"), admin_integrations_path ], [ t(".component_types"), admin_component_types_path ], [ t(".airports"), admin_airports_path ], [ t(".logbook_templates"), admin_logbook_templates_path ], [ t(".settings"), edit_admin_settings_path ], [ t(".off_site_backup"), admin_offsite_backup_path ], [ t(".recordkeeping_procedures"), admin_procedures_path ], [ t(".records_audits"), admin_audits_path ], [ t(".about"), admin_about_path ] ].each do |label, path| %>
|
||||||
<%= link_to label, path, class: [ "block px-4 py-2 text-sm hover:bg-slate-100", ("font-semibold text-sky-700" if current_page?(path)) ] %>
|
<%= link_to label, path, class: [ "block px-4 py-2 text-sm hover:bg-slate-100", ("font-semibold text-sky-700" if current_page?(path)) ] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,10 +13,8 @@
|
|||||||
<%= f.submit t(".filter"), class: "sr-only" %>
|
<%= f.submit t(".filter"), class: "sr-only" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if @entries.any? %><button type="submit" form="print-entries" class="btn-secondary" hidden data-needs-selection="print-entries" title="<%= t(".print_the_ticked_entries_on") %>"><%= t(".print_selected") %></button><% end %>
|
<% if @entries.any? %><button type="submit" form="print-entries" class="btn-secondary" hidden data-needs-selection="print-entries" title="<%= t(".print_the_ticked_entries_on") %>"><%= t(".print_selected") %></button><% end %>
|
||||||
<% if owner? %>
|
<% if can?(:import_records) %><%= more_menu do %><%= link_to t(".import_scans"), new_aircraft_logbook_import_path(@aircraft), class: "menu-item" %><% end %><% end %>
|
||||||
<%= more_menu do %><%= link_to t(".import_scans"), new_aircraft_logbook_import_path(@aircraft), class: "menu-item" %><% end %>
|
<% if can?(:write_logbook) %><%= link_to t(".new_entry"), new_aircraft_logbook_entry_path(@aircraft), class: "btn-primary" %><% end %>
|
||||||
<%= link_to t(".new_entry"), new_aircraft_logbook_entry_path(@aircraft), class: "btn-primary" %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% if @entries.any? %>
|
<% if @entries.any? %>
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<% if @entry.signed? %>
|
<% if @entry.signed? %>
|
||||||
<%= link_to t(".print_for_logbook"), new_aircraft_logbook_print_path(@aircraft, ids: [ @entry.id ]), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".print_for_logbook"), new_aircraft_logbook_print_path(@aircraft, ids: [ @entry.id ]), class: "btn-secondary btn-sm" %>
|
||||||
<% if owner? && !@entry.superseded? && !@entry.superseded_by %>
|
<% if can?(:write_logbook) && !@entry.superseded? && !@entry.superseded_by %>
|
||||||
<%= more_menu(small: true) do %><%= link_to t(".correct_this_entry"), new_aircraft_logbook_entry_path(@aircraft, supersedes: @entry.id), class: "menu-item" %><% end %>
|
<%= more_menu(small: true) do %><%= link_to t(".correct_this_entry"), new_aircraft_logbook_entry_path(@aircraft, supersedes: @entry.id), class: "menu-item" %><% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to t(".sign"), new_aircraft_logbook_entry_signature_path(@aircraft, @entry), class: "btn-primary btn-sm" %>
|
<% if can?(:sign_logbook) %><%= link_to t(".sign"), new_aircraft_logbook_entry_signature_path(@aircraft, @entry), class: "btn-primary btn-sm" %><% end %>
|
||||||
<% if owner? %><%= link_to t(".edit"), edit_aircraft_logbook_entry_path(@aircraft, @entry), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:write_logbook) %><%= link_to t(".edit"), edit_aircraft_logbook_entry_path(@aircraft, @entry), class: "btn-secondary btn-sm" %><% end %>
|
||||||
<%= more_menu(small: true) do %>
|
<%= more_menu(small: true) do %>
|
||||||
<% if owner? %><%= link_to t(".ask_someone_to_sign"), new_aircraft_logbook_entry_signing_invitation_path(@aircraft, @entry), class: "menu-item" %><% end %>
|
<% if can?(:write_logbook) %><%= link_to t(".ask_someone_to_sign"), new_aircraft_logbook_entry_signing_invitation_path(@aircraft, @entry), class: "menu-item" %><% end %>
|
||||||
<%= link_to t(".print_for_logbook"), new_aircraft_logbook_print_path(@aircraft, ids: [ @entry.id ]), class: "menu-item" %>
|
<%= link_to t(".print_for_logbook"), new_aircraft_logbook_print_path(@aircraft, ids: [ @entry.id ]), class: "menu-item" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<% unless @entry.verified? %>
|
<% unless @entry.verified? %>
|
||||||
<div class="flex flex-wrap items-center justify-between gap-2 rounded-md bg-amber-50 px-3 py-2 text-sm text-amber-900 ring-1 ring-amber-200">
|
<div class="flex flex-wrap items-center justify-between gap-2 rounded-md bg-amber-50 px-3 py-2 text-sm text-amber-900 ring-1 ring-amber-200">
|
||||||
<span><%= t(".transcribed_by_claude_and_not_html", transcription_confidence: (t(".confidence", transcription_confidence: @entry.transcription_confidence) if @entry.transcription_confidence), logbook: (@entry.document ? "" : t(".or_the_paper_logbook"))) %></span>
|
<span><%= t(".transcribed_by_claude_and_not_html", transcription_confidence: (t(".confidence", transcription_confidence: @entry.transcription_confidence) if @entry.transcription_confidence), logbook: (@entry.document ? "" : t(".or_the_paper_logbook"))) %></span>
|
||||||
<% if owner? %><%= button_to t(".matches_the_scan_mark_verified"), verify_aircraft_logbook_entry_path(@aircraft, @entry), method: :patch, class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:write_logbook) %><%= button_to t(".matches_the_scan_mark_verified"), verify_aircraft_logbook_entry_path(@aircraft, @entry), method: :patch, class: "btn-secondary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="flex flex-wrap gap-4 text-sm text-slate-600">
|
<div class="flex flex-wrap gap-4 text-sm text-slate-600">
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<% if (missing = @entry.missing_record_items).any? %>
|
<% if (missing = @entry.missing_record_items).any? %>
|
||||||
<p class="rounded-md bg-amber-50 px-3 py-2 text-sm text-amber-900 ring-1 ring-amber-200">
|
<p class="rounded-md bg-amber-50 px-3 py-2 text-sm text-amber-900 ring-1 ring-amber-200">
|
||||||
<%= t(".missing_for_html", entry_type: (@entry.entry_type == "INSPECTION" ? "43.11" : "43.9"), items: missing.to_sentence) %>
|
<%= t(".missing_for_html", entry_type: (@entry.entry_type == "INSPECTION" ? "43.11" : "43.9"), items: missing.to_sentence) %>
|
||||||
<%= link_to(t(".fill_in"), edit_aircraft_logbook_entry_path(@aircraft, @entry), class: "link") if owner? %>
|
<%= link_to(t(".fill_in"), edit_aircraft_logbook_entry_path(@aircraft, @entry), class: "link") if can?(:write_logbook) %>
|
||||||
<%= t(".check_against_the_signed_logbook") %>
|
<%= t(".check_against_the_signed_logbook") %>
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header"><h2 class="card-title"><%= t(".major_repairs_alterations") %></h2>
|
<div class="card-header"><h2 class="card-title"><%= t(".major_repairs_alterations") %></h2>
|
||||||
<% if owner? %><div class="flex gap-2">
|
<% if can?(:manage_major_records) %><div class="flex gap-2">
|
||||||
<%= link_to t(".repair"), new_aircraft_major_record_path(@aircraft, type: "repair"), class: "btn-secondary" %>
|
<%= link_to t(".repair"), new_aircraft_major_record_path(@aircraft, type: "repair"), class: "btn-secondary" %>
|
||||||
<%= link_to t(".alteration"), new_aircraft_major_record_path(@aircraft, type: "alteration"), class: "btn-primary" %></div><% end %></div>
|
<%= link_to t(".alteration"), new_aircraft_major_record_path(@aircraft, type: "alteration"), class: "btn-primary" %></div><% end %></div>
|
||||||
<% if @records.any? %>
|
<% if @records.any? %>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||||
<section class="card max-w-4xl">
|
<section class="card max-w-4xl">
|
||||||
<div class="card-header"><h2 class="card-title"><%= @record.type_label %>: <%= @record.title %></h2>
|
<div class="card-header"><h2 class="card-title"><%= @record.type_label %>: <%= @record.title %></h2>
|
||||||
<% if owner? %><%= link_to t(".edit"), edit_aircraft_major_record_path(@aircraft, @record), class: "btn-secondary btn-sm" %><% end %></div>
|
<% if can?(:manage_major_records) %><%= link_to t(".edit"), edit_aircraft_major_record_path(@aircraft, @record), class: "btn-secondary btn-sm" %><% end %></div>
|
||||||
<dl class="card-body grid gap-x-8 gap-y-3 text-sm sm:grid-cols-2">
|
<dl class="card-body grid gap-x-8 gap-y-3 text-sm sm:grid-cols-2">
|
||||||
<div class="detail-row"><dt><%= t(".date") %></dt><dd><%= fmt_date(@record.date_performed) %></dd></div>
|
<div class="detail-row"><dt><%= t(".date") %></dt><dd><%= fmt_date(@record.date_performed) %></dd></div>
|
||||||
<div class="detail-row"><dt><%= t(".aircraft_hours") %></dt><dd><%= hours(@record.aircraft_hours) %></dd></div>
|
<div class="detail-row"><dt><%= t(".aircraft_hours") %></dt><dd><%= hours(@record.aircraft_hours) %></dd></div>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
<dd>
|
<dd>
|
||||||
<% if (wb = @aircraft.weight_balance_records.where(major_record: @record).recent_first.first) %>
|
<% if (wb = @aircraft.weight_balance_records.where(major_record: @record).recent_first.first) %>
|
||||||
<%= link_to t(".lb_in", date: fmt_date(wb.date), weight: number_with_precision(wb.empty_weight, precision: 1), arm: number_with_precision(wb.empty_arm, precision: 2)), aircraft_weight_balance_records_path(@aircraft), class: "link" %>
|
<%= link_to t(".lb_in", date: fmt_date(wb.date), weight: number_with_precision(wb.empty_weight, precision: 1), arm: number_with_precision(wb.empty_arm, precision: 2)), aircraft_weight_balance_records_path(@aircraft), class: "link" %>
|
||||||
<% elsif owner? %>
|
<% elsif can?(:manage_major_records) %>
|
||||||
<%= link_to t(".record_the_new_w_b"), new_aircraft_weight_balance_record_path(@aircraft, major_record_id: @record.id), class: "link" %>
|
<%= link_to t(".record_the_new_w_b"), new_aircraft_weight_balance_record_path(@aircraft, major_record_id: @record.id), class: "link" %>
|
||||||
<% else %>—<% end %>
|
<% else %>—<% end %>
|
||||||
</dd></div>
|
</dd></div>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<% if (ica = @record.ica_inspection_type) %>
|
<% if (ica = @record.ica_inspection_type) %>
|
||||||
<% row = Compliance.inspection_rows(@aircraft).find { _1.type == ica } %>
|
<% row = Compliance.inspection_rows(@aircraft).find { _1.type == ica } %>
|
||||||
<%= t(".inspection_html", link: (link_to ica.name, aircraft_inspections_path(@aircraft), class: "link"), row: (compliance_badge(row.status) if row)) %>
|
<%= t(".inspection_html", link: (link_to ica.name, aircraft_inspections_path(@aircraft), class: "link"), row: (compliance_badge(row.status) if row)) %>
|
||||||
<% elsif @record.has_ica? && owner? %>
|
<% elsif @record.has_ica? && can?(:manage_major_records) %>
|
||||||
· <%= link_to t(".add_the_ica_s_recurring"), new_aircraft_inspection_type_path(@aircraft, major_record_id: @record.id), class: "link" %>
|
· <%= link_to t(".add_the_ica_s_recurring"), new_aircraft_inspection_type_path(@aircraft, major_record_id: @record.id), class: "link" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</dd></div>
|
</dd></div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<% content_for :title, t(".notes", tail_number: @aircraft.tail_number) %>
|
<% content_for :title, t(".notes", tail_number: @aircraft.tail_number) %>
|
||||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header"><h2 class="card-title"><%= t(".notes_2") %></h2><%= link_to t(".add_note"), new_aircraft_note_path(@aircraft), class: "btn-primary" %></div>
|
<div class="card-header"><h2 class="card-title"><%= t(".notes_2") %></h2><% if can?(:write_notes) %><%= link_to t(".add_note"), new_aircraft_note_path(@aircraft), class: "btn-primary" %><% end %></div>
|
||||||
<% if @notes.any? %>
|
<% if @notes.any? %>
|
||||||
<ul class="divide-y divide-slate-100">
|
<ul class="divide-y divide-slate-100">
|
||||||
<% @notes.each do |note| %>
|
<% @notes.each do |note| %>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<% if note.public? %><span class="badge-green ml-1"><%= t(".visible_on_share_links") %></span><% end %>
|
<% if note.public? %><span class="badge-green ml-1"><%= t(".visible_on_share_links") %></span><% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% if owner? %><%= link_to t(".edit"), edit_aircraft_note_path(@aircraft, note), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:manage_notes) %><%= link_to t(".edit"), edit_aircraft_note_path(@aircraft, note), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
<%= render "shared/oil_subnav", aircraft: @aircraft %>
|
<%= render "shared/oil_subnav", aircraft: @aircraft %>
|
||||||
<% recent = @analyses.first(OilAnalysesController::COMPARE_SAMPLES) %>
|
<% recent = @analyses.first(OilAnalysesController::COMPARE_SAMPLES) %>
|
||||||
<div class="space-y-5">
|
<div class="space-y-5">
|
||||||
|
<% if can?(:record_oil_analyses) %>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div>
|
<div>
|
||||||
@@ -12,11 +13,12 @@
|
|||||||
<%= render "import", aircraft: @aircraft %>
|
<%= render "import", aircraft: @aircraft %>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= t(".wear_metal_trends") %></h2>
|
<h2 class="card-title"><%= t(".wear_metal_trends") %></h2>
|
||||||
<%= link_to t(".add_oil_analysis"), new_aircraft_oil_analysis_path(@aircraft), class: "btn-secondary btn-sm" %>
|
<% if can?(:record_oil_analyses) %><%= link_to t(".add_oil_analysis"), new_aircraft_oil_analysis_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<% series = oil_trend_series(@analyses) %>
|
<% series = oil_trend_series(@analyses) %>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<% if @analysis.notes.present? %>
|
<% if @analysis.notes.present? %>
|
||||||
<div class="border-t border-slate-100 px-4 py-3 text-sm"><div class="mb-1 text-xs font-semibold text-slate-500"><%= t(".notes") %></div><%= simple_format @analysis.notes %></div>
|
<div class="border-t border-slate-100 px-4 py-3 text-sm"><div class="mb-1 text-xs font-semibold text-slate-500"><%= t(".notes") %></div><%= simple_format @analysis.notes %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if owner? %>
|
<% if can?(:manage_oil_analyses) %>
|
||||||
<div class="flex gap-2 border-t border-slate-100 px-4 py-3">
|
<div class="flex gap-2 border-t border-slate-100 px-4 py-3">
|
||||||
<%= link_to t(".edit"), edit_aircraft_oil_analysis_path(@aircraft, @analysis), class: "btn-secondary btn-sm" %>
|
<%= link_to t(".edit"), edit_aircraft_oil_analysis_path(@aircraft, @analysis), class: "btn-secondary btn-sm" %>
|
||||||
<%= delete_button t(".delete"), aircraft_oil_analysis_path(@aircraft, @analysis), confirm: t(".delete_this_oil_analysis") %>
|
<%= delete_button t(".delete"), aircraft_oil_analysis_path(@aircraft, @analysis), confirm: t(".delete_this_oil_analysis") %>
|
||||||
|
|||||||
@@ -10,5 +10,5 @@
|
|||||||
<%= select_tag :type, options_for_select([ [ t(".all_records"), "" ] ] + @types.map { [ _1.underscore.humanize, _1 ] }, @type), class: "input w-48", data: { submit_on_change: true } %>
|
<%= select_tag :type, options_for_select([ [ t(".all_records"), "" ] ] + @types.map { [ _1.underscore.humanize, _1 ] }, @type), class: "input w-48", data: { submit_on_change: true } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% if @versions.any? %><%= render "record_versions/list", versions: @versions, aircraft: @aircraft, can_restore: owner? %><% else %><%= empty_state t(".no_changes_recorded_yet") %><% end %>
|
<% if @versions.any? %><%= render "record_versions/list", versions: @versions, aircraft: @aircraft, can_restore: can?(:restore_history) %><% else %><%= empty_state t(".no_changes_recorded_yet") %><% end %>
|
||||||
</section>
|
</section>
|
||||||
@@ -14,18 +14,18 @@
|
|||||||
<%= airworthiness_badge(aw) %>
|
<%= airworthiness_badge(aw) %>
|
||||||
<%= aircraft_status_badge(aircraft) unless aircraft.status == "AVAILABLE" %>
|
<%= aircraft_status_badge(aircraft) unless aircraft.status == "AVAILABLE" %>
|
||||||
<span class="text-slate-500"><%= t(".tach_hobbs_html", tach_time: (hours(aircraft.tach_time)), hobbs_time: (hours(aircraft.hobbs_time))) %></span>
|
<span class="text-slate-500"><%= t(".tach_hobbs_html", tach_time: (hours(aircraft.tach_time)), hobbs_time: (hours(aircraft.hobbs_time))) %></span>
|
||||||
<span class="badge-gray" title="<%= t(".your_access_to_this_aircraft") %>"><%= (current_user.aircraft_roles.find_by(aircraft: aircraft)&.role || current_role).capitalize %></span>
|
<span class="badge-gray" title="<%= t(".your_access_to_this_aircraft") %>"><%= current_role&.name || t(".admin") %></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex w-full gap-2 sm:w-auto [&>a]:flex-1 [&>a]:justify-center [&>a]:whitespace-nowrap max-sm:[&>a]:px-2 sm:[&>a]:flex-none">
|
<div class="flex w-full gap-2 sm:w-auto [&>a]:flex-1 [&>a]:justify-center [&>a]:whitespace-nowrap max-sm:[&>a]:px-2 sm:[&>a]:flex-none">
|
||||||
<%= link_to t(".log_flight"), new_aircraft_flight_log_path(aircraft), class: "btn-primary" %>
|
<% if can?(:log_flights) %><%= link_to t(".log_flight"), new_aircraft_flight_log_path(aircraft), class: "btn-primary" %><% end %>
|
||||||
<%= link_to t(".report_squawk"), new_aircraft_squawk_path(aircraft), class: "btn-secondary" %>
|
<% if can?(:report_squawks) %><%= link_to t(".report_squawk"), new_aircraft_squawk_path(aircraft), class: "btn-secondary" %><% end %>
|
||||||
<%= more_menu do %>
|
<%= more_menu do %>
|
||||||
<%= link_to t(".status_report"), aircraft_report_path(aircraft), class: "menu-item" %>
|
<%= link_to t(".status_report"), aircraft_report_path(aircraft), class: "menu-item" %>
|
||||||
<% if owner? %>
|
<% if can?(:manage_people) || can?(:manage_sharing) || can?(:export_data) %><%= link_to t(".access_sharing"), aircraft_aircraft_roles_path(aircraft), class: "menu-item" %><% end %>
|
||||||
<%= link_to t(".access_sharing"), aircraft_aircraft_roles_path(aircraft), class: "menu-item" %>
|
<% if can?(:edit_aircraft) %><%= link_to t(".edit_aircraft"), edit_aircraft_path(aircraft), class: "menu-item" %><% end %>
|
||||||
<%= link_to t(".edit_aircraft"), edit_aircraft_path(aircraft), class: "menu-item" %>
|
<% if can?(:export_data) %>
|
||||||
<%= link_to t(".download_sam_zip"), aircraft_export_path(aircraft), class: "menu-item", data: { turbo: false } %>
|
<%= link_to t(".download_sam_zip"), aircraft_export_path(aircraft), class: "menu-item", data: { turbo: false } %>
|
||||||
<%= link_to t(".download_records_package"), aircraft_records_package_path(aircraft), class: "menu-item", data: { turbo: false } %>
|
<%= link_to t(".download_records_package"), aircraft_records_package_path(aircraft), class: "menu-item", data: { turbo: false } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -29,6 +29,6 @@
|
|||||||
<%= link_to t(".cancel"), aircraft_squawks_path(aircraft), class: "btn-secondary" %>
|
<%= link_to t(".cancel"), aircraft_squawks_path(aircraft), class: "btn-secondary" %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if squawk.persisted? && owner? %>
|
<% if squawk.persisted? && can?(:manage_squawks) %>
|
||||||
<div class="mt-4"><%= delete_button t(".delete_squawk"), aircraft_squawk_path(aircraft, squawk) %></div>
|
<div class="mt-4"><%= delete_button t(".delete_squawk"), aircraft_squawk_path(aircraft, squawk) %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -14,13 +14,13 @@
|
|||||||
<td><%= s.component&.to_s || "—" %></td>
|
<td><%= s.component&.to_s || "—" %></td>
|
||||||
<td class="whitespace-nowrap text-xs text-slate-500"><%= fmt_date(s.created_at.to_date) %><br><%= s.reported_by&.display_name %></td>
|
<td class="whitespace-nowrap text-xs text-slate-500"><%= fmt_date(s.created_at.to_date) %><br><%= s.reported_by&.display_name %></td>
|
||||||
<td class="whitespace-nowrap text-right">
|
<td class="whitespace-nowrap text-right">
|
||||||
<% if owner? %><%= link_to t(".resolve"), resolution_aircraft_squawk_path(aircraft, s), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:manage_squawks) %><%= link_to t(".resolve"), resolution_aircraft_squawk_path(aircraft, s), class: "btn-secondary btn-sm" %><% end %>
|
||||||
<% if s.deferred? %>
|
<% if s.deferred? %>
|
||||||
<% if owner? %><%= button_to t(".undo_deferral"), undefer_aircraft_squawk_path(aircraft, s), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline" } %><% end %>
|
<% if can?(:manage_squawks) %><%= button_to t(".undo_deferral"), undefer_aircraft_squawk_path(aircraft, s), method: :patch, class: "btn-secondary btn-sm", form: { class: "inline" } %><% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to t(".defer"), deferral_aircraft_squawk_path(aircraft, s), class: "btn-secondary btn-sm", title: t(".defer_as_inoperative_91_213") %>
|
<% if can?(:defer_squawks) %><%= link_to t(".defer"), deferral_aircraft_squawk_path(aircraft, s), class: "btn-secondary btn-sm", title: t(".defer_as_inoperative_91_213") %><% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if owner? %><%= link_to t(".edit"), edit_aircraft_squawk_path(aircraft, s), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:manage_squawks) %><%= link_to t(".edit"), edit_aircraft_squawk_path(aircraft, s), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<td><%= s.issue_reported %><%= render "squawks/attachments", squawk: s %></td>
|
<td><%= s.issue_reported %><%= render "squawks/attachments", squawk: s %></td>
|
||||||
<td class="text-xs text-slate-600"><%= s.notes %><% if s.logbook_entry %><div><%= link_to t(".logbook", date: fmt_date(s.logbook_entry.date)), aircraft_logbook_entry_path(@aircraft, s.logbook_entry), class: "link" %></div><% end %></td>
|
<td class="text-xs text-slate-600"><%= s.notes %><% if s.logbook_entry %><div><%= link_to t(".logbook", date: fmt_date(s.logbook_entry.date)), aircraft_logbook_entry_path(@aircraft, s.logbook_entry), class: "link" %></div><% end %></td>
|
||||||
<td class="text-xs text-slate-500"><%= fmt_date(s.resolved_at&.to_date) %></td>
|
<td class="text-xs text-slate-500"><%= fmt_date(s.resolved_at&.to_date) %></td>
|
||||||
<td class="text-right"><% if owner? %><%= button_to t(".reopen"), reopen_aircraft_squawk_path(@aircraft, s), method: :patch, class: "btn-secondary btn-sm" %><% end %></td>
|
<td class="text-right"><% if can?(:manage_squawks) %><%= button_to t(".reopen"), reopen_aircraft_squawk_path(@aircraft, s), method: :patch, class: "btn-secondary btn-sm" %><% end %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= t(".current_weight_balance") %></h2>
|
<h2 class="card-title"><%= t(".current_weight_balance") %></h2>
|
||||||
<% if owner? %><%= link_to t(".new_w_b"), new_aircraft_weight_balance_record_path(@aircraft), class: "btn-primary btn-sm" %><% end %>
|
<% if can?(:manage_weight_balance) %><%= link_to t(".new_w_b"), new_aircraft_weight_balance_record_path(@aircraft), class: "btn-primary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
<% if @current %>
|
<% if @current %>
|
||||||
<dl class="card-body grid grid-cols-2 gap-x-4 gap-y-2 text-sm">
|
<dl class="card-body grid grid-cols-2 gap-x-4 gap-y-2 text-sm">
|
||||||
@@ -24,14 +24,14 @@
|
|||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2 class="card-title"><%= t(".loading_calculator") %></h2>
|
<h2 class="card-title"><%= t(".loading_calculator") %></h2>
|
||||||
<% if owner? %><%= link_to t(".loading_setup"), edit_aircraft_loading_setup_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
|
<% if can?(:manage_weight_balance) %><%= link_to t(".loading_setup"), edit_aircraft_loading_setup_path(@aircraft), class: "btn-secondary btn-sm" %><% end %>
|
||||||
</div>
|
</div>
|
||||||
<% if @current && setup.configured? %>
|
<% if @current && setup.configured? %>
|
||||||
<%= render "weight_balance_records/calculator", record: @current, setup: setup %>
|
<%= render "weight_balance_records/calculator", record: @current, setup: setup %>
|
||||||
<% elsif !@current %>
|
<% elsif !@current %>
|
||||||
<%= empty_state t(".record_the_current_weight_balance") %>
|
<%= empty_state t(".record_the_current_weight_balance") %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= empty_state(owner? ? t(".set_up_the_loading_stations") : t(".an_owner_needs_to_set")) %>
|
<%= empty_state(can?(:manage_weight_balance) ? t(".set_up_the_loading_stations") : t(".an_owner_needs_to_set")) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
<td class="text-xs"><%= r.reason %>
|
<td class="text-xs"><%= r.reason %>
|
||||||
<% if r.major_record %><div><%= link_to r.major_record.title, aircraft_major_record_path(@aircraft, r.major_record), class: "link" %></div><% end %>
|
<% if r.major_record %><div><%= link_to r.major_record.title, aircraft_major_record_path(@aircraft, r.major_record), class: "link" %></div><% end %>
|
||||||
<% if r.document %><div><%= link_to "📄 #{r.document.name}", aircraft_document_path(@aircraft, r.document), class: "link" %></div><% end %></td>
|
<% if r.document %><div><%= link_to "📄 #{r.document.name}", aircraft_document_path(@aircraft, r.document), class: "link" %></div><% end %></td>
|
||||||
<td class="text-right"><% if owner? %><%= link_to t(".edit"), edit_aircraft_weight_balance_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %></td>
|
<td class="text-right"><% if can?(:manage_weight_balance) %><%= link_to t(".edit"), edit_aircraft_weight_balance_record_path(@aircraft, r), class: "btn-secondary btn-sm" %><% end %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
+173
-7
@@ -165,10 +165,6 @@ en:
|
|||||||
privileges:
|
privileges:
|
||||||
status: Current Status
|
status: Current Status
|
||||||
maintenance: Maintenance Detail
|
maintenance: Maintenance Detail
|
||||||
aircraft_role:
|
|
||||||
roles:
|
|
||||||
owner: Owner
|
|
||||||
pilot: Pilot
|
|
||||||
airport:
|
airport:
|
||||||
kinds:
|
kinds:
|
||||||
seaplane_base: seaplane base
|
seaplane_base: seaplane base
|
||||||
@@ -826,7 +822,7 @@ en:
|
|||||||
engine_data_attached: Engine data attached.
|
engine_data_attached: Engine data attached.
|
||||||
engine_data_removed: Engine data removed.
|
engine_data_removed: Engine data removed.
|
||||||
flight_log_deleted_aircraft: Flight log deleted. Aircraft hours were not changed.
|
flight_log_deleted_aircraft: Flight log deleted. Aircraft hours were not changed.
|
||||||
only_owners_or_the: Only owners or the flight's pilot can do that.
|
only_owners_or_the: Your role on this aircraft doesn't allow changing this flight.
|
||||||
flight_log_deleted: Flight log deleted
|
flight_log_deleted: Flight log deleted
|
||||||
track_unreadable: 'Couldn''t read track: %{message}'
|
track_unreadable: 'Couldn''t read track: %{message}'
|
||||||
engine_data_unreadable: 'Couldn''t read engine data: %{message}'
|
engine_data_unreadable: 'Couldn''t read engine data: %{message}'
|
||||||
@@ -1110,7 +1106,18 @@ en:
|
|||||||
one: Restored %{count} built-in template.
|
one: Restored %{count} built-in template.
|
||||||
other: Restored %{count} built-in templates.
|
other: Restored %{count} built-in templates.
|
||||||
all_present: All the built-in templates are already here.
|
all_present: All the built-in templates are already here.
|
||||||
|
admin_roles:
|
||||||
|
created: Role “%{name}” created.
|
||||||
|
updated: Role “%{name}” saved.
|
||||||
|
deleted: Role “%{name}” deleted.
|
||||||
|
built_in: Built-in roles can't be deleted.
|
||||||
|
in_use:
|
||||||
|
one: "“%{name}” is still given to 1 person; give them another role first."
|
||||||
|
other: "“%{name}” is still given to %{count} people; give them another role first."
|
||||||
admin_users:
|
admin_users:
|
||||||
|
access_added: Added to %{tail_number}.
|
||||||
|
access_changed: Role on %{tail_number} changed.
|
||||||
|
access_removed: Removed from %{tail_number}.
|
||||||
user_created: User %{email_address} created.
|
user_created: User %{email_address} created.
|
||||||
you_can_t_remove: You can't remove your own admin rights.
|
you_can_t_remove: You can't remove your own admin rights.
|
||||||
user_updated: User updated.
|
user_updated: User updated.
|
||||||
@@ -1137,7 +1144,7 @@ en:
|
|||||||
component_type_updated: Component type updated.
|
component_type_updated: Component type updated.
|
||||||
component_type_deleted: Component type deleted.
|
component_type_deleted: Component type deleted.
|
||||||
common:
|
common:
|
||||||
only_owners_can_do: Only owners can do that.
|
not_allowed: Your role on this aircraft doesn't allow that.
|
||||||
calendar_feeds:
|
calendar_feeds:
|
||||||
name: Aircraft maintenance
|
name: Aircraft maintenance
|
||||||
projected: projected from recent flying
|
projected: projected from recent flying
|
||||||
@@ -1217,6 +1224,30 @@ en:
|
|||||||
matches: Matches
|
matches: Matches
|
||||||
update: Update
|
update: Update
|
||||||
admin:
|
admin:
|
||||||
|
roles:
|
||||||
|
index:
|
||||||
|
roles: Roles
|
||||||
|
new_role: New role
|
||||||
|
intro: What people can do on an aircraft depends on their role there. Change what a role allows, or add your own (a partner, an instructor, an insurer). Everyone can see the records of the aircraft they have a role on.
|
||||||
|
name: Role
|
||||||
|
can: Can
|
||||||
|
people: People
|
||||||
|
built_in: Built in
|
||||||
|
everything: Everything, including people and sharing
|
||||||
|
view_only: View only
|
||||||
|
edit: Edit
|
||||||
|
new:
|
||||||
|
new_role: New Role
|
||||||
|
edit:
|
||||||
|
edit_role: 'Edit Role: %{name}'
|
||||||
|
form:
|
||||||
|
description_hint: Shown when choosing a role.
|
||||||
|
owner_has_everything: Owner always has every permission, so every aircraft can always be managed. Its name and description can be changed.
|
||||||
|
viewing_needs_nothing: Seeing the aircraft's records needs no permission. Signing a logbook entry also needs a current certificate on the person's profile.
|
||||||
|
save: Save
|
||||||
|
cancel: Cancel
|
||||||
|
delete_role: Delete role
|
||||||
|
delete_role_confirm: Delete the role “%{name}”?
|
||||||
integrations:
|
integrations:
|
||||||
show:
|
show:
|
||||||
revoked: Revoked
|
revoked: Revoked
|
||||||
@@ -1658,6 +1689,16 @@ en:
|
|||||||
users:
|
users:
|
||||||
edit:
|
edit:
|
||||||
edit_user: Edit User
|
edit_user: Edit User
|
||||||
|
aircraft_access: Aircraft access
|
||||||
|
role_on: Role on %{tail_number}
|
||||||
|
remove: Remove
|
||||||
|
remove_access: Remove their access to %{tail_number}?
|
||||||
|
no_aircraft: No access to any aircraft yet.
|
||||||
|
aircraft: Aircraft
|
||||||
|
role: Role
|
||||||
|
add: Add
|
||||||
|
roles: Roles
|
||||||
|
roles_hint_html: What each role can do is set under %{link}. As an administrator they can see and change every aircraft whatever their roles.
|
||||||
form:
|
form:
|
||||||
email: Email
|
email: Email
|
||||||
administrator: Administrator
|
administrator: Administrator
|
||||||
@@ -1787,6 +1828,7 @@ en:
|
|||||||
hobbs: Hobbs
|
hobbs: Hobbs
|
||||||
log_flight: Log Flight
|
log_flight: Log Flight
|
||||||
enter_the_current_meter_readings_html: Enter the current meter readings. The difference is applied to every in-service component. For a single flight, use %{link}.
|
enter_the_current_meter_readings_html: Enter the current meter readings. The difference is applied to every in-service component. For a single flight, use %{link}.
|
||||||
|
enter_the_current_meter_readings: Enter the current meter readings. The difference is applied to every in-service component.
|
||||||
details: Details
|
details: Details
|
||||||
edit: Edit
|
edit: Edit
|
||||||
serial: Serial
|
serial: Serial
|
||||||
@@ -1856,7 +1898,10 @@ en:
|
|||||||
remove: Remove
|
remove: Remove
|
||||||
add_by_email: Add by email
|
add_by_email: Add by email
|
||||||
add: Add
|
add: Add
|
||||||
owners_can_edit_everything_pilots_html: "<strong>Owners</strong> can edit everything. <strong>Pilots</strong> can view all records, log flights, update hours, and add squawks, notes and oil/fuel."
|
role_for: Role for %{display_name}
|
||||||
|
role: Role
|
||||||
|
what_each_role_can_do: What each role can do
|
||||||
|
roles_are_set_by_an_administrator: An administrator sets what each role can do, and can add roles (Admin → Roles). Only an Owner can give or take away the Owner role.
|
||||||
share_links: Share Links
|
share_links: Share Links
|
||||||
expired: Expired
|
expired: Expired
|
||||||
revoke_this_link_anyone_using: Revoke this link? Anyone using it will lose access.
|
revoke_this_link_anyone_using: Revoke this link? Anyone using it will lose access.
|
||||||
@@ -2602,6 +2647,7 @@ en:
|
|||||||
sign_out: Sign out
|
sign_out: Sign out
|
||||||
layouts:
|
layouts:
|
||||||
application:
|
application:
|
||||||
|
roles: Roles
|
||||||
integrations: Integrations
|
integrations: Integrations
|
||||||
skip_to_content_html: <a href="#main" class="skip-link">Skip to content</a>
|
skip_to_content_html: <a href="#main" class="skip-link">Skip to content</a>
|
||||||
simple_aircraft_manager: Simple Aircraft Manager
|
simple_aircraft_manager: Simple Aircraft Manager
|
||||||
@@ -3269,6 +3315,7 @@ en:
|
|||||||
create_admin_account: Create Admin Account
|
create_admin_account: Create Admin Account
|
||||||
shared:
|
shared:
|
||||||
aircraft_header:
|
aircraft_header:
|
||||||
|
admin: Admin
|
||||||
tach_hobbs_html: Tach %{tach_time} · Hobbs %{hobbs_time}
|
tach_hobbs_html: Tach %{tach_time} · Hobbs %{hobbs_time}
|
||||||
your_access_to_this_aircraft: Your access to this aircraft
|
your_access_to_this_aircraft: Your access to this aircraft
|
||||||
log_flight: Log Flight
|
log_flight: Log Flight
|
||||||
@@ -3546,6 +3593,120 @@ en:
|
|||||||
an_owner_needs_to_set: An owner needs to set up the loading stations first.
|
an_owner_needs_to_set: An owner needs to set up the loading stations first.
|
||||||
new:
|
new:
|
||||||
weight_balance: "%{tail_number} Weight & Balance"
|
weight_balance: "%{tail_number} Weight & Balance"
|
||||||
|
roles:
|
||||||
|
owner:
|
||||||
|
name: Owner
|
||||||
|
description: Everything on the aircraft, including its people and sharing.
|
||||||
|
mechanic:
|
||||||
|
name: Mechanic
|
||||||
|
description: 'Maintenance records: logbook entries, components, inspections, ADs and squawks.'
|
||||||
|
pilot:
|
||||||
|
name: Pilot
|
||||||
|
description: 'Flying: logs flights and hours, reports squawks, adds notes and oil and fuel.'
|
||||||
|
viewer:
|
||||||
|
name: Viewer
|
||||||
|
description: Sees everything on the aircraft and changes nothing.
|
||||||
|
permissions:
|
||||||
|
groups:
|
||||||
|
flying: Flying
|
||||||
|
squawks_and_notes: Squawks, notes, oil and fuel
|
||||||
|
maintenance: Maintenance records
|
||||||
|
data: Imports and exports
|
||||||
|
aircraft: The aircraft
|
||||||
|
notifications: Notifications
|
||||||
|
log_flights:
|
||||||
|
label: Log flights
|
||||||
|
description: Log Flight (also offline) and the AirTrail export.
|
||||||
|
update_hours:
|
||||||
|
label: Update hours
|
||||||
|
description: Set the tach and Hobbs readings without logging a flight.
|
||||||
|
import_flights:
|
||||||
|
label: Import flights
|
||||||
|
description: From a spreadsheet.
|
||||||
|
edit_own_flights:
|
||||||
|
label: Correct own flights
|
||||||
|
description: The flights they logged, and their engine data.
|
||||||
|
edit_any_flight:
|
||||||
|
label: Correct any flight
|
||||||
|
description: Any flight and its engine data, and standardizing airport codes.
|
||||||
|
delete_flights:
|
||||||
|
label: Delete flights
|
||||||
|
description: Deleting doesn't take the hours back off.
|
||||||
|
report_squawks:
|
||||||
|
label: Report squawks
|
||||||
|
description: Also offline, and through the API.
|
||||||
|
defer_squawks:
|
||||||
|
label: Defer squawks
|
||||||
|
description: As inoperative equipment (14 CFR 91.213).
|
||||||
|
manage_squawks:
|
||||||
|
label: Manage squawks
|
||||||
|
description: Edit, resolve, reopen and delete squawks, and undo deferrals.
|
||||||
|
write_notes:
|
||||||
|
label: Write notes
|
||||||
|
description: Add notes to the aircraft.
|
||||||
|
manage_notes:
|
||||||
|
label: Manage notes
|
||||||
|
description: Edit and delete anyone's notes.
|
||||||
|
record_consumables:
|
||||||
|
label: Record oil and fuel
|
||||||
|
description: Add oil and fuel records.
|
||||||
|
manage_consumables:
|
||||||
|
label: Manage oil and fuel
|
||||||
|
description: Edit and delete oil and fuel records.
|
||||||
|
write_logbook:
|
||||||
|
label: Write logbook entries
|
||||||
|
description: Create and edit unsigned entries, correct signed ones, ask someone to sign, and send drafts through the API.
|
||||||
|
sign_logbook:
|
||||||
|
label: Sign logbook entries
|
||||||
|
description: Also needs a current certificate on their profile.
|
||||||
|
manage_components:
|
||||||
|
label: Manage components
|
||||||
|
description: Add, edit and remove components, and record service.
|
||||||
|
manage_inspections:
|
||||||
|
label: Manage inspections
|
||||||
|
description: Inspection types and records.
|
||||||
|
manage_ads:
|
||||||
|
label: Manage ADs
|
||||||
|
description: ADs, compliance, the DRS import and new-AD alerts.
|
||||||
|
manage_major_records:
|
||||||
|
label: Manage major repairs and alterations
|
||||||
|
description: Form 337s and their ICAs.
|
||||||
|
manage_weight_balance:
|
||||||
|
label: Manage weight and balance
|
||||||
|
description: Records and the loading setup.
|
||||||
|
manage_documents:
|
||||||
|
label: Manage documents
|
||||||
|
description: Upload, edit and delete documents and collections.
|
||||||
|
record_oil_analyses:
|
||||||
|
label: Add oil analyses
|
||||||
|
description: Enter or import lab reports.
|
||||||
|
manage_oil_analyses:
|
||||||
|
label: Manage oil analyses
|
||||||
|
description: Edit and delete oil analyses.
|
||||||
|
import_records:
|
||||||
|
label: Import logbook scans
|
||||||
|
description: Turn photos or PDFs of paper logbooks into entries.
|
||||||
|
export_data:
|
||||||
|
label: Export
|
||||||
|
description: The .sam.zip backup and the records package.
|
||||||
|
restore_history:
|
||||||
|
label: Restore from history
|
||||||
|
description: Put a record back as it was in the record history.
|
||||||
|
edit_aircraft:
|
||||||
|
label: Edit the aircraft
|
||||||
|
description: Its details, photo and settings, and the setup checklist.
|
||||||
|
delete_aircraft:
|
||||||
|
label: Delete the aircraft
|
||||||
|
description: With all its records.
|
||||||
|
manage_people:
|
||||||
|
label: Manage people
|
||||||
|
description: Give people roles on the aircraft.
|
||||||
|
manage_sharing:
|
||||||
|
label: Share links
|
||||||
|
description: Create and revoke read-only links.
|
||||||
|
receive_reminders:
|
||||||
|
label: Get reminders
|
||||||
|
description: The weekly email of what's coming due, and alerts when something becomes overdue.
|
||||||
helpers:
|
helpers:
|
||||||
aircraft:
|
aircraft:
|
||||||
overview: Overview
|
overview: Overview
|
||||||
@@ -3590,6 +3751,11 @@ en:
|
|||||||
form:
|
form:
|
||||||
interval_unit: "%{label} unit"
|
interval_unit: "%{label} unit"
|
||||||
services:
|
services:
|
||||||
|
aircraft_access:
|
||||||
|
not_found: Choose a person and a role.
|
||||||
|
owner_only: Only an Owner can give or take away the Owner role.
|
||||||
|
own_role: You can't change your own role; ask another Owner or an administrator.
|
||||||
|
last_owner: An aircraft must keep at least one Owner.
|
||||||
airworthiness:
|
airworthiness:
|
||||||
disclaimer: Based on the records in this app. Before each flight the pilot in command decides whether the aircraft is airworthy (14 CFR 91.7).
|
disclaimer: Based on the records in this app. Before each flight the pilot in command decides whether the aircraft is airworthy (14 CFR 91.7).
|
||||||
categories:
|
categories:
|
||||||
|
|||||||
+4
-1
@@ -171,7 +171,10 @@ Rails.application.routes.draw do
|
|||||||
post "about/test_email", to: "about#test_email", as: :test_email
|
post "about/test_email", to: "about#test_email", as: :test_email
|
||||||
post "about/test_reminder", to: "about#test_reminder", as: :test_reminder
|
post "about/test_reminder", to: "about#test_reminder", as: :test_reminder
|
||||||
post "about/check_records", to: "about#check_records", as: :check_records
|
post "about/check_records", to: "about#check_records", as: :check_records
|
||||||
resources :users, except: :show
|
resources :users, except: :show do
|
||||||
|
resources :aircraft_roles, controller: "user_aircraft_roles", only: %i[create update destroy]
|
||||||
|
end
|
||||||
|
resources :roles, except: :show
|
||||||
resources :integrations do
|
resources :integrations do
|
||||||
post :new_secret, on: :member
|
post :new_secret, on: :member
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# Configurable roles (Role, Permission): the owner/pilot text on each
|
||||||
|
# aircraft role becomes a link to a role. Owners and pilots keep exactly what
|
||||||
|
# they could do (Owner has everything; Pilot gets what pilots could do), and
|
||||||
|
# Mechanic and Viewer are added. The permissions are spelled out here so this
|
||||||
|
# migration doesn't change if the defaults in code do.
|
||||||
|
class CreateRoles < ActiveRecord::Migration[8.1]
|
||||||
|
BUILT_IN = [
|
||||||
|
[ "owner", "Owner", "Everything on the aircraft, including its people and sharing.", [] ],
|
||||||
|
[ "mechanic", "Mechanic", "Maintenance records: logbook entries, components, inspections, ADs and squawks.",
|
||||||
|
%w[update_hours report_squawks defer_squawks manage_squawks write_notes manage_notes record_consumables
|
||||||
|
manage_consumables write_logbook sign_logbook manage_components manage_inspections manage_ads
|
||||||
|
manage_major_records manage_weight_balance manage_documents record_oil_analyses manage_oil_analyses
|
||||||
|
receive_reminders] ],
|
||||||
|
[ "pilot", "Pilot", "Flying: logs flights and hours, reports squawks, adds notes and oil and fuel.",
|
||||||
|
%w[log_flights update_hours edit_own_flights report_squawks defer_squawks write_notes record_consumables
|
||||||
|
record_oil_analyses sign_logbook] ],
|
||||||
|
[ "viewer", "Viewer", "Sees everything on the aircraft and changes nothing.", [] ]
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
def up
|
||||||
|
create_table :roles do |t|
|
||||||
|
t.string :name, null: false
|
||||||
|
t.string :key
|
||||||
|
t.string :description
|
||||||
|
t.json :permissions, null: false, default: []
|
||||||
|
t.integer :position, null: false, default: 0
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :roles, :key, unique: true
|
||||||
|
add_index :roles, :name, unique: true
|
||||||
|
|
||||||
|
now = Time.current
|
||||||
|
BUILT_IN.each_with_index do |(key, name, description, permissions), i|
|
||||||
|
execute sanitize_sql([ "INSERT INTO roles (name, key, description, permissions, position, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
name, key, description, permissions.to_json, i, now, now ])
|
||||||
|
end
|
||||||
|
|
||||||
|
add_reference :aircraft_roles, :role, foreign_key: true
|
||||||
|
execute "UPDATE aircraft_roles SET role_id = (SELECT id FROM roles WHERE roles.key = aircraft_roles.role)"
|
||||||
|
execute "UPDATE aircraft_roles SET role_id = (SELECT id FROM roles WHERE key = 'pilot') WHERE role_id IS NULL"
|
||||||
|
change_column_null :aircraft_roles, :role_id, false
|
||||||
|
remove_column :aircraft_roles, :role
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
add_column :aircraft_roles, :role, :string
|
||||||
|
execute "UPDATE aircraft_roles SET role = CASE (SELECT key FROM roles WHERE roles.id = aircraft_roles.role_id) WHEN 'owner' THEN 'owner' ELSE 'pilot' END"
|
||||||
|
change_column_null :aircraft_roles, :role, false
|
||||||
|
remove_reference :aircraft_roles, :role, foreign_key: true
|
||||||
|
drop_table :roles
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def sanitize_sql(args) = ActiveRecord::Base.sanitize_sql_array(args)
|
||||||
|
end
|
||||||
Generated
+16
-2
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.1].define(version: 2026_11_15_020000) do
|
ActiveRecord::Schema[8.1].define(version: 2026_11_16_010000) do
|
||||||
create_table "active_storage_attachments", force: :cascade do |t|
|
create_table "active_storage_attachments", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.string "record_type", null: false
|
t.string "record_type", null: false
|
||||||
@@ -210,11 +210,12 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_15_020000) do
|
|||||||
create_table "aircraft_roles", force: :cascade do |t|
|
create_table "aircraft_roles", force: :cascade do |t|
|
||||||
t.integer "aircraft_id", null: false
|
t.integer "aircraft_id", null: false
|
||||||
t.integer "user_id", null: false
|
t.integer "user_id", null: false
|
||||||
t.string "role", null: false
|
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "role_id", null: false
|
||||||
t.index ["aircraft_id", "user_id"], name: "index_aircraft_roles_on_aircraft_id_and_user_id", unique: true
|
t.index ["aircraft_id", "user_id"], name: "index_aircraft_roles_on_aircraft_id_and_user_id", unique: true
|
||||||
t.index ["aircraft_id"], name: "index_aircraft_roles_on_aircraft_id"
|
t.index ["aircraft_id"], name: "index_aircraft_roles_on_aircraft_id"
|
||||||
|
t.index ["role_id"], name: "index_aircraft_roles_on_role_id"
|
||||||
t.index ["user_id"], name: "index_aircraft_roles_on_user_id"
|
t.index ["user_id"], name: "index_aircraft_roles_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -785,6 +786,18 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_15_020000) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "roles", force: :cascade do |t|
|
||||||
|
t.string "name", null: false
|
||||||
|
t.string "key"
|
||||||
|
t.string "description"
|
||||||
|
t.json "permissions", default: [], null: false
|
||||||
|
t.integer "position", default: 0, null: false
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["key"], name: "index_roles_on_key", unique: true
|
||||||
|
t.index ["name"], name: "index_roles_on_name", unique: true
|
||||||
|
end
|
||||||
|
|
||||||
create_table "sessions", force: :cascade do |t|
|
create_table "sessions", force: :cascade do |t|
|
||||||
t.integer "user_id", null: false
|
t.integer "user_id", null: false
|
||||||
t.string "ip_address"
|
t.string "ip_address"
|
||||||
@@ -958,6 +971,7 @@ ActiveRecord::Schema[8.1].define(version: 2026_11_15_020000) do
|
|||||||
add_foreign_key "aircraft_notes", "aircraft"
|
add_foreign_key "aircraft_notes", "aircraft"
|
||||||
add_foreign_key "aircraft_notes", "users", on_delete: :nullify
|
add_foreign_key "aircraft_notes", "users", on_delete: :nullify
|
||||||
add_foreign_key "aircraft_roles", "aircraft"
|
add_foreign_key "aircraft_roles", "aircraft"
|
||||||
|
add_foreign_key "aircraft_roles", "roles"
|
||||||
add_foreign_key "aircraft_roles", "users"
|
add_foreign_key "aircraft_roles", "users"
|
||||||
add_foreign_key "airport_updates", "users", column: "requested_by_id", on_delete: :nullify
|
add_foreign_key "airport_updates", "users", column: "requested_by_id", on_delete: :nullify
|
||||||
add_foreign_key "airworthiness_directives", "documents", on_delete: :nullify
|
add_foreign_key "airworthiness_directives", "documents", on_delete: :nullify
|
||||||
|
|||||||
@@ -14,6 +14,18 @@ Admins see the **Admin** menu (on a phone, under ☰). Admins can see and edit e
|
|||||||
|
|
||||||
With single sign-on, accounts can be created automatically at first sign-in, and admin rights can follow a group at the provider (see the main README).
|
With single sign-on, accounts can be created automatically at first sign-in, and admin rights can follow a group at the provider (see the main README).
|
||||||
|
|
||||||
|
## Roles
|
||||||
|
|
||||||
|
**Admin → Roles** sets what people can do on an aircraft. Each person has one role per aircraft; a role is a set of permissions, grouped as flying, squawks and notes, maintenance records, imports and exports, the aircraft itself, and notifications. Everyone can see the records of the aircraft they have a role on; the permissions are for changing things.
|
||||||
|
|
||||||
|
- **Owner** always has every permission, so every aircraft can always be managed. Its name and description can be changed.
|
||||||
|
- **Mechanic**, **Pilot** and **Viewer** come with sensible permissions (the table in [Getting started](getting-started.md#roles)) that you can change.
|
||||||
|
- **New role** adds your own, such as a partner, an instructor or an insurer. A role can be deleted once nobody has it.
|
||||||
|
|
||||||
|
Signing a logbook entry needs the **Sign logbook entries** permission *and* a current certificate on the person's profile. **Get reminders** decides who receives the weekly email of what's coming due and the alerts when something becomes overdue.
|
||||||
|
|
||||||
|
To give someone a role on any aircraft, open them in **Admin → Users**: **Aircraft access** lists their role on each aircraft, to change, remove or add.
|
||||||
|
|
||||||
## Account recovery from the command line
|
## Account recovery from the command line
|
||||||
|
|
||||||
If nobody can sign in to fix an account in the app (a forgotten admin password, a lockout, a lost phone with no recovery codes, the only admin disabled), run these on the server. With Docker Compose, put `docker compose exec web` in front; in Portainer, open the container's **Console** and run them there. Anyone who can run commands on the server already has the data, so they ask for nothing else. Each one is written to the log.
|
If nobody can sign in to fix an account in the app (a forgotten admin password, a lockout, a lost phone with no recovery codes, the only admin disabled), run these on the server. With Docker Compose, put `docker compose exec web` in front; in Portainer, open the container's **Console** and run them there. Anyone who can run commands on the server already has the data, so they ask for nothing else. Each one is written to the log.
|
||||||
|
|||||||
+4
-4
@@ -35,14 +35,14 @@ Reading works without it (limited to the integration's aircraft). Every write ne
|
|||||||
|---|---|
|
|---|---|
|
||||||
| `read` | Aircraft, parts, due items, inspections, ADs, squawks and logbook entries |
|
| `read` | Aircraft, parts, due items, inspections, ADs, squawks and logbook entries |
|
||||||
| `squawks:write` | Reporting squawks and updating them |
|
| `squawks:write` | Reporting squawks and updating them |
|
||||||
| `drafts:write` | Sending draft logbook entries for signing, and withdrawing them (acting for an owner of the aircraft) |
|
| `drafts:write` | Sending draft logbook entries for signing, and withdrawing them (acting for someone who can write logbook entries on the aircraft) |
|
||||||
|
|
||||||
## Requests and answers
|
## Requests and answers
|
||||||
|
|
||||||
- Base address: `https://<your server>/api/v1`
|
- Base address: `https://<your server>/api/v1`
|
||||||
- JSON in and out. Times are ISO 8601 in UTC, hours are decimals, and values are codes (`ENG`, `IN-USE`) rather than translated labels.
|
- JSON in and out. Times are ISO 8601 in UTC, hours are decimals, and values are codes (`ENG`, `IN-USE`) rather than translated labels.
|
||||||
- Lists answer `{ "data": [ … ], "next_after": 123 }`. Ask for more with `?after=123`; `?limit=` sets the page size (up to 200, default 50); `?updated_since=2026-11-01T00:00:00Z` lists only what changed since then.
|
- Lists answer `{ "data": [ … ], "next_after": 123 }`. Ask for more with `?after=123`; `?limit=` sets the page size (up to 200, default 50); `?updated_since=2026-11-01T00:00:00Z` lists only what changed since then.
|
||||||
- Errors answer `{ "error": { "code": "invalid", "message": "…", "fields": { "issue_reported": ["can't be blank"] } } }` with the matching HTTP status: 400 bad request, 401 no or wrong token, 403 not allowed (`missing_scope`, `owners_only`), 404 not found or not reachable with this token, 409 `idempotency_conflict`, 422 invalid, 429 too many requests (600 a minute per token).
|
- Errors answer `{ "error": { "code": "invalid", "message": "…", "fields": { "issue_reported": ["can't be blank"] } } }` with the matching HTTP status: 400 bad request, 401 no or wrong token, 403 not allowed (`missing_scope`; `not_permitted` when the person's role on the aircraft doesn't allow it), 404 not found or not reachable with this token, 409 `idempotency_conflict`, 422 invalid, 429 too many requests (600 a minute per token).
|
||||||
|
|
||||||
### Safe retries
|
### Safe retries
|
||||||
|
|
||||||
@@ -98,11 +98,11 @@ The answer is `201` with the squawk:
|
|||||||
|
|
||||||
### Updating a squawk
|
### Updating a squawk
|
||||||
|
|
||||||
`PATCH /squawks/:id` with `{ "squawk": { … } }`. Anyone who may write can set `external_ref`; changing `issue_reported`, `priority`, `component_id` or `notes` needs an owner of the aircraft, as in the app. A resolved squawk can't be changed. Squawks are resolved by a signed logbook entry, in the app.
|
`PATCH /squawks/:id` with `{ "squawk": { … } }`. Anyone who may write can set `external_ref`; changing `issue_reported`, `priority`, `component_id` or `notes` needs the **Manage squawks** permission on the aircraft, as in the app. Reporting one needs **Report squawks**. A resolved squawk can't be changed. Squawks are resolved by a signed logbook entry, in the app.
|
||||||
|
|
||||||
## Draft entries
|
## Draft entries
|
||||||
|
|
||||||
Another system that tracks the work, such as Redmine's issues, can send a finished visit to SAM as **draft logbook entries**: the person certifying the work then reviews and signs them in the app. Like writing entries in the app, sending drafts is for the aircraft's owners: an integration acts for an owner (`SAM-On-Behalf-Of`), such as the director of maintenance.
|
Another system that tracks the work, such as Redmine's issues, can send a finished visit to SAM as **draft logbook entries**: the person certifying the work then reviews and signs them in the app. Like writing entries in the app, sending drafts needs the **Write logbook entries** permission (Owners and Mechanics have it): an integration acts for such a person (`SAM-On-Behalf-Of`), such as the director of maintenance.
|
||||||
|
|
||||||
```
|
```
|
||||||
POST /api/v1/aircraft/12/draft_batches
|
POST /api/v1/aircraft/12/draft_batches
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Track and engine data files attached offline are kept and sent too.
|
|||||||
|
|
||||||
## Correct a flight
|
## Correct a flight
|
||||||
|
|
||||||
Open the flight and choose **Edit**. Owners can correct any flight; a pilot, the flights they logged. The date, airports, route, notes, oil and fuel (its oil and fuel records follow), and the track and engine data files can always be changed.
|
Open the flight and choose **Edit**. Owners can correct any flight; pilots, the flights they logged (the **Correct any flight** and **Correct own flights** permissions). The date, airports, route, notes, oil and fuel (its oil and fuel records follow), and the track and engine data files can always be changed.
|
||||||
|
|
||||||
The meter readings can be changed only on the latest flight, and only until the hours change again (another flight, an hours update or an import). The aircraft and its installed components then move by the difference: fixing a tach in of 1001.4 to 1001.6 adds 0.2 hours. On earlier flights the readings are locked, since the flights after them started from those readings; correct the aircraft's hours with **Update Hours** instead.
|
The meter readings can be changed only on the latest flight, and only until the hours change again (another flight, an hours update or an import). The aircraft and its installed components then move by the difference: fixing a tach in of 1001.4 to 1001.6 adds 0.2 hours. On earlier flights the readings are locked, since the flights after them started from those readings; correct the aircraft's hours with **Update Hours** instead.
|
||||||
|
|
||||||
|
|||||||
@@ -16,20 +16,21 @@ The very first visit to a new installation asks for the administrator account in
|
|||||||
|
|
||||||
## Roles
|
## Roles
|
||||||
|
|
||||||
What you can do depends on your role on each aircraft:
|
What you can do depends on your role on each aircraft. These are the built-in roles as they come; the administrator can change what each allows and add others (see [Administration](administration.md#roles)).
|
||||||
|
|
||||||
| | Pilot | Owner | Admin |
|
| | Viewer | Pilot | Mechanic | Owner |
|
||||||
|---|:-:|:-:|:-:|
|
|---|:-:|:-:|:-:|:-:|
|
||||||
| See everything on the aircraft | ✓ | ✓ | ✓ |
|
| See everything on the aircraft | ✓ | ✓ | ✓ | ✓ |
|
||||||
| Log flights, update hours, report squawks, add notes, oil and fuel | ✓ | ✓ | ✓ |
|
| Log flights, correct the ones you logged | | ✓ | | ✓ |
|
||||||
| Defer a squawk as inoperative | ✓ | ✓ | ✓ |
|
| Update hours, report and defer squawks, add notes, oil and fuel | | ✓ | ✓ | ✓ |
|
||||||
| Sign logbook entries (with your own certificate) | ✓ | ✓ | ✓ |
|
| Sign logbook entries (with your own certificate) | | ✓ | ✓ | ✓ |
|
||||||
| Edit squawks and notes, resolve squawks | | ✓ | ✓ |
|
| Write logbook entries; components, inspections, ADs, major records, W&B, documents | | | ✓ | ✓ |
|
||||||
| Components, logbook, inspections, ADs, documents, major records, W&B | | ✓ | ✓ |
|
| Edit squawks and notes, resolve squawks; edit oil and fuel records | | | ✓ | ✓ |
|
||||||
| Edit the aircraft, manage people and share links | | ✓ | ✓ |
|
| Weekly reminders and overdue alerts | | | ✓ | ✓ |
|
||||||
| Users, settings, procedures and audits for the whole app | | | ✓ |
|
| Correct or delete any flight, imports, exports, restore from history | | | | ✓ |
|
||||||
|
| Edit the aircraft, manage people and share links | | | | ✓ |
|
||||||
|
|
||||||
Anyone can add an aircraft and becomes its owner. You only see aircraft you have a role on; admins see all of them.
|
Administrators can do everything on every aircraft, and manage users, roles, settings, procedures and audits for the whole app. Anyone can add an aircraft and becomes its Owner. You only see aircraft you have a role on; administrators see all of them.
|
||||||
|
|
||||||
## Finding your way around
|
## Finding your way around
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
# Access, sharing and transfer
|
# Access, sharing and transfer
|
||||||
|
|
||||||
**Access & sharing** is for the aircraft's owners: open it from **More** at the top of the aircraft's pages.
|
**Access & sharing** is for people whose role lets them manage the aircraft's people, share links or exports (Owners): open it from **More** at the top of the aircraft's pages.
|
||||||
|
|
||||||
## People
|
## People
|
||||||
|
|
||||||
Add people by email as **owner** or **pilot** (they need an account; ask the administrator). Change or remove their role at any time. See the roles table in [Getting started](getting-started.md).
|
Add people by email with a role: **Owner**, **Mechanic**, **Pilot**, **Viewer**, or one the administrator added (they need an account; ask the administrator). Change or remove their role at any time; **What each role can do** on the page lists them. See the roles table in [Getting started](getting-started.md).
|
||||||
|
|
||||||
|
Only an Owner can give or take away the Owner role, nobody can change their own, and an aircraft always keeps at least one Owner. An administrator can also give people roles on any aircraft from **Admin → Users**.
|
||||||
|
|
||||||
## Share links
|
## Share links
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class AircraftArchiveFlowTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal "done", import.status, import.error
|
assert_equal "done", import.status, import.error
|
||||||
copy = import.aircraft
|
copy = import.aircraft
|
||||||
assert_equal [ "N54321", "Cessna" ], [ copy.tail_number, copy.make ]
|
assert_equal [ "N54321", "Cessna" ], [ copy.tail_number, copy.make ]
|
||||||
assert_equal [ "owner" ], copy.roles.where(user: @pilot).pluck(:role) # the importer owns the copy
|
assert_equal [ "owner" ], copy.roles.where(user: @pilot).map { _1.role.key } # the importer owns the copy
|
||||||
assert_equal "notes.txt", copy.squawks.sole.attachments.sole.filename.to_s
|
assert_equal "notes.txt", copy.squawks.sole.attachments.sole.filename.to_s
|
||||||
assert_equal 1, import.counts["logbook_entries"]
|
assert_equal 1, import.counts["logbook_entries"]
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class ApiDraftsTest < ActionDispatch::IntegrationTest
|
|||||||
test "drafts are for owners: an integration must act for one, with the drafts scope" do
|
test "drafts are for owners: an integration must act for one, with the drafts scope" do
|
||||||
post "/api/v1/aircraft/#{@a.id}/draft_batches", params: batch_params, headers: headers(as: @mech), as: :json
|
post "/api/v1/aircraft/#{@a.id}/draft_batches", params: batch_params, headers: headers(as: @mech), as: :json
|
||||||
assert_response :forbidden
|
assert_response :forbidden
|
||||||
assert_equal "owners_only", JSON.parse(response.body).dig("error", "code")
|
assert_equal "not_permitted", JSON.parse(response.body).dig("error", "code")
|
||||||
@token.update!(scopes: %w[read])
|
@token.update!(scopes: %w[read])
|
||||||
post "/api/v1/aircraft/#{@a.id}/draft_batches", params: batch_params, headers: headers(as: @owner), as: :json
|
post "/api/v1/aircraft/#{@a.id}/draft_batches", params: batch_params, headers: headers(as: @owner), as: :json
|
||||||
assert_equal "missing_scope", JSON.parse(response.body).dig("error", "code")
|
assert_equal "missing_scope", JSON.parse(response.body).dig("error", "code")
|
||||||
|
|||||||
@@ -79,15 +79,20 @@ class PermissionsTest < ActionDispatch::IntegrationTest
|
|||||||
test "owner manages roles with last-owner protection" do
|
test "owner manages roles with last-owner protection" do
|
||||||
sign_in @owner
|
sign_in @owner
|
||||||
owner_role = @a.roles.find_by(user: @owner)
|
owner_role = @a.roles.find_by(user: @owner)
|
||||||
patch aircraft_aircraft_role_path(@a, owner_role), params: { role: "pilot" }
|
patch aircraft_aircraft_role_path(@a, owner_role), params: { role_id: Role.for_key("pilot").id }
|
||||||
assert_equal "owner", owner_role.reload.role
|
assert_equal "owner", owner_role.reload.role.key # not their own role
|
||||||
|
|
||||||
newbie = create_user("newbie@example.com")
|
newbie = create_user("newbie@example.com")
|
||||||
post aircraft_aircraft_roles_path(@a), params: { email_address: "NewBie@example.com ", role: "owner" }
|
post aircraft_aircraft_roles_path(@a), params: { email_address: "NewBie@example.com ", role_id: Role.owner.id }
|
||||||
assert_equal "owner", @a.roles.find_by(user: newbie).role
|
assert_equal "owner", @a.roles.find_by(user: newbie).role.key
|
||||||
|
|
||||||
delete aircraft_aircraft_role_path(@a, owner_role)
|
delete aircraft_aircraft_role_path(@a, owner_role)
|
||||||
assert AircraftRole.exists?(owner_role.id), "can't remove self"
|
assert AircraftRole.exists?(owner_role.id), "can't remove self"
|
||||||
|
|
||||||
|
newbie_role = @a.roles.find_by(user: newbie)
|
||||||
|
patch aircraft_aircraft_role_path(@a, newbie_role), params: { role_id: Role.for_key("mechanic").id }
|
||||||
|
assert_equal "mechanic", newbie_role.reload.role.key
|
||||||
|
assert_equal 1, @a.roles.owners.count
|
||||||
end
|
end
|
||||||
|
|
||||||
test "owner full workflow: component service, AD compliance, inspection" do
|
test "owner full workflow: component service, AD compliance, inspection" do
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
# Configurable roles (Role, Permission): what each built-in role can do, a
|
||||||
|
# custom role, who can hand out roles, administrators managing them, and
|
||||||
|
# that every action that changes something declares the permission it needs.
|
||||||
|
class RolesTest < ActionDispatch::IntegrationTest
|
||||||
|
setup do
|
||||||
|
@owner = create_user("owner@example.com")
|
||||||
|
@admin = create_user("admin@example.com", admin: true)
|
||||||
|
@a = create_aircraft(owner: @owner, tail_number: "N12345", tach_time: 1000)
|
||||||
|
end
|
||||||
|
|
||||||
|
def member(email, role)
|
||||||
|
create_user(email).tap { @a.roles.create!(user: _1, role: role) }
|
||||||
|
end
|
||||||
|
|
||||||
|
test "every action that changes something declares the permission it needs" do
|
||||||
|
missing = Rails.application.routes.routes.filter_map do |route|
|
||||||
|
verb, controller, action = route.verb, route.defaults[:controller], route.defaults[:action]
|
||||||
|
next if controller.blank? || verb.blank? || verb.match?(/\A(GET|HEAD)?\z/)
|
||||||
|
klass = "#{controller.camelize}Controller".safe_constantize
|
||||||
|
next unless klass && klass < ApplicationController && klass.include?(AircraftScoped)
|
||||||
|
next if klass._process_action_callbacks.none? { _1.filter == :authorize_permission! && _1.kind == :before } ||
|
||||||
|
(klass == AircraftController && action == "create") # adding an aircraft makes you its Owner
|
||||||
|
rules = klass.permission_rules.select { |_, only, except| (only.nil? || only.include?(action)) && (except.nil? || except.exclude?(action)) }
|
||||||
|
"#{verb} #{controller}##{action}" if rules.empty?
|
||||||
|
end
|
||||||
|
assert_empty missing.uniq, "actions without a permission"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "the built-in roles: Owner has everything, the others their defaults, and none can be deleted" do
|
||||||
|
Role.ensure_built_in!
|
||||||
|
assert_equal Permission::ALL, Role.owner.permissions
|
||||||
|
assert_equal Permission::DEFAULTS["pilot"].sort, Role.for_key("pilot").permissions.sort
|
||||||
|
assert_empty Role.for_key("viewer").permissions
|
||||||
|
assert_not Role.for_key("pilot").destroy
|
||||||
|
Role.owner.update!(permissions: [])
|
||||||
|
assert_equal Permission::ALL, Role.owner.reload.permissions
|
||||||
|
end
|
||||||
|
|
||||||
|
test "a viewer sees the records and can change nothing" do
|
||||||
|
viewer = member("viewer@example.com", "viewer")
|
||||||
|
sign_in viewer
|
||||||
|
get aircraft_path(@a)
|
||||||
|
assert_response :success
|
||||||
|
assert_select "a[href=?]", new_aircraft_flight_log_path(@a), 0
|
||||||
|
assert_select "a[href=?]", new_aircraft_squawk_path(@a), 0
|
||||||
|
assert_select "form[action=?]", hours_aircraft_path(@a), 0
|
||||||
|
assert_select ".badge-gray", text: "Viewer"
|
||||||
|
|
||||||
|
post aircraft_flight_logs_path(@a), params: { flight_log: { date: Date.current, tach_out: 1000, tach_in: 1001 } }
|
||||||
|
assert_redirected_to aircraft_path(@a)
|
||||||
|
assert_equal "Your role on this aircraft doesn't allow that.", flash[:alert]
|
||||||
|
post aircraft_squawks_path(@a), params: { squawk: { priority: 1, issue_reported: "x" } }
|
||||||
|
patch hours_aircraft_path(@a), params: { tach_time: 1010 }
|
||||||
|
post aircraft_notes_path(@a), params: { aircraft_note: { text: "hi" } }
|
||||||
|
assert_equal 0, @a.flight_logs.count
|
||||||
|
assert_equal 0, @a.squawks.count
|
||||||
|
assert_equal 0, @a.notes.count
|
||||||
|
assert_equal 1000, @a.reload.tach_time
|
||||||
|
end
|
||||||
|
|
||||||
|
test "a mechanic maintains the aircraft but doesn't fly it or manage its people" do
|
||||||
|
mechanic = member("mech@example.com", "mechanic")
|
||||||
|
squawk = @a.squawks.create!(priority: 1, issue_reported: "Loose cowl")
|
||||||
|
sign_in mechanic
|
||||||
|
post aircraft_components_path(@a), params: { component: { component_type_id: component_type.id, manufacturer: "Lycoming", model: "O-320", date_in_service: Date.current } }
|
||||||
|
assert_equal 1, @a.components.count
|
||||||
|
patch aircraft_squawk_path(@a, squawk), params: { squawk: { issue_reported: "Loose cowl fastener" } }
|
||||||
|
assert_equal "Loose cowl fastener", squawk.reload.issue_reported
|
||||||
|
|
||||||
|
post aircraft_flight_logs_path(@a), params: { flight_log: { date: Date.current, tach_out: 1000, tach_in: 1001 } }
|
||||||
|
assert_equal 0, @a.flight_logs.count
|
||||||
|
post aircraft_aircraft_roles_path(@a), params: { email_address: "owner@example.com", role_id: Role.for_key("viewer").id }
|
||||||
|
assert_equal "owner", @a.roles.find_by(user: @owner).role.key
|
||||||
|
get aircraft_aircraft_roles_path(@a)
|
||||||
|
assert_redirected_to aircraft_path(@a)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "a custom role gets exactly what's ticked, and managing people doesn't make you an Owner" do
|
||||||
|
role = Role.create!(name: "Partner", permissions: %w[log_flights manage_people])
|
||||||
|
partner = member("partner@example.com", role)
|
||||||
|
sign_in partner
|
||||||
|
post aircraft_flight_logs_path(@a), params: { flight_log: { date: Date.current, tach_out: 1000, tach_in: 1001 } }
|
||||||
|
assert_equal 1, @a.flight_logs.count
|
||||||
|
post aircraft_squawks_path(@a), params: { squawk: { priority: 1, issue_reported: "x" } }
|
||||||
|
assert_equal 0, @a.squawks.count
|
||||||
|
|
||||||
|
get aircraft_aircraft_roles_path(@a)
|
||||||
|
assert_response :success
|
||||||
|
assert_select "select[name=role_id] option", text: "Owner", count: 0
|
||||||
|
newbie = create_user("newbie@example.com")
|
||||||
|
post aircraft_aircraft_roles_path(@a), params: { email_address: newbie.email_address, role_id: Role.owner.id }
|
||||||
|
assert_nil @a.roles.find_by(user: newbie)
|
||||||
|
post aircraft_aircraft_roles_path(@a), params: { email_address: newbie.email_address, role_id: Role.for_key("viewer").id }
|
||||||
|
assert_equal "viewer", @a.roles.find_by(user: newbie).role.key
|
||||||
|
|
||||||
|
mine = @a.roles.find_by(user: partner)
|
||||||
|
patch aircraft_aircraft_role_path(@a, mine), params: { role_id: Role.owner.id }
|
||||||
|
assert_equal role, mine.reload.role
|
||||||
|
owners = @a.roles.find_by(user: @owner)
|
||||||
|
patch aircraft_aircraft_role_path(@a, owners), params: { role_id: Role.for_key("viewer").id }
|
||||||
|
delete aircraft_aircraft_role_path(@a, owners)
|
||||||
|
assert_equal "owner", owners.reload.role.key
|
||||||
|
end
|
||||||
|
|
||||||
|
test "administrators manage roles: create, change, and delete only unused custom ones" do
|
||||||
|
sign_in @admin
|
||||||
|
get admin_roles_path
|
||||||
|
assert_select "tr.role-row", 4
|
||||||
|
post admin_roles_path, params: { role: { name: "Instructor", description: "Teaches in it", permissions: [ "", "log_flights", "bogus" ] } }
|
||||||
|
role = Role.find_by!(name: "Instructor")
|
||||||
|
assert_equal %w[log_flights], role.permissions
|
||||||
|
|
||||||
|
patch admin_role_path(role), params: { role: { name: "Instructor", permissions: [ "" ] } }
|
||||||
|
assert_empty role.reload.permissions
|
||||||
|
patch admin_role_path(Role.owner), params: { role: { name: "Owner", permissions: [ "" ] } }
|
||||||
|
assert_equal Permission::ALL, Role.owner.reload.permissions
|
||||||
|
|
||||||
|
@a.roles.create!(user: create_user, role: role)
|
||||||
|
delete admin_role_path(role)
|
||||||
|
assert Role.exists?(role.id)
|
||||||
|
delete admin_role_path(Role.for_key("viewer"))
|
||||||
|
assert Role.for_key("viewer")
|
||||||
|
@a.roles.where(role: role).destroy_all
|
||||||
|
delete admin_role_path(role)
|
||||||
|
assert_not Role.exists?(role.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "administrators give people roles on any aircraft, keeping an Owner" do
|
||||||
|
person = create_user("person@example.com")
|
||||||
|
sign_in @admin
|
||||||
|
get edit_admin_user_path(person)
|
||||||
|
assert_select "#access select[name=aircraft_id] option", text: "N12345"
|
||||||
|
post admin_user_aircraft_roles_path(person), params: { aircraft_id: @a.id, role_id: Role.for_key("mechanic").id }
|
||||||
|
membership = @a.roles.find_by!(user: person)
|
||||||
|
assert_equal "mechanic", membership.role.key
|
||||||
|
|
||||||
|
patch admin_user_aircraft_role_path(person, membership), params: { role_id: Role.owner.id }
|
||||||
|
assert_equal "owner", membership.reload.role.key
|
||||||
|
owner_membership = @a.roles.find_by(user: @owner)
|
||||||
|
delete admin_user_aircraft_role_path(@owner, owner_membership)
|
||||||
|
assert_not AircraftRole.exists?(owner_membership.id)
|
||||||
|
delete admin_user_aircraft_role_path(person, membership)
|
||||||
|
assert AircraftRole.exists?(membership.id), "the last Owner stays"
|
||||||
|
|
||||||
|
sign_in create_user("nobody@example.com")
|
||||||
|
post admin_user_aircraft_roles_path(person), params: { aircraft_id: @a.id, role_id: Role.owner.id }
|
||||||
|
assert_equal 1, @a.roles.count
|
||||||
|
end
|
||||||
|
|
||||||
|
test "reminders go to roles that get them" do
|
||||||
|
mechanic = member("mech@example.com", "mechanic")
|
||||||
|
pilot = member("pilot@example.com", "pilot")
|
||||||
|
@a.squawks.create!(priority: 0, issue_reported: "Grounding")
|
||||||
|
assert_equal [ @a ], ReminderMailer.items_for(@owner).map(&:first)
|
||||||
|
assert_equal [ @a ], ReminderMailer.items_for(mechanic).map(&:first)
|
||||||
|
assert_empty ReminderMailer.items_for(pilot)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "the API follows the person's role" do
|
||||||
|
viewer = member("viewer@example.com", "viewer")
|
||||||
|
token = ApiToken.create!(name: "script", kind: "personal", user: viewer, scopes: %w[read squawks:write])
|
||||||
|
post "/api/v1/aircraft/#{@a.id}/squawks", params: { squawk: { issue_reported: "x", priority: 1 } },
|
||||||
|
headers: { "Authorization" => "Bearer #{token.token}" }, as: :json
|
||||||
|
assert_response :forbidden
|
||||||
|
assert_equal "not_permitted", JSON.parse(response.body).dig("error", "code")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -26,6 +26,6 @@ class SetupTest < ActionDispatch::IntegrationTest
|
|||||||
post aircraft_index_path, params: { aircraft: { tail_number: "N1", tach_time: 50 } }
|
post aircraft_index_path, params: { aircraft: { tail_number: "N1", tach_time: 50 } }
|
||||||
a = Aircraft.find_by!(tail_number: "N1")
|
a = Aircraft.find_by!(tail_number: "N1")
|
||||||
assert_redirected_to aircraft_path(a)
|
assert_redirected_to aircraft_path(a)
|
||||||
assert_equal "owner", user.role_for(a)
|
assert_equal "owner", user.role_for(a).key
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Loaded 100 of 101 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user