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