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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#66961] use scored list custom fields in work packages
Eric Schubertd38f5220c175
diff --git a/app/forms/custom_fields/custom_field_rendering.rb b/app/forms/custom_fields/custom_field_rendering.rbindex 2f3072d0bdc..2fd18f71dbf 100644--- a/app/forms/custom_fields/custom_field_rendering.rb+++ b/app/forms/custom_fields/custom_field_rendering.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -36,7 +36,7 @@ module CustomFields::CustomFieldRendering"text" => "CustomFields::Inputs::Text","int" => "CustomFields::Inputs::Int","float" => "CustomFields::Inputs::Float",- %w[hierarchy list] => "CustomFields::Inputs::SingleSelectList",+ %w[hierarchy scored_list list] => "CustomFields::Inputs::SingleSelectList","date" => "CustomFields::Inputs::Date","bool" => "CustomFields::Inputs::Bool","user" => "CustomFields::Inputs::SingleUserSelectList",@@ -45,7 +45,7 @@ module CustomFields::CustomFieldRendering).freezeMULTI_VALUE_INPUT_CLASS_NAMES = OpenProject::MultiKeyHash.expand(- ["hierarchy", "list"] => "CustomFields::Inputs::MultiSelectList",+ %w[hierarchy scored_list list] => "CustomFields::Inputs::MultiSelectList","user" => "CustomFields::Inputs::MultiUserSelectList","version" => "CustomFields::Inputs::MultiVersionSelectList").freezediff --git a/app/forms/custom_fields/inputs/multi_select_list.rb b/app/forms/custom_fields/inputs/multi_select_list.rbindex bccbfd57958..a280c24861e 100644--- a/app/forms/custom_fields/inputs/multi_select_list.rb+++ b/app/forms/custom_fields/inputs/multi_select_list.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -59,8 +59,8 @@ class CustomFields::Inputs::MultiSelectList < CustomFields::Inputs::Base::Autocodef list_itemscase @custom_field.field_format- when "hierarchy"- hierarchy_items.map do |item|+ when "hierarchy", "scored_list"+ hierarchical_list_items.map do |item|{label: item.ancestry_path,value: item.id,@@ -78,7 +78,7 @@ class CustomFields::Inputs::MultiSelectList < CustomFields::Inputs::Base::Autocoendend- def hierarchy_items+ def hierarchical_list_itemsCustomFields::Hierarchy::HierarchicalItemService.new.get_descendants(item: @custom_field.hierarchy_root, include_self: false).value_or([])diff --git a/app/forms/custom_fields/inputs/single_select_list.rb b/app/forms/custom_fields/inputs/single_select_list.rbindex 137c249c590..8030485f635 100644--- a/app/forms/custom_fields/inputs/single_select_list.rb+++ b/app/forms/custom_fields/inputs/single_select_list.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -54,8 +54,8 @@ class CustomFields::Inputs::SingleSelectList < CustomFields::Inputs::Base::Autocdef list_itemscase @custom_field.field_format- when "hierarchy"- hierarchy_items.map do |item|+ when "hierarchy", "scored_list"+ hierarchical_list_items.map do |item|{label: item.ancestry_path,value: item.id,@@ -73,7 +73,7 @@ class CustomFields::Inputs::SingleSelectList < CustomFields::Inputs::Base::Autocendend- def hierarchy_items+ def hierarchical_list_itemsCustomFields::Hierarchy::HierarchicalItemService.new.get_descendants(item: @custom_field.hierarchy_root, include_self: false).value_or([])diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rbindex 172f224d1ea..73ce152b78f 100644--- a/app/helpers/custom_fields_helper.rb+++ b/app/helpers/custom_fields_helper.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -99,7 +99,7 @@ module CustomFieldsHelperid: field_id,multiple: custom_field.multi_value?,include_blank: I18n.t(:label_no_change_option))- when "hierarchy"+ when "hierarchy", "scored_list"base_options = []result = CustomFields::Hierarchy::HierarchicalItemService.new.get_descendants(item: custom_field.hierarchy_root, include_self: false)diff --git a/app/models/custom_field/order_statements.rb b/app/models/custom_field/order_statements.rbindex 45d02cc493f..cb5bafaaa73 100644--- a/app/models/custom_field/order_statements.rb+++ b/app/models/custom_field/order_statements.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -36,7 +36,7 @@ module CustomField::OrderStatements"list" => :join_for_order_by_list_sql,"user" => :join_for_order_by_user_sql,"version" => :join_for_order_by_version_sql,- "hierarchy" => :join_for_order_by_hierarchy_sql+ %w[hierarchy scored_list] => :join_for_order_by_hierarchy_sql).freeze# Returns the expression to use in ORDER BY clause to sort objects by their@@ -70,7 +70,7 @@ module CustomField::OrderStatements# Returns the expression to use in SELECT clause if it differs from one used# to group bydef group_by_select_statement- return unless ["list", "hierarchy"].include?(field_format)+ return unless %w[list hierarchy scored_list].include?(field_format)# MIN needed to not add this column to group by, ANY_VALUE can be used when# minimum required PostgreSQL becomes 16diff --git a/app/models/exports/formatters/custom_field.rb b/app/models/exports/formatters/custom_field.rbindex f5e22a932cb..c0e5c21a034 100644--- a/app/models/exports/formatters/custom_field.rb+++ b/app/models/exports/formatters/custom_field.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -58,7 +58,7 @@ module Exportsvalue == nil ? false : valuewhen "text"object.typed_custom_value_for(custom_field)- when "hierarchy"+ when "hierarchy", "scored_list"HierarchyFormatter.new.format(object, custom_field)elseobject.formatted_custom_value_for(custom_field)diff --git a/app/models/queries/filters/shared/custom_field_filter.rb b/app/models/queries/filters/shared/custom_field_filter.rbindex fa00b8e91ac..058e34d8aec 100644--- a/app/models/queries/filters/shared/custom_field_filter.rb+++ b/app/models/queries/filters/shared/custom_field_filter.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -96,7 +96,7 @@ module Queries::Filters::Shared::CustomFieldFilter::Queries::Filters::Shared::CustomFields::Userwhen "list", "version"::Queries::Filters::Shared::CustomFields::ListOptional- when "hierarchy"+ when "hierarchy", "scored_list"::Queries::Filters::Shared::CustomFields::Hierarchywhen "bool"::Queries::Filters::Shared::CustomFields::Booldiff --git a/app/models/queries/filters/shared/custom_fields/base.rb b/app/models/queries/filters/shared/custom_fields/base.rbindex b92a0bcc031..c966da953d6 100644--- a/app/models/queries/filters/shared/custom_fields/base.rb+++ b/app/models/queries/filters/shared/custom_fields/base.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -91,7 +91,7 @@ module Queries::Filters::Shared:textwhen "date":date- when "hierarchy"+ when "hierarchy", "scored_list":hierarchyelse:stringdiff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rbindex 8072bce619a..a44c9942073 100644--- a/lib/api/v3/utilities/custom_field_injector.rb+++ b/lib/api/v3/utilities/custom_field_injector.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -21,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -46,7 +48,7 @@ module API"scored_list" => "CustomField::Hierarchy::Item"}.freeze- LINK_FORMATS = %w(list user version hierarchy).freeze+ LINK_FORMATS = %w(list user version hierarchy scored_list).freezeNAMESPACE_MAP = {"user" => %w[users groups placeholder_users],@@ -251,9 +253,9 @@ module API# Do not embed list, hierarchies or multi values as their links contain all the# information needed (title and href) already.next if represented.available_custom_fields.exclude?(custom_field) ||- custom_field.list? ||- custom_field.field_format_hierarchy? ||- custom_field.multi_value?+ custom_field.list? ||+ custom_field.hierarchical_list? ||+ custom_field.multi_value?value = represented.send custom_field.attribute_getterdiff --git a/spec/forms/custom_fields/custom_field_rendering_spec.rb b/spec/forms/custom_fields/custom_field_rendering_spec.rbindex 7e8cc6f0202..7c3c2efad50 100644--- a/spec/forms/custom_fields/custom_field_rendering_spec.rb+++ b/spec/forms/custom_fields/custom_field_rendering_spec.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -61,6 +61,7 @@ RSpec.describe CustomFields::CustomFieldRendering do"int" => CustomFields::Inputs::Int,"float" => CustomFields::Inputs::Float,"hierarchy" => CustomFields::Inputs::SingleSelectList,+ "scored_list" => CustomFields::Inputs::SingleSelectList,"list" => CustomFields::Inputs::SingleSelectList,"date" => CustomFields::Inputs::Date,"bool" => CustomFields::Inputs::Bool,@@ -100,6 +101,7 @@ RSpec.describe CustomFields::CustomFieldRendering do{"hierarchy" => CustomFields::Inputs::MultiSelectList,+ "scored_list" => CustomFields::Inputs::MultiSelectList,"list" => CustomFields::Inputs::MultiSelectList,"user" => CustomFields::Inputs::MultiUserSelectList,"version" => CustomFields::Inputs::MultiVersionSelectListdiff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rbindex 32a00bf7d42..3010600cafa 100644--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb@@ -23,7 +23,7 @@## 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.+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.## See COPYRIGHT and LICENSE files for more details.#++@@ -77,6 +77,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doignore_non_working_days:,status:) do |wp|allow(wp).to receive_messages(available_custom_fields:,+ custom_field_values:,spent_hours:,derived_start_date:,derived_due_date:)@@ -115,6 +116,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendlet(:status) { build_stubbed(:status, updated_at: Time.zone.now) }let(:available_custom_fields) { [] }+ let(:custom_field_values) { [] }before dologin_as current_user@@ -1237,6 +1239,47 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter doendend+ describe "customField" do+ let(:available_custom_fields) { [custom_field] }+ let(:custom_field_values) { [build_stubbed(:custom_value, custom_field:, value:)] }++ context "with format scored list" do+ let(:custom_field) { build_stubbed(:scored_list_wp_custom_field) }+ let(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }+ let(:contract_class) { CustomFields::Hierarchy::InsertScoredItemContract }+ let(:scored_item) do+ service+ .insert_item(contract_class:, parent: custom_field.hierarchy_root, label: "TIE Fighter", score: 16.7)+ .value!+ end+ let(:value) { scored_item.id }++ it_behaves_like "has a titled link" do+ let(:link) { "customField#{custom_field.id}" }+ let(:href) { "/api/v3/custom_field_items/#{item.id}" }+ let(:title) { "TIE Fighter" }+ end+ end++ context "with format hierarchy" do+ let(:custom_field) { build_stubbed(:hierarchy_wp_custom_field) }+ let(:service) { CustomFields::Hierarchy::HierarchicalItemService.new }+ let(:contract_class) { CustomFields::Hierarchy::InsertListItemContract }+ let(:item) do+ service+ .insert_item(contract_class:, parent: custom_field.hierarchy_root, label: "TIE Fighter", short: "TF")+ .value!+ end+ let(:value) { item.id }++ it_behaves_like "has a titled link" do+ let(:link) { "customField#{custom_field.id}" }+ let(:href) { "/api/v3/custom_field_items/#{item.id}" }+ let(:title) { "TIE Fighter (TF)" }+ end+ end+ end+describe "formConfiguration" docontext "when not admin" doit_behaves_like "has no link" do