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
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user