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

avoid having the estimates and time section for milestone types

ulfertsf9ca863e66f1
diff --git a/app/models/type/attribute_groups.rb b/app/models/type/attribute_groups.rb
index a54aa240da4..13315a7fd2f 100644
--- a/app/models/type/attribute_groups.rb
+++ b/app/models/type/attribute_groups.rb
@@ -117,6 +117,7 @@ module Type::AttributeGroups
# the default group map.
def default_attribute_groups
values = work_package_attributes_by_default_group_key
+ values.reject! { |k, _| k == :estimates_and_time } if is_milestone?
default_groups.keys.each_with_object([]) do |groupkey, array|
members = values[groupkey]
@@ -167,6 +168,7 @@ module Type::AttributeGroups
# it will put them into the other group.
def work_package_attributes_by_default_group_key
active_cfs = active_custom_field_attributes
+
work_package_attributes
.keys
.select { |key| default_attribute?(active_cfs, key) }
diff --git a/app/services/base_type_service.rb b/app/services/base_type_service.rb
index e04135346b3..ac248bd4a44 100644
--- a/app/services/base_type_service.rb
+++ b/app/services/base_type_service.rb
@@ -71,12 +71,13 @@ class BaseTypeService
def set_params_and_validate(params)
# Only set attribute groups when it exists
# (Regression #28400)
- unless params[:attribute_groups].nil?
- set_attribute_groups(params)
- end
+ set_attribute_groups(params) unless params[:attribute_groups].nil?
# This should go before `set_scalar_params` call to get the
- # project_ids, custom_field_ids diffs from the type and the params
+ # project_ids, custom_field_ids diffs from the type and the params.
+ # For determining the active custom fields for the type, it is necessary
+ # to know whether the type is a milestone or not.
+ set_milestone_param(params) unless params[:is_milestone].nil?
set_active_custom_fields
if params[:project_ids].present?
@@ -88,6 +89,10 @@ class BaseTypeService
validate_and_save(type, user)
end
+ def set_milestone_param(params)
+ type.is_milestone = params[:is_milestone]
+ end
+
def set_scalar_params(params)
type.attributes = params.except(:attribute_groups)
end
diff --git a/spec/services/create_type_service_spec.rb b/spec/services/create_type_service_spec.rb
index b5e1c774c1e..f0ebd9f9349 100644
--- a/spec/services/create_type_service_spec.rb
+++ b/spec/services/create_type_service_spec.rb
@@ -36,5 +36,25 @@ RSpec.describe CreateTypeService do
let(:instance) { described_class.new(user) }
let(:service_call) { instance.call({ name: "foo" }.merge(params), {}) }
- it_behaves_like "type service"
+ it_behaves_like "type service" do
+ describe "default attribute_groups" do
+ context "for a milestone type" do
+ let(:params) { { is_milestone: true } }
+
+ it "does not include the progress attribute group" do
+ expect(service_call.result.attribute_groups.map(&:key))
+ .to eql %i[people details costs]
+ end
+ end
+
+ context "for a non milestone type" do
+ let(:params) { { is_milestone: false } }
+
+ it "does include the progress attribute group" do
+ expect(service_call.result.attribute_groups.map(&:key))
+ .to eql %i[people estimates_and_time details costs]
+ end
+ end
+ end
+ end
end