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.
|
||||
class AdAlertsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :manage_ads
|
||||
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") }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class AdCompliancesController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :manage_ads
|
||||
before_action :set_compliance, only: %i[edit update destroy]
|
||||
|
||||
def new
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
class AdImportsController < ApplicationController
|
||||
include AircraftScoped
|
||||
include StoredUpload
|
||||
before_action :require_owner!
|
||||
requires_permission :manage_ads
|
||||
|
||||
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]
|
||||
|
||||
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
|
||||
|
||||
def new
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Download the aircraft's flights as an AirTrail import file.
|
||||
class AirTrailExportsController < ApplicationController
|
||||
include AircraftScoped
|
||||
requires_permission :log_flights
|
||||
|
||||
def new
|
||||
@export = build_export
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
class AircraftController < ApplicationController
|
||||
include AircraftScoped
|
||||
skip_before_action :set_aircraft, only: %i[index new create]
|
||||
before_action :require_owner!, only: %i[edit update destroy]
|
||||
skip_before_action :set_aircraft, :authorize_permission!, only: %i[index new create]
|
||||
requires_permission :edit_aircraft, only: %i[edit update]
|
||||
requires_permission :delete_aircraft, only: :destroy
|
||||
requires_permission :update_hours, only: :update_hours
|
||||
|
||||
def index
|
||||
@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).
|
||||
class AircraftExportsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :export_data
|
||||
|
||||
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
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
checks_permission_itself only: :index
|
||||
requires_permission :manage_people, only: %i[create update destroy]
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
def create
|
||||
user = User.find_by(email_address: params[:email_address].to_s.strip.downcase)
|
||||
unless user
|
||||
return redirect_to aircraft_aircraft_roles_path(@aircraft),
|
||||
alert: t("flash.aircraft_roles.no_user_with_that")
|
||||
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
|
||||
return back(alert: t("flash.aircraft_roles.no_user_with_that")) unless user
|
||||
error = access.add(user, Role.find_by(id: params[:role_id]))
|
||||
back(error ? { alert: error } : { notice: t("flash.aircraft_roles.added", display_name: user.display_name) })
|
||||
end
|
||||
|
||||
def update
|
||||
role = @aircraft.roles.find(params[:id])
|
||||
if demoting_last_owner?(role, params[:role])
|
||||
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")
|
||||
error = access.change(@aircraft.roles.find(params[:id]), Role.find_by(id: params[:role_id]))
|
||||
back(error ? { alert: error } : { notice: t("flash.aircraft_roles.role_updated") })
|
||||
end
|
||||
|
||||
def destroy
|
||||
role = @aircraft.roles.find(params[:id])
|
||||
if role.user == current_user
|
||||
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")
|
||||
error = access.remove(@aircraft.roles.find(params[:id]))
|
||||
back(error ? { alert: error } : { notice: t("flash.aircraft_roles.access_removed") })
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def demoting_last_owner?(role, new_role)
|
||||
role.role == "owner" && new_role != "owner" && @aircraft.roles.owners.count <= 1
|
||||
end
|
||||
def access = AircraftAccess.new(@aircraft, actor: current_user)
|
||||
def back(flash) = redirect_to(aircraft_aircraft_roles_path(@aircraft), flash)
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
# Flights → Standardize airport codes (owners).
|
||||
class AirportCodesController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :edit_any_flight
|
||||
|
||||
def show
|
||||
@standardizer = AirportCodeStandardizer.new(@aircraft)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
class AirworthinessDirectivesController < ApplicationController
|
||||
include AircraftScoped
|
||||
include Applicability
|
||||
before_action :require_owner!, except: :index
|
||||
requires_permission :manage_ads, except: :index
|
||||
before_action :set_ad, only: %i[edit update destroy]
|
||||
|
||||
def index
|
||||
@rows = Compliance.ad_rows(@aircraft)
|
||||
@history = AdCompliance.for_aircraft(@aircraft).recent_first
|
||||
.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
|
||||
end
|
||||
|
||||
|
||||
@@ -70,8 +70,12 @@ module Api
|
||||
|
||||
def find_aircraft(id = params[:aircraft_id]) = aircraft_scope.find(id)
|
||||
|
||||
def role_on(aircraft) = acting_user&.role_for(aircraft)
|
||||
def owner_of?(aircraft) = role_on(aircraft).in?(%w[admin owner])
|
||||
# What the person it's acting for can do on the aircraft, as in the app (Role).
|
||||
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>.
|
||||
def paginate(scope)
|
||||
|
||||
@@ -27,7 +27,7 @@ module Api
|
||||
# POST /aircraft/:aircraft_id/draft_batches
|
||||
def create
|
||||
@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)
|
||||
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.
|
||||
def destroy
|
||||
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?)
|
||||
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
|
||||
|
||||
@@ -31,6 +31,7 @@ module Api
|
||||
# POST /aircraft/:aircraft_id/squawks
|
||||
def create
|
||||
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.component_id = nil unless aircraft.components.exists?(id: squawk.component_id)
|
||||
squawk.save!
|
||||
@@ -39,13 +40,13 @@ module Api
|
||||
end
|
||||
|
||||
# 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
|
||||
squawk = find_squawk
|
||||
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)
|
||||
if (attrs.keys - %w[external_ref]).any? && !owner_of?(squawk.aircraft)
|
||||
return render_error(:forbidden, "owners_only", "Only the aircraft's owners can change a squawk's details.")
|
||||
if (attrs.keys - %w[external_ref]).any? && !can?(:manage_squawks, squawk.aircraft)
|
||||
return not_permitted(:manage_squawks)
|
||||
end
|
||||
attrs[:component_id] = nil if attrs.key?(:component_id) && !squawk.aircraft.components.exists?(id: attrs[:component_id])
|
||||
squawk.update!(attrs)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class ComponentsController < ApplicationController
|
||||
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]
|
||||
|
||||
def index
|
||||
|
||||
@@ -1,16 +1,38 @@
|
||||
# Scopes a controller to one aircraft the current user can access and exposes
|
||||
# role helpers. Unknown and inaccessible aircraft both 404 (enumeration-safe).
|
||||
# Scopes a controller to one aircraft the current user can access, and checks
|
||||
# what their role there allows (Role, Permission). Unknown and inaccessible
|
||||
# aircraft both 404 (enumeration-safe). Administrators can do everything.
|
||||
#
|
||||
# Access matrix (mirrors the original):
|
||||
# admin – everything
|
||||
# owner – everything on their aircraft
|
||||
# pilot – view all; update hours; create squawks, notes, oil/fuel, flight logs
|
||||
# Each controller says which permission its actions need:
|
||||
#
|
||||
# requires_permission :manage_components, except: %i[index show]
|
||||
# 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
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
SELF_CHECKED = "(checked by the controller)".freeze
|
||||
|
||||
class MissingPermission < StandardError; end
|
||||
|
||||
included do
|
||||
class_attribute :permission_rules, instance_accessor: false, default: []
|
||||
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
|
||||
|
||||
private
|
||||
@@ -21,18 +43,34 @@ module AircraftScoped
|
||||
@aircraft = current_user.accessible_aircraft.find(aircraft_param)
|
||||
end
|
||||
|
||||
# Their Role here (nil for an administrator without one).
|
||||
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
|
||||
|
||||
# Owner-level write access (admins included).
|
||||
def owner? = current_role.in?(%w[admin owner])
|
||||
alias_method :can_write?, :owner?
|
||||
def can?(permission) = current_user.admin? || current_role&.can?(permission) || false
|
||||
|
||||
def require_owner!
|
||||
return if owner?
|
||||
redirect_back fallback_location: aircraft_path(@aircraft),
|
||||
alert: t("flash.common.only_owners_can_do")
|
||||
# The Owner role (or an administrator): everything.
|
||||
def owner? = current_user.admin? || current_role&.owner? || false
|
||||
|
||||
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
|
||||
|
||||
# Returns id only if it belongs to the given (aircraft-scoped) relation; else nil.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class ConsumableRecordsController < ApplicationController
|
||||
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]
|
||||
|
||||
RECORDS_PER_PAGE = 50
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class DocumentCollectionsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :manage_documents
|
||||
before_action :set_collection, only: %i[edit update destroy]
|
||||
|
||||
def new
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class DocumentsController < ApplicationController
|
||||
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]
|
||||
|
||||
def index
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
# who they are again (password, or single sign-on just now), and confirms.
|
||||
class EntrySignaturesController < ApplicationController
|
||||
include AircraftScoped
|
||||
requires_permission :sign_logbook
|
||||
include EntrySigning
|
||||
before_action :set_entry
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
class FlightImportsController < ApplicationController
|
||||
include AircraftScoped
|
||||
include StoredUpload
|
||||
before_action :require_owner!
|
||||
requires_permission :import_flights
|
||||
|
||||
def new; end
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
class FlightLogsController < ApplicationController
|
||||
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 :require_flight_editor!, only: %i[edit update]
|
||||
helper_method :can_edit_flight?
|
||||
@@ -126,7 +128,10 @@ class FlightLogsController < ApplicationController
|
||||
|
||||
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!
|
||||
return if can_edit_flight?(@flight_log)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class InspectionRecordsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :manage_inspections
|
||||
before_action :set_record, only: %i[edit update destroy]
|
||||
|
||||
def new
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class InspectionTypesController < ApplicationController
|
||||
include AircraftScoped
|
||||
include Applicability
|
||||
before_action :require_owner!
|
||||
requires_permission :manage_inspections
|
||||
before_action :set_type, only: %i[edit update destroy]
|
||||
|
||||
def new
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# the loading calculator.
|
||||
class LoadingSetupsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :manage_weight_balance
|
||||
|
||||
def edit
|
||||
@setup = @aircraft.loading_setup
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class LogbookEntriesController < ApplicationController
|
||||
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 :require_unsigned, only: %i[edit update destroy]
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# entries in the background (LogbookTranscriptionJob).
|
||||
class LogbookImportsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :import_records
|
||||
|
||||
def new
|
||||
@collections = @aircraft.document_collections.ordered
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MajorRecordsController < ApplicationController
|
||||
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]
|
||||
|
||||
def index
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class NotesController < ApplicationController
|
||||
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]
|
||||
|
||||
def index
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class OilAnalysesController < ApplicationController
|
||||
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]
|
||||
|
||||
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).
|
||||
class RecordVersionsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!, only: :restore
|
||||
requires_permission :restore_history, only: :restore
|
||||
|
||||
SHARED = { "AirworthinessDirective" => AirworthinessDirective, "InspectionType" => InspectionType }.freeze
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Download every record of an aircraft in one ZIP (owners).
|
||||
class RecordsPackagesController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :export_data
|
||||
|
||||
def show
|
||||
package = RecordsPackage.new(@aircraft, source: request.host)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class ShareTokensController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :manage_sharing
|
||||
|
||||
def create
|
||||
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.
|
||||
class SigningInvitationsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :write_logbook
|
||||
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") }
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ class SquawksController < ApplicationController
|
||||
include AircraftScoped
|
||||
# Pilots may create squawks and defer inoperative items (91.213(d) lets the
|
||||
# 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]
|
||||
|
||||
def index
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class StandardInspectionsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!
|
||||
requires_permission :manage_inspections
|
||||
|
||||
def new; end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# keep the records and the loading setup).
|
||||
class WeightBalanceRecordsController < ApplicationController
|
||||
include AircraftScoped
|
||||
before_action :require_owner!, except: :index
|
||||
requires_permission :manage_weight_balance, except: :index
|
||||
before_action :set_record, only: %i[edit update destroy]
|
||||
|
||||
def index
|
||||
|
||||
@@ -3,11 +3,14 @@ module AircraftHelper
|
||||
|
||||
# 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,
|
||||
# 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
|
||||
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) ],
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,9 +29,9 @@ export default class extends Controller {
|
||||
const forms = {}
|
||||
const paths = [ "/" ]
|
||||
for (const a of this.aircraftValue) {
|
||||
paths.push(...a.pages, a.flight, a.squawk)
|
||||
forms[a.flight] = { tail: a.tail, kind: "flight" }
|
||||
forms[a.squawk] = { tail: a.tail, kind: "squawk" }
|
||||
paths.push(...a.pages)
|
||||
if (a.flight) { paths.push(a.flight); forms[a.flight] = { tail: a.tail, kind: "flight" } }
|
||||
if (a.squawk) { paths.push(a.squawk); forms[a.squawk] = { tail: a.tail, kind: "squawk" } }
|
||||
}
|
||||
const pictures = this.aircraftValue.flatMap((a) => a.pictures || [])
|
||||
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
|
||||
# becomes overdue again is sent again.
|
||||
class OverdueNotificationJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
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 ]) }
|
||||
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]) }
|
||||
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?
|
||||
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)
|
||||
end
|
||||
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
|
||||
# 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.
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
class ReminderMailer < ApplicationMailer
|
||||
# [[aircraft, issues, new AD alerts], …] for the aircraft the user owns
|
||||
# that need attention.
|
||||
# Aircraft where the user's role includes the permission.
|
||||
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)
|
||||
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? }
|
||||
end
|
||||
|
||||
@@ -10,10 +15,11 @@ class ReminderMailer < ApplicationMailer
|
||||
|
||||
def self.audit_due_for?(user) = user.admin? && AuditRun.due_soon?
|
||||
|
||||
# Owned aircraft whose AD baseline needs a (new) DRS import: none yet, a
|
||||
# year old, or a model never covered.
|
||||
# Aircraft they get reminders for and manage the ADs of, whose AD baseline
|
||||
# needs a (new) DRS import: none yet, a year old, or a model never covered.
|
||||
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? }
|
||||
end
|
||||
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
# Someone's role on an aircraft (Role), which decides what they can do there.
|
||||
class AircraftRole < ApplicationRecord
|
||||
ROLES = LabelSet.new("aircraft_role.roles", %w[owner pilot])
|
||||
|
||||
belongs_to :aircraft
|
||||
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" }
|
||||
|
||||
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
|
||||
@@ -36,11 +36,6 @@ class FlightLog < ApplicationRecord
|
||||
aircraft.flight_logs.maximum(:id) == id && (tach_in.nil? || tach_in == aircraft.tach_time)
|
||||
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
|
||||
|
||||
# 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
|
||||
end
|
||||
|
||||
# 'admin' | 'owner' | 'pilot' | nil
|
||||
# Their Role on the aircraft (nil for none; administrators may have none).
|
||||
def role_for(aircraft)
|
||||
return "admin" if admin?
|
||||
aircraft_roles.find_by(aircraft: aircraft)&.role
|
||||
aircraft_roles.includes(:role).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
|
||||
|
||||
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_oil_analyses
|
||||
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",
|
||||
notes: [ @manifest["source_instance"].presence && "Source: #{@manifest['source_instance']}", summary ].compact.join(". "),
|
||||
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)
|
||||
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" => … } }.
|
||||
def record!(user:, answers:, notes:, sample_ids:)
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
</ul>
|
||||
<% elsif key == "users" %>
|
||||
<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>
|
||||
<% end %>
|
||||
<%= 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. %>
|
||||
<% info = SystemInfo.new %>
|
||||
<% 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" %>
|
||||
<% p_ = "mt-1 text-sm leading-relaxed" %>
|
||||
<article class="text-slate-900">
|
||||
@@ -50,7 +50,7 @@
|
||||
<% users.each do |u| %>
|
||||
<% 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>
|
||||
<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"><%= if u.disabled? || current.empty? then t(".no")
|
||||
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>
|
||||
<%= 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>
|
||||
<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 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="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" } %>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<div class="grid gap-5 lg:grid-cols-3">
|
||||
<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">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title"><%= t(".airworthiness") %></h2>
|
||||
@@ -58,6 +58,7 @@
|
||||
</div>
|
||||
|
||||
<div class="space-y-5">
|
||||
<% if can?(:update_hours) %>
|
||||
<section class="card">
|
||||
<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",
|
||||
@@ -69,17 +70,18 @@
|
||||
<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>
|
||||
</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" %>
|
||||
<% end %>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
<%= render "aircraft/last_flight", aircraft: @aircraft, last_day: @last_day %>
|
||||
|
||||
<section class="card">
|
||||
<div class="card-header">
|
||||
<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>
|
||||
<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>
|
||||
@@ -94,7 +96,7 @@
|
||||
|
||||
<section class="card">
|
||||
<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? %>
|
||||
<ul class="divide-y divide-slate-100">
|
||||
<% @notes.each do |note| %>
|
||||
|
||||
@@ -2,31 +2,45 @@
|
||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||
<h2 class="mb-4 text-lg font-semibold"><%= t(".access_sharing_html") %></h2>
|
||||
<div class="grid gap-5 lg:grid-cols-2">
|
||||
<% if can?(:manage_people) %>
|
||||
<section class="card">
|
||||
<div class="card-header"><h2 class="card-title"><%= t(".people") %></h2></div>
|
||||
<% roles = @access.assignable_roles %>
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<% @roles.each do |r| %>
|
||||
<tr>
|
||||
<td><%= r.user.display_name %><div class="text-xs text-slate-500"><%= r.user.email_address %></div></td>
|
||||
<td>
|
||||
<%= form_with url: aircraft_aircraft_role_path(@aircraft, r), method: :patch do |f| %>
|
||||
<%= f.select :role, AircraftRole::ROLES.invert, { selected: r.role }, class: "input w-28", data: { submit_on_change: true } %>
|
||||
<% if roles.include?(r.role) && (r.user != current_user || current_user.admin?) %>
|
||||
<%= 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 %>
|
||||
</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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</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| %>
|
||||
<div class="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" %>
|
||||
<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_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" %>
|
||||
<% 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>
|
||||
<% end %>
|
||||
|
||||
<% if can?(:manage_sharing) %>
|
||||
<section class="card">
|
||||
<div class="card-header"><h2 class="card-title"><%= t(".share_links") %></h2></div>
|
||||
<% if @share_tokens.any? %>
|
||||
@@ -59,7 +73,9 @@
|
||||
<%= f.submit t(".create_share_link") %>
|
||||
<% end %>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
<% if can?(:export_data) %>
|
||||
<section class="card lg:col-span-2">
|
||||
<div class="card-header">
|
||||
<div>
|
||||
@@ -76,4 +92,5 @@
|
||||
<%= link_to t(".download_records_package"), aircraft_records_package_path(@aircraft), class: "btn-secondary", data: { turbo: false } %>
|
||||
</div>
|
||||
</section>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -3,7 +3,7 @@
|
||||
<section class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title"><%= t(".airworthiness_directives_bulletins") %></h2>
|
||||
<% if owner? %>
|
||||
<% if can?(:manage_ads) %>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<% if @attachable.any? %>
|
||||
<%= 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><%= compliance_badge(row.status) %></td>
|
||||
<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" %>
|
||||
<% 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" %>
|
||||
@@ -58,7 +58,7 @@
|
||||
<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>
|
||||
</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 class="card-body space-y-2 text-sm">
|
||||
<% if last_drs %>
|
||||
@@ -77,7 +77,7 @@
|
||||
<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>
|
||||
</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>
|
||||
<% if @alerts.any? %>
|
||||
<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>
|
||||
<%= link_to t(".read_it_in_the_federal"), alert.html_url, class: "link text-xs", target: "_blank", rel: "noopener" %>
|
||||
</div>
|
||||
<% if owner? %>
|
||||
<% if can?(:manage_ads) %>
|
||||
<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(".dismiss"), dismiss_aircraft_ad_alert_path(@aircraft, alert), class: "btn-secondary btn-sm", title: t(".doesn_t_apply") %>
|
||||
@@ -101,7 +101,7 @@
|
||||
<% else %>
|
||||
<%= empty_state t(".nothing_new_to_review") %>
|
||||
<% 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 %>
|
||||
<div class="min-w-0 flex-1">
|
||||
<%= label_tag :ad_watch_terms, t(".additional_search_terms"), class: "label" %>
|
||||
@@ -140,7 +140,7 @@
|
||||
</div>
|
||||
<% end %>
|
||||
</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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="flex items-center gap-3">
|
||||
<%= link_to (@show_disposed ? t(".hide_disposed") : t(".show_disposed")),
|
||||
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>
|
||||
<% if @rows.empty? %>
|
||||
@@ -39,7 +39,7 @@
|
||||
</td>
|
||||
<td><%= life_badge(c.life_status) %></td>
|
||||
<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(".service"), aircraft_component_path(@aircraft, c, anchor: "service"), class: "btn-secondary btn-sm" %>
|
||||
<% end %>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<section class="card lg:col-span-2">
|
||||
<div class="card-header">
|
||||
<h2 class="card-title"><%= @component %> <%= life_badge(@component.life_status) %></h2>
|
||||
<% if owner? %>
|
||||
<% if can?(:manage_components) %>
|
||||
<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(".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 %>
|
||||
</section>
|
||||
|
||||
<% if owner? %>
|
||||
<% if can?(:manage_components) %>
|
||||
<section class="card" id="service">
|
||||
<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",
|
||||
@@ -53,11 +53,11 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if @inspection_rows.any? || owner? %>
|
||||
<% if @inspection_rows.any? || can?(:manage_inspections) %>
|
||||
<section class="card mt-5" id="inspections">
|
||||
<div class="card-header">
|
||||
<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>
|
||||
<% if @inspection_rows.any? %>
|
||||
<table class="table">
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<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-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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<section class="card">
|
||||
<div class="card-header">
|
||||
<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 class="card-body">
|
||||
<div class="mb-3 flex flex-wrap gap-x-6 gap-y-1 text-sm">
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<%= 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>
|
||||
</li>
|
||||
@@ -1,7 +1,7 @@
|
||||
<% content_for :title, t(".documents", tail_number: @aircraft.tail_number) %>
|
||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||
<div class="mb-4 flex flex-wrap justify-end gap-2">
|
||||
<% if owner? %>
|
||||
<% if can?(:manage_documents) %>
|
||||
<%= more_menu do %>
|
||||
<%= 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" %>
|
||||
@@ -25,7 +25,7 @@
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<%= 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(".edit"), edit_aircraft_document_collection_path(@aircraft, col), class: "btn-secondary btn-sm" %>
|
||||
<% end %>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<%= 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 class="card-body">
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
<div class="card-header">
|
||||
<h2 class="card-title"><%= t(".flight_log") %></h2>
|
||||
<%= more_menu do %>
|
||||
<% if owner? %><%= 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 owner? %><%= link_to t(".standardize_airport_codes"), aircraft_airport_codes_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 %>
|
||||
<% if can?(:log_flights) %><%= link_to t(".export_for_airtrail"), new_aircraft_air_trail_export_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 %>
|
||||
</div>
|
||||
<% 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="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 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>
|
||||
<%# 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">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||
<section class="card">
|
||||
<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? %>
|
||||
<div class="overflow-x-auto">
|
||||
<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><%= compliance_badge(row.status) %></td>
|
||||
<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(".edit"), edit_aircraft_inspection_type_path(@aircraft, row.type), class: "btn-secondary btn-sm" %>
|
||||
<% end %>
|
||||
@@ -44,7 +44,7 @@
|
||||
<td><%= r.inspection_type.name %><%= " (#{r.component})" if r.component %></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-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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<%= link_to t(".help"), help_path, class: "block px-4 py-2.5 hover:bg-slate-100" %>
|
||||
<% 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>
|
||||
<% [ [ 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" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -71,7 +71,7 @@
|
||||
<%= t(".admin") %> <span aria-hidden="true" class="text-xs">▾</span>
|
||||
</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">
|
||||
<% [ [ 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)) ] %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -13,10 +13,8 @@
|
||||
<%= f.submit t(".filter"), class: "sr-only" %>
|
||||
<% 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? %>
|
||||
<%= more_menu do %><%= link_to t(".import_scans"), new_aircraft_logbook_import_path(@aircraft), class: "menu-item" %><% end %>
|
||||
<%= link_to t(".new_entry"), new_aircraft_logbook_entry_path(@aircraft), class: "btn-primary" %>
|
||||
<% end %>
|
||||
<% if can?(:import_records) %><%= more_menu do %><%= link_to t(".import_scans"), new_aircraft_logbook_import_path(@aircraft), class: "menu-item" %><% end %><% end %>
|
||||
<% if can?(:write_logbook) %><%= link_to t(".new_entry"), new_aircraft_logbook_entry_path(@aircraft), class: "btn-primary" %><% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% if @entries.any? %>
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
<div class="flex gap-2">
|
||||
<% if @entry.signed? %>
|
||||
<%= 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 %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= link_to t(".sign"), new_aircraft_logbook_entry_signature_path(@aircraft, @entry), class: "btn-primary btn-sm" %>
|
||||
<% if owner? %><%= link_to t(".edit"), edit_aircraft_logbook_entry_path(@aircraft, @entry), class: "btn-secondary btn-sm" %><% end %>
|
||||
<% if can?(:sign_logbook) %><%= link_to t(".sign"), new_aircraft_logbook_entry_signature_path(@aircraft, @entry), class: "btn-primary 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 %>
|
||||
<% 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" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -27,7 +27,7 @@
|
||||
<% 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">
|
||||
<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>
|
||||
<% end %>
|
||||
<div class="flex flex-wrap gap-4 text-sm text-slate-600">
|
||||
@@ -53,7 +53,7 @@
|
||||
<% 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">
|
||||
<%= 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") %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||
<section class="card">
|
||||
<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(".alteration"), new_aircraft_major_record_path(@aircraft, type: "alteration"), class: "btn-primary" %></div><% end %></div>
|
||||
<% if @records.any? %>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||
<section class="card max-w-4xl">
|
||||
<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">
|
||||
<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>
|
||||
@@ -15,7 +15,7 @@
|
||||
<dd>
|
||||
<% 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" %>
|
||||
<% 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" %>
|
||||
<% else %>—<% end %>
|
||||
</dd></div>
|
||||
@@ -25,7 +25,7 @@
|
||||
<% if (ica = @record.ica_inspection_type) %>
|
||||
<% 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)) %>
|
||||
<% 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" %>
|
||||
<% end %>
|
||||
</dd></div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<% content_for :title, t(".notes", tail_number: @aircraft.tail_number) %>
|
||||
<%= render "shared/aircraft_header", aircraft: @aircraft %>
|
||||
<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? %>
|
||||
<ul class="divide-y divide-slate-100">
|
||||
<% @notes.each do |note| %>
|
||||
@@ -14,7 +14,7 @@
|
||||
<% if note.public? %><span class="badge-green ml-1"><%= t(".visible_on_share_links") %></span><% end %>
|
||||
</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>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<%= render "shared/oil_subnav", aircraft: @aircraft %>
|
||||
<% recent = @analyses.first(OilAnalysesController::COMPARE_SAMPLES) %>
|
||||
<div class="space-y-5">
|
||||
<% if can?(:record_oil_analyses) %>
|
||||
<section class="card">
|
||||
<div class="card-header">
|
||||
<div>
|
||||
@@ -12,11 +13,12 @@
|
||||
<%= render "import", aircraft: @aircraft %>
|
||||
</div>
|
||||
</section>
|
||||
<% end %>
|
||||
|
||||
<section class="card">
|
||||
<div class="card-header">
|
||||
<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 class="card-body">
|
||||
<% series = oil_trend_series(@analyses) %>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<% 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>
|
||||
<% end %>
|
||||
<% if owner? %>
|
||||
<% if can?(:manage_oil_analyses) %>
|
||||
<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" %>
|
||||
<%= 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 } %>
|
||||
<% end %>
|
||||
</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>
|
||||
@@ -14,18 +14,18 @@
|
||||
<%= airworthiness_badge(aw) %>
|
||||
<%= 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="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 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" %>
|
||||
<%= link_to t(".report_squawk"), new_aircraft_squawk_path(aircraft), class: "btn-secondary" %>
|
||||
<% if can?(:log_flights) %><%= link_to t(".log_flight"), new_aircraft_flight_log_path(aircraft), class: "btn-primary" %><% end %>
|
||||
<% if can?(:report_squawks) %><%= link_to t(".report_squawk"), new_aircraft_squawk_path(aircraft), class: "btn-secondary" %><% end %>
|
||||
<%= more_menu do %>
|
||||
<%= link_to t(".status_report"), aircraft_report_path(aircraft), class: "menu-item" %>
|
||||
<% if owner? %>
|
||||
<%= link_to t(".access_sharing"), aircraft_aircraft_roles_path(aircraft), class: "menu-item" %>
|
||||
<%= link_to t(".edit_aircraft"), edit_aircraft_path(aircraft), class: "menu-item" %>
|
||||
<% if can?(:manage_people) || can?(:manage_sharing) || can?(:export_data) %><%= link_to t(".access_sharing"), aircraft_aircraft_roles_path(aircraft), class: "menu-item" %><% end %>
|
||||
<% if can?(:edit_aircraft) %><%= link_to t(".edit_aircraft"), edit_aircraft_path(aircraft), class: "menu-item" %><% end %>
|
||||
<% if can?(:export_data) %>
|
||||
<%= 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 } %>
|
||||
<% end %>
|
||||
|
||||
@@ -29,6 +29,6 @@
|
||||
<%= link_to t(".cancel"), aircraft_squawks_path(aircraft), class: "btn-secondary" %>
|
||||
</div>
|
||||
<% 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>
|
||||
<% end %>
|
||||
@@ -14,13 +14,13 @@
|
||||
<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-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 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 %>
|
||||
<%= 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 %>
|
||||
<% 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>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<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-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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<section class="card">
|
||||
<div class="card-header">
|
||||
<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>
|
||||
<% if @current %>
|
||||
<dl class="card-body grid grid-cols-2 gap-x-4 gap-y-2 text-sm">
|
||||
@@ -24,14 +24,14 @@
|
||||
<section class="card">
|
||||
<div class="card-header">
|
||||
<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>
|
||||
<% if @current && setup.configured? %>
|
||||
<%= render "weight_balance_records/calculator", record: @current, setup: setup %>
|
||||
<% elsif !@current %>
|
||||
<%= empty_state t(".record_the_current_weight_balance") %>
|
||||
<% 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 %>
|
||||
</section>
|
||||
</div>
|
||||
@@ -52,7 +52,7 @@
|
||||
<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.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>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
Reference in new issue
Block a user