mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
Owners can invite mechanics again; who adds aircraft is an admin setting
- Admin → Settings → Who can add aircraft: administrators only (the default) or everyone. Adding an aircraft or importing a .sam.zip makes you its Owner, so this decides who can become one. - A signing invitation from an Owner of the aircraft (or an administrator) lets the outside mechanic create an account for the invited address again, with a password or by signing in with SSO; checked when it's used. Others' signing invitations still need an existing account, and say so. - Docs: who makes accounts, the new setting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
19bc3efa19
commit
9a20c91f5e
30 files changed
+219
-40
No files matched your search
@@ -0,0 +1,43 @@
|
||||
require "test_helper"
|
||||
|
||||
# Who can add aircraft (Admin → Settings): adding or importing one makes you
|
||||
# its Owner, who can bring in outside mechanics, so by default only
|
||||
# administrators can.
|
||||
class AddingAircraftTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = create_user("user@example.com")
|
||||
@admin = create_user("admin@example.com", admin: true)
|
||||
end
|
||||
|
||||
test "by default only administrators add or import aircraft" do
|
||||
sign_in @user
|
||||
get root_path
|
||||
assert_select "a[href=?]", new_aircraft_path, 0
|
||||
assert_select "a[href=?]", new_aircraft_import_path, 0
|
||||
assert_includes response.body, "An administrator adds aircraft"
|
||||
get new_aircraft_path
|
||||
assert_redirected_to root_path
|
||||
post aircraft_index_path, params: { aircraft: { tail_number: "N1", tach_time: 50 } }
|
||||
assert_not Aircraft.exists?(tail_number: "N1")
|
||||
get new_aircraft_import_path
|
||||
assert_redirected_to root_path
|
||||
|
||||
sign_in @admin
|
||||
post aircraft_index_path, params: { aircraft: { tail_number: "N1", tach_time: 50 } }
|
||||
assert_equal "owner", @admin.role_for(Aircraft.find_by!(tail_number: "N1")).key
|
||||
end
|
||||
|
||||
test "an administrator can let everyone add aircraft" do
|
||||
sign_in @admin
|
||||
get edit_admin_settings_path
|
||||
assert_select "select[name='settings[anyone_adds_aircraft]'] option[selected]", text: "Administrators only"
|
||||
patch admin_settings_path, params: { settings: { anyone_adds_aircraft: 1 } }
|
||||
assert Setting.anyone_adds_aircraft?
|
||||
|
||||
sign_in @user
|
||||
get root_path
|
||||
assert_select "a[href=?]", new_aircraft_path
|
||||
post aircraft_index_path, params: { aircraft: { tail_number: "N2", tach_time: 50 } }
|
||||
assert_equal "owner", @user.role_for(Aircraft.find_by!(tail_number: "N2")).key
|
||||
end
|
||||
end
|
||||
@@ -4,6 +4,7 @@ class AircraftArchiveFlowTest < ActionDispatch::IntegrationTest
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
setup do
|
||||
Setting.update_integers("anyone_adds_aircraft" => 1) # anyone may add aircraft here
|
||||
@owner = create_user("owner@example.com")
|
||||
@pilot = create_user("pilot@example.com")
|
||||
@a = create_aircraft(owner: @owner, pilot: @pilot, tail_number: "N12345", make: "Cessna")
|
||||
|
||||
@@ -159,7 +159,6 @@ class ElectronicSignaturesTest < ActionDispatch::IntegrationTest
|
||||
post aircraft_logbook_entry_signing_invitations_path(@a, @entry), params: { signing_invitation: { email: "Outside@Example.com", message: "Thanks!" } }
|
||||
end
|
||||
end
|
||||
assert_match "They don't have an account here yet", flash[:notice]
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
assert_equal [ "outside@example.com" ], mail.to
|
||||
path = mail.text_part.body.to_s[%r{http://example\.com(/sign/[\w-]+)}, 1]
|
||||
@@ -167,16 +166,8 @@ class ElectronicSignaturesTest < ActionDispatch::IntegrationTest
|
||||
|
||||
get path
|
||||
assert_includes response.body, "sign in as <strong>outside@example.com</strong>"
|
||||
assert_includes response.body, "no account for outside@example.com yet" # a signing link doesn't make accounts
|
||||
post "#{path}/account", params: { name: "Olive Outside", password: "longpassword1", password_confirmation: "longpassword1" }
|
||||
assert_response :not_found
|
||||
assert_not User.exists?(email_address: "outside@example.com")
|
||||
|
||||
# The administrator adds their account; they sign in and come back to the link.
|
||||
User.create!(email_address: "outside@example.com", name: "Olive Outside", password: "longpassword1")
|
||||
get path
|
||||
post session_path, params: { email_address: "outside@example.com", password: "longpassword1" }
|
||||
assert_redirected_to "http://www.example.com#{path}"
|
||||
post "#{path}/account", params: { name: "Olive Outside", password: "longpassword1", password_confirmation: "longpassword1" } # an Owner's invitation
|
||||
assert_redirected_to path
|
||||
follow_redirect!
|
||||
assert_select "form[action='#{certificates_path(return_to: path)}']" # add a certificate first
|
||||
post certificates_path(return_to: path), params: { user_certificate: { kind: "IA", number: "2222222" } }
|
||||
@@ -223,4 +214,23 @@ class ElectronicSignaturesTest < ActionDispatch::IntegrationTest
|
||||
patch enable_admin_user_path(@mech)
|
||||
refute @mech.reload.disabled?
|
||||
end
|
||||
|
||||
test "a signing invitation from someone who isn't an Owner doesn't make accounts" do
|
||||
mechanic = create_user("shop@example.com")
|
||||
@a.roles.create!(user: mechanic, role: "mechanic")
|
||||
sign_in mechanic
|
||||
perform_enqueued_jobs do
|
||||
post aircraft_logbook_entry_signing_invitations_path(@a, @entry), params: { signing_invitation: { email: "outside2@example.com" } }
|
||||
end
|
||||
assert_match "They don't have an account here yet", flash[:notice]
|
||||
path = ActionMailer::Base.deliveries.last.text_part.body.to_s[%r{http://example\.com(/sign/[\w-]+)}, 1]
|
||||
assert_match "if you don't have one, ask the owner", ActionMailer::Base.deliveries.last.text_part.body.to_s
|
||||
delete session_path
|
||||
|
||||
get path
|
||||
assert_includes response.body, "no account for outside2@example.com yet"
|
||||
assert_select "form[action$='/account']", 0
|
||||
post "#{path}/account", params: { name: "X", password: "longpassword1", password_confirmation: "longpassword1" }
|
||||
assert_not User.exists?(email_address: "outside2@example.com")
|
||||
end
|
||||
end
|
||||
@@ -41,6 +41,7 @@ class MalformedInputTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "text where a file belongs, or a tampered upload reference, is turned away politely" do
|
||||
Setting.update_integers("anyone_adds_aircraft" => 1) # anyone may add aircraft here
|
||||
post import_aircraft_oil_analyses_path(@a), params: { report: "not a file" }
|
||||
assert_redirected_to new_aircraft_oil_analysis_path(@a)
|
||||
post aircraft_imports_path, params: { archive: "not a file" }
|
||||
|
||||
@@ -31,6 +31,7 @@ class PagesTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "owner can render every page" do
|
||||
Setting.update_integers("anyone_adds_aircraft" => 1) # anyone may add aircraft here
|
||||
a = @a
|
||||
paths = [
|
||||
root_path, aircraft_path(a), new_aircraft_path, edit_aircraft_path(a),
|
||||
|
||||
@@ -21,6 +21,7 @@ class SetupTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "create aircraft makes creator the owner" do
|
||||
Setting.update_integers("anyone_adds_aircraft" => 1) # anyone may add aircraft here
|
||||
user = create_user
|
||||
sign_in user
|
||||
post aircraft_index_path, params: { aircraft: { tail_number: "N1", tach_time: 50 } }
|
||||
|
||||
@@ -169,4 +169,22 @@ class SsoTest < ActionDispatch::IntegrationTest
|
||||
assert_not User.exists?(email_address: "someone.else@example.com")
|
||||
assert_equal 0, invitation.reload.uses_count
|
||||
end
|
||||
|
||||
test "an Owner's signing invitation makes the mechanic's account by signing in with SSO, for its address only" do
|
||||
ENV.delete("OIDC_AUTO_CREATE_USERS")
|
||||
owner = create_user("owner3@example.com")
|
||||
aircraft = create_aircraft(owner: owner, tail_number: "N888CD")
|
||||
entry = aircraft.logbook_entries.create!(date: Date.new(2026, 10, 1), log_type: "AC", entry_type: "MAINTENANCE", aircraft_hours_at_entry: 1000, text: "Oil changed.")
|
||||
invitation = entry.signing_invitations.create!(email: "mech@example.com", invited_by: owner)
|
||||
|
||||
get invited_signing_path(invitation.token)
|
||||
mock(uid: "sub-other", email: "not.mech@example.com")
|
||||
sso_sign_in
|
||||
assert_not User.exists?(email_address: "not.mech@example.com")
|
||||
|
||||
get invited_signing_path(invitation.token)
|
||||
mock(uid: "sub-mech", email: "mech@example.com", name: "Mo Mechanic")
|
||||
sso_sign_in
|
||||
assert_equal "sub-mech", User.find_by!(email_address: "mech@example.com").sso_uid
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user