Skip to content

Commit efe27bf

Browse files
committed
Map deprecated version macro to target versions
workPackageValue:X:version now renders all target versions of the work package, single-line by default so legacy macros keep their inline shape within existing content. Applies to both the web and export render paths.
1 parent c6a6000 commit efe27bf

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

app/models/work_package/exports/macros/attributes.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,25 @@ def self.resolve_value(obj, attribute, disabled_rich_text_fields, layout: nil)
175175
custom_field = find_custom_field(obj, attribute)
176176

177177
attribute_name = convert_to_attribute_name(custom_field, attribute, obj)
178+
attribute_name, layout = map_legacy_version(attribute_name, layout, obj)
178179
return " " unless can_view_attribute?(custom_field, obj, attribute_name)
179180

180181
is_rich_text = custom_field&.formattable? || disabled_rich_text_fields.include?(attribute_name.to_sym)
181182
[format_attribute_value(attribute_name, obj.class, obj, is_rich_text, layout), is_rich_text]
182183
end
183184

185+
##
186+
# The deprecated version attribute renders the work package's target
187+
# versions, on a single line by default so legacy macros keep their
188+
# inline shape within existing content.
189+
def self.map_legacy_version(attribute_name, layout, obj)
190+
if obj.is_a?(WorkPackage) && attribute_name == "version"
191+
["target_versions", layout || "singleline"]
192+
else
193+
[attribute_name, layout]
194+
end
195+
end
196+
184197
def self.can_view_attribute?(custom_field, obj, attribute_name)
185198
custom_field || allowed_to_view_attribute?(obj, attribute_name)
186199
end

frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ export class AttributeValueMacroComponent implements OnInit {
127127

128128
const schema = await this.schemaCache.ensureLoaded(resource);
129129
const proxied = this.schemaCache.proxied(resource, schema);
130-
const attribute = schema.attributeFromLocalizedName(attributeName) ?? this.dateAttribute(resource, proxied, attributeName);
130+
let attribute = schema.attributeFromLocalizedName(attributeName) ?? this.dateAttribute(resource, proxied, attributeName);
131+
132+
// The deprecated version attribute renders the work package's target
133+
// versions, single-line by default so legacy macros keep their inline shape.
134+
if (resource._type === 'WorkPackage' && attribute === 'version') {
135+
attribute = 'targetVersions';
136+
this.layout = this.layout ?? 'singleline';
137+
}
138+
131139
const fieldSchema = proxied.ofProperty(attribute) as IFieldSchema|undefined;
132140

133141
if (fieldSchema) {

spec/models/exports/pdf/common/macro_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,41 @@
369369
end
370370
end
371371

372+
describe "with target versions" do
373+
shared_let(:version_one) { create(:version, project:, name: "1.0") }
374+
shared_let(:version_two) { create(:version, project:, name: "2.0") }
375+
376+
before do
377+
create(:work_package_version, work_package:, version: version_one)
378+
create(:work_package_version, work_package:, version: version_two)
379+
end
380+
381+
describe "with targetVersions attribute" do
382+
let(:markdown) { "workPackageValue:#{work_package.id}:targetVersions" }
383+
384+
it "outputs one version per line" do
385+
# the association carries no order, so compare the lines as a set
386+
expect(formatted.split(" \n")).to match_array(%w[1.0 2.0])
387+
end
388+
end
389+
390+
describe "with legacy version attribute" do
391+
let(:markdown) { "workPackageValue:#{work_package.id}:version" }
392+
393+
it "outputs all target versions on a single line" do
394+
expect(formatted.split(", ")).to match_array(%w[1.0 2.0])
395+
end
396+
end
397+
398+
describe "with legacy version attribute and multiline layout" do
399+
let(:markdown) { "workPackageValue:#{work_package.id}:version:multiline" }
400+
401+
it "outputs one version per line" do
402+
expect(formatted.split(" \n")).to match_array(%w[1.0 2.0])
403+
end
404+
end
405+
end
406+
372407
describe "with specific work package ID and attribute" do
373408
let(:markdown) { "workPackageValue:#{work_package.id}:subject" }
374409

0 commit comments

Comments
 (0)