Fill the vehicle into issue subjects (<VEHICLE>)

An issue subject containing the placeholder (e.g. an issue template's "Frame Evaluation // <VEHICLE>") gets
the issue's vehicle when it's saved with one: on creation, or the first save after a vehicle is added
(journaled like any subject change). The placeholder is a plugin setting, "Vehicle in subjects": <VEHICLE>
by default (also for settings saved before it existed), blank turns it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-02 18:23:07 -05:00
1 parent ff6522ad77
commit 2074ec65b9
6 files changed
+32 -1

No files matched your search

+10
View File
@@ -22,10 +22,20 @@ module Vehicles
# The vehicle must belong to the issue's customer. Only checked when either changes, so older
# issues with a mismatch don't block unrelated edits.
validate :vehicle_matches_customer, if: -> { will_save_change_to_vehicle_id? || will_save_change_to_customer_id? }
# A subject with the placeholder (e.g. from a template) gets the vehicle once one is assigned
before_validation :fill_subject_vehicle
end
private
def fill_subject_vehicle
placeholder = Vehicle.subject_placeholder
return if placeholder.nil? || vehicle.nil? || !subject.to_s.include?(placeholder)
self.subject = subject.gsub(placeholder, vehicle.to_s)
end
def vehicle_matches_customer
return if vehicle_id.blank?