Files
simple-aircraft-manager-rails/app/controllers/aircraft_roles_controller.rb
T
rickyandClaude Opus 5.5 89ed0a76f9 Move all user-facing text into config/locales/en.yml for localization
- Views use lazy t(".key") lookups; sentences with values or links stay
  whole (interpolation, _html keys); counts use one/other plurals
- Stored-value labels (statuses, types, priorities...) are LabelSets read
  from labels: in the current locale; field names and validation messages
  under activerecord:; flash and activity text under flash:
- Services, models, helpers, mailer subjects, the logbook PDF, procedures
  templates, records package README and transcription warnings localized;
  the PDF reuses LogbookEntry#certification_statement instead of a copy
- Scripts read js: strings from a JSON tag via app/javascript/i18n.js
- Dates through I18n.l (app, weekday, month_year, long formats); html lang
  follows the locale
- APP_LOCALE picks the language (falls back to English); missing
  translations raise in development and tests
- README: Translating section and APP_LOCALE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 22:08:20 -05:00

55 lines
2.3 KiB
Ruby

# Owner-only: manage who can access the aircraft, and its public share links.
class AircraftRolesController < ApplicationController
include AircraftScoped
before_action :require_owner!
def index
@roles = @aircraft.roles.includes(:user).order(:role, :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
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")
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")
end
private
def demoting_last_owner?(role, new_role)
role.role == "owner" && new_role != "owner" && @aircraft.roles.owners.count <= 1
end
end