Skip to content

Commit d8885ff

Browse files
authored
Merge pull request opf#18419 from opf/bugfix/62429-missing-fields
Work Package Subject Patterns - Adds Missing Fields
2 parents 1f57cdc + f4280bc commit d8885ff

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

app/models/types/pattern_resolver.rb

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def stringify(value)
5656
case value
5757
when Date, Time, DateTime
5858
value.strftime("%Y-%m-%d")
59+
when Array
60+
value.join(", ")
5961
when NilClass
6062
"NA"
6163
else

app/models/types/patterns/token_property_mapper.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ class TokenPropertyMapper
3939

4040
TOKEN_PROPERTY_MAP = IceNine.deep_freeze(
4141
{
42+
id: { fn: ->(wp) { wp.id }, label: -> { WorkPackage.human_attribute_name(:id) } },
4243
accountable: { fn: ->(wp) { wp.responsible&.name }, label: -> { WorkPackage.human_attribute_name(:responsible) } },
4344
assignee: { fn: ->(wp) { wp.assigned_to&.name }, label: -> { WorkPackage.human_attribute_name(:assigned_to) } },
4445
author: { fn: ->(wp) { wp.author&.name }, label: -> { WorkPackage.human_attribute_name(:author) } },
4546
category: { fn: ->(wp) { wp.category&.name }, label: -> { WorkPackage.human_attribute_name(:category) } },
4647
creation_date: { fn: ->(wp) { wp.created_at }, label: -> { WorkPackage.human_attribute_name(:created_at) } },
4748
estimated_time: { fn: ->(wp) { wp.estimated_hours }, label: -> { WorkPackage.human_attribute_name(:estimated_hours) } },
4849
finish_date: { fn: ->(wp) { wp.due_date }, label: -> { WorkPackage.human_attribute_name(:due_date) } },
49-
parent: { fn: ->(wp) { wp.parent&.id }, label: -> { WorkPackage.human_attribute_name(:parent) } },
50+
parent_id: { fn: ->(wp) { wp.parent&.id }, label: -> { WorkPackage.human_attribute_name(:parent_id) } },
51+
parent_assignee: { fn: ->(wp) { wp.parent&.assigned_to&.name }, label: -> {
52+
WorkPackage.human_attribute_name(:assigned_to)
53+
} },
5054
parent_author: { fn: ->(wp) { wp.parent&.author&.name }, label: -> { WorkPackage.human_attribute_name(:author) } },
5155
parent_category: { fn: ->(wp) { wp.parent&.category&.name },
5256
label: -> { WorkPackage.human_attribute_name(:category) } },
@@ -57,6 +61,7 @@ class TokenPropertyMapper
5761
parent_finish_date: { fn: ->(wp) { wp.parent&.due_date },
5862
label: -> { WorkPackage.human_attribute_name(:due_date) } },
5963
parent_priority: { fn: ->(wp) { wp.parent&.priority }, label: -> { WorkPackage.human_attribute_name(:priority) } },
64+
parent_subject: { fn: ->(wp) { wp.parent&.subject }, label: -> { WorkPackage.human_attribute_name(:subject) } },
6065
priority: { fn: ->(wp) { wp.priority }, label: -> { WorkPackage.human_attribute_name(:priority) } },
6166
project: { fn: ->(wp) { wp.project_id }, label: -> { WorkPackage.human_attribute_name(:project) } },
6267
project_active: { fn: ->(wp) { wp.project&.active? }, label: -> { Project.human_attribute_name(:active) } },
@@ -111,7 +116,7 @@ def work_package_cfs_for(type)
111116
end
112117

113118
def all_work_package_cfs
114-
WorkPackageCustomField.where(multi_value: false).where.not(field_format: %w[text bool link empty]).order(:name)
119+
WorkPackageCustomField.where.not(field_format: %w[text bool link empty]).order(:name)
115120
end
116121

117122
def project_attributes

spec/models/types/pattern_resolver_spec.rb

+12-3
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,32 @@
6161

6262
context "when the pattern has custom fields" do
6363
let(:custom_field) { create(:string_wp_custom_field) }
64-
let(:type) { create(:type, custom_fields: [custom_field]) }
65-
let(:project) { create(:project, types: [type], work_package_custom_fields: [custom_field]) }
64+
let(:multi_value_field) { create(:multi_list_wp_custom_field) }
65+
let(:type) { create(:type, custom_fields: [custom_field, multi_value_field]) }
66+
let(:project) { create(:project, types: [type], work_package_custom_fields: [custom_field, multi_value_field]) }
6667
let(:project_custom_field) { create(:project_custom_field, projects: [project], field_format: "string") }
6768

6869
let(:subject_pattern) do
6970
"{{project_custom_field_#{project_custom_field.id}}} A custom field value: {{custom_field_#{custom_field.id}}}"
7071
end
7172

7273
let(:work_package) do
73-
create(:work_package, type:, project:, custom_values: { custom_field.id => "Important Information" })
74+
create(:work_package, type:, project:,
75+
custom_values: { custom_field.id => "Important Information",
76+
multi_value_field.id => multi_value_field.possible_values.take(2) })
7477
end
7578

7679
before do
7780
project.public_send :"custom_field_#{project_custom_field.id}=", "PROSPEC"
7881
project.save
7982
end
8083

84+
it "multi value fields are joined by comma" do
85+
subject_pattern = "MCF: {{custom_field_#{multi_value_field.id}}}"
86+
resolver = described_class.new(subject_pattern)
87+
expect(resolver.resolve(work_package)).to eq("MCF: A, B")
88+
end
89+
8190
it "resolves the pattern" do
8291
User.current = SystemUser.first
8392

spec/models/types/patterns/token_property_mapper_spec.rb

+17-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
RSpec.describe Types::Patterns::TokenPropertyMapper do
3434
shared_let(:responsible) { create(:user, firstname: "Responsible") }
3535
shared_let(:assignee) { create(:user, firstname: "Assignee") }
36+
shared_let(:parent_assignee) { create(:user, firstname: "Parent", lastname: "Assignee") }
3637

3738
shared_let(:category) { create(:category) }
3839

3940
shared_let(:project) { create(:project, parent: create(:project), status_code: 1, status_explanation: "A Mess") }
4041

4142
shared_let(:work_package_parent) do
42-
create(:work_package, project:, category:, start_date: Date.yesterday, estimated_hours: 120, due_date: 3.months.from_now)
43+
create(:work_package, project:, category:, start_date: Date.yesterday, estimated_hours: 120,
44+
due_date: 3.months.from_now, assigned_to: parent_assignee)
4345
end
4446

4547
shared_let(:work_package) do
@@ -51,8 +53,16 @@
5153
create(:string_wp_custom_field).tap do |custom_field|
5254
project.work_package_custom_fields << custom_field
5355
work_package.type.custom_fields << custom_field
56+
end
57+
end
58+
59+
shared_let(:mult_list_custom_field) do
60+
create(:multi_list_wp_custom_field).tap do
61+
project.work_package_custom_fields << it
62+
work_package.type.custom_fields << it
5463

55-
create(:work_package_custom_value, custom_field:, customized: work_package, value: "test")
64+
work_package.send(:"custom_field_#{it.id}=", it.possible_values.take(2))
65+
work_package.save
5666
end
5767
end
5868

@@ -63,6 +73,11 @@
6373
end
6474
end
6575

76+
it "multi value fields are supported" do
77+
function = described_class.new.fetch :"custom_field_#{mult_list_custom_field.id}"
78+
expect(function.call(work_package)).to eq(%w[A B])
79+
end
80+
6681
it "returns all possible tokens" do
6782
cf = string_custom_field
6883
tokens = described_class.new.tokens_for_type(work_package.type)

0 commit comments

Comments
 (0)