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
[#67462] code cleanup after code review
Eric Schubert256a078486b9
diff --git a/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb b/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rbindex baf5f82ee48..d424ee57919 100644--- a/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb+++ b/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb@@ -57,7 +57,9 @@ module Admindef hierarchy_itemshashed_hierarchy = @custom_field.hierarchy_root.hash_tree- hashed_hierarchy.nil? ? {} : hashed_hierarchy.first[1]+ hashed_hierarchy.keys.first.label = @custom_field.name++ hashed_hierarchyenddef add_sub_tree(tree, hierarchy_hash)@@ -67,7 +69,7 @@ module Adminelseexpanded = current?(item) || child_hash.any? { |child, _| current?(child) }- tree.with_sub_tree(expanded: expanded, **item_options(item)) do |sub_tree|+ tree.with_sub_tree(expanded:, **item_options(item)) do |sub_tree|add_sub_tree(sub_tree, child_hash)endenddiff --git a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_controller.rbindex 0793930f9d1..03de873e437 100644--- a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb+++ b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb@@ -103,14 +103,14 @@ module Adminredirect_to(custom_field_item_path(@custom_field, @active_item.parent), status: :see_other)end- def change_parent # rubocop:disable Metrics/AbcSize- input = params.require(:custom_field_hierarchy_forms_new_parent_form_model).require(:new_parent)-- parse_parent_input(input).bind do |new_parent|+ def change_parent+ result = parse_parent_input(new_parent_params).bind do |new_parent|validate_new_parent(new_parent).bind doitem_service.move_item(item: @active_item, new_parent:)end- end.either(+ end++ result.either(->(result) doredirect_to(custom_field_item_path(@custom_field, result.parent),@@ -162,6 +162,10 @@ module Admininputend+ def new_parent_params+ params.require(:custom_field_hierarchy_forms_new_parent_form_model).require(:new_parent)+ end+def create_contractcase @custom_field.field_formatwhen "hierarchy"@@ -203,16 +207,21 @@ module Admincase new_parent_inputin [new_parent]input = MultiJson.load(new_parent, symbolize_keys: true)[:value]- new_parent = CustomField::Hierarchy::Item.including_children.find(input)- Success(new_parent)+ new_parent = CustomField::Hierarchy::Item.including_children.find_by(id: input)++ if new_parent.present?+ Success(new_parent)+ else+ Failure("Cannot find parent with id: #{input}")+ endelseFailure("Invalid input: #{new_parent_input}")endenddef validate_new_parent(new_parent)- return Failure(I18n.t(:notice_change_parent_same_target)) if @active_item.parent.id == new_parent.id- return Failure(I18n.t(:notice_change_parent_to_self)) if @active_item.id == new_parent.id+ return Failure("Parent must not be the same as before.") if @active_item.parent.id == new_parent.id+ return Failure("Parent must not be the current item.") if @active_item.id == new_parent.idSuccess()enddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 4dc11e2865b..d8cb22f457f 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3749,8 +3749,6 @@ en:notice_auth_stage_wrong_stage: "Expected to finish authentication stage '%{expected}', but '%{actual}' returned."notice_auth_stage_error: "Authentication stage '%{stage}' failed."notice_can_t_change_password: "This account uses an external authentication source. Impossible to change the password."- notice_change_parent_same_target: "The selected item is already the parent."- notice_change_parent_to_self: "Cannot change parent to itself."notice_custom_options_deleted: "Option '%{option_value}' and its %{num_deleted} occurrences were deleted."notice_email_error: "An error occurred while sending mail (%{value})"notice_email_sent: "An email was sent to %{value}"