Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#62217] allow custom fields that are not enabled in project

Eric Schubertb9c3a7de9e94
diff --git a/app/models/types/patterns/token_property_mapper.rb b/app/models/types/patterns/token_property_mapper.rb
index a739a0e3fec..f9e8aa18118 100644
--- a/app/models/types/patterns/token_property_mapper.rb
+++ b/app/models/types/patterns/token_property_mapper.rb
@@ -33,6 +33,7 @@ module Types
class TokenPropertyMapper
DEFAULT_FUNCTION = ->(key, context) do
return nil if context.nil?
+ return nil unless context.respond_to?(key.to_sym)
context.public_send(key.to_sym)
end.curry
diff --git a/spec/models/types/patterns/token_property_mapper_spec.rb b/spec/models/types/patterns/token_property_mapper_spec.rb
index 8a4c9b8b318..3340c3d71d6 100644
--- a/spec/models/types/patterns/token_property_mapper_spec.rb
+++ b/spec/models/types/patterns/token_property_mapper_spec.rb
@@ -66,6 +66,12 @@ RSpec.describe Types::Patterns::TokenPropertyMapper do
end
end
+ shared_let(:not_activated_custom_field) do
+ create(:boolean_wp_custom_field).tap do |custom_field|
+ work_package.type.custom_fields << custom_field
+ end
+ end
+
described_class::TOKEN_PROPERTY_MAP.each_pair do |key, details|
it "the token named #{key} resolves successfully" do
expect { details[:fn].call(work_package) }.not_to raise_error
@@ -78,6 +84,12 @@ RSpec.describe Types::Patterns::TokenPropertyMapper do
expect(function.call(work_package)).to eq(%w[A B])
end
+ it "must return nil if custom field is not activated in project" do
+ function = described_class.new.fetch :"custom_field_#{not_activated_custom_field.id}"
+ expect { function.call(work_package) }.not_to raise_error
+ expect(function.call(work_package)).to be_nil
+ end
+
it "returns all possible tokens" do
cf = string_custom_field
tokens = described_class.new.tokens_for_type(work_package.type)