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
fix for bulk editting wps with hierarchy items
Bruno Pagno1963d24acba2
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rbindex 9a7607bb245..1c9d15ae208 100644--- a/app/helpers/custom_fields_helper.rb+++ b/app/helpers/custom_fields_helper.rb@@ -172,6 +172,19 @@ module CustomFieldsHelperoptions_for_select(base_options + custom_field.possible_values_options(project)),id: field_id,multiple: custom_field.multi_value?)+ when "hierarchy"+ base_options = [[I18n.t(:label_no_change_option), ""]]+ result = CustomFields::Hierarchy::HierarchicalItemService.new+ .get_descendants(item: custom_field.hierarchy_root, include_self: false)+ .either(+ ->(items) { items },+ ->(_) { [] }+ )+ options = base_options + result.map do |item|+ label = item.short.present? ? "#{item.label} (#{item.short})" : item.label+ [label, item.id]+ end+ styled_select_tag(field_name, options_for_select(options), id: field_id, multiple: custom_field.multi_value?)elsestyled_text_field_tag(field_name, "", id: field_id)enddiff --git a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb b/app/services/custom_fields/hierarchy/hierarchical_item_service.rbindex 415caf1ed0c..8d942105465 100644--- a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb+++ b/app/services/custom_fields/hierarchy/hierarchical_item_service.rb@@ -90,9 +90,14 @@ module CustomFields# Gets all descendant nodes in a tree starting from the item/node.# @param item [CustomField::Hierarchy::Item] the node+ # @param include_self [Boolean] flag# @return [Success(Array<CustomField::Hierarchy::Item>)]- def get_descendants(item:)- Success(item.self_and_descendants)+ def get_descendants(item:, include_self: true)+ if include_self+ Success(item.self_and_descendants)+ else+ Success(item.descendants)+ endend# Move an item/node to a new parent item/nodediff --git a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rbindex 2756565477e..e88ed99bf4e 100644--- a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb+++ b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb@@ -188,6 +188,17 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService doexpect(result.value!).to match_array(subitem2)endend++ context "when does not include self" do+ it "returns all descendants not including the item passed" do+ result = service.get_descendants(item: mara, include_self: false)+ expect(result).to be_success++ descendants = result.value!+ expect(descendants.size).to eq(2)+ expect(descendants).to contain_exactly(subitem, subitem2)+ end+ endenddescribe "#move_item" do