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

[59174] Fixed group_by hierarchy for multi select field

Andreas Pfohl640f983daa7d
diff --git a/app/models/custom_field/hierarchy/hierarchy_item_adapter.rb b/app/models/custom_field/hierarchy/hierarchy_item_adapter.rb
new file mode 100644
index 00000000000..7db6d539d3f
--- /dev/null
+++ b/app/models/custom_field/hierarchy/hierarchy_item_adapter.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+class CustomField::Hierarchy::HierarchyItemAdapter
+ attr_reader :name
+
+ delegate :id, :label, :short, :to_s, to: :item
+
+ def initialize(item:)
+ @item = item
+ @name = item.label
+ end
+
+ private
+
+ attr_accessor :item
+end
diff --git a/app/models/queries/filters/shared/custom_fields/hierarchy.rb b/app/models/queries/filters/shared/custom_fields/hierarchy.rb
index 81538bc4bdb..c29e545b9be 100644
--- a/app/models/queries/filters/shared/custom_fields/hierarchy.rb
+++ b/app/models/queries/filters/shared/custom_fields/hierarchy.rb
@@ -40,24 +40,9 @@ module Queries
def value_objects
CustomField::Hierarchy::Item
.where(id: @values)
- .map { |item| HierarchyItemFilterAdapter.new(item:) }
+ .map { |item| CustomField::Hierarchy::HierarchyItemAdapter.new(item:) }
end
end
-
- class HierarchyItemFilterAdapter
- attr_reader :name
-
- delegate :id, to: :item
-
- def initialize(item:)
- @item = item
- @name = item.label
- end
-
- private
-
- attr_accessor :item
- end
end
end
end
diff --git a/app/models/query/results/group_by.rb b/app/models/query/results/group_by.rb
index 045a3b8669c..ed741e8f255 100644
--- a/app/models/query/results/group_by.rb
+++ b/app/models/query/results/group_by.rb
@@ -117,8 +117,11 @@ module ::Query::Results::GroupBy
CustomFields::Hierarchy::HierarchicalItemService
.new
.get_descendants(item: custom_field.hierarchy_root, include_self: false)
- .fmap { |list| list.filter { |item| keys.include?(item.label) } }
- .fmap { |list| list.index_by(&:label) }
+ .fmap do |list|
+ list.map { |item| CustomField::Hierarchy::HierarchyItemAdapter.new(item:) }
+ .filter { |item| keys.include?(item.label) }
+ .index_by(&:label)
+ end
.either(
->(list) { list },
->(error) do
@@ -127,6 +130,7 @@ module ::Query::Results::GroupBy
end
)
end
+
# rubocop:enable Metrics/AbcSize
def transform_list_custom_field_keys(custom_field, groups)
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index cfe1a35ac6a..42824f82b57 100644
--- a/lib/api/v3/utilities/path_helper.rb
+++ b/lib/api/v3/utilities/path_helper.rb
@@ -210,17 +210,12 @@ module API
"#{root}/custom_fields/#{id}"
end
- # Needed as the method is derived from the name of the class for the query API representation.
- def self.custom_field_hierarchy_item(id)
- custom_field_item(id)
- end
-
def self.custom_field_item(id)
"#{root}/custom_field_items/#{id}"
end
# API::V3::Queries::Filters::QueryFilterInstanceRepresenter need a path derived from a class name.
- def self.hierarchy_item_filter_adapter(id)
+ def self.hierarchy_item_adapter(id)
custom_field_item(id)
end
diff --git a/lib/api/v3/utilities/resource_link_generator.rb b/lib/api/v3/utilities/resource_link_generator.rb
index bb3b003008e..d1901e6b27f 100644
--- a/lib/api/v3/utilities/resource_link_generator.rb
+++ b/lib/api/v3/utilities/resource_link_generator.rb
@@ -59,6 +59,8 @@ module API
:activity
when Changeset
:revision
+ when ::CustomField::Hierarchy::HierarchyItemAdapter
+ :custom_field_item
else
record.class.model_name.singular
end