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 ordered_work_packages now that we're base service compatible
Oliver Güntherbcd8da890234
diff --git a/app/services/queries/create_service.rb b/app/services/queries/create_service.rbindex 3f0ffd5215e..0d75b853ff5 100644--- a/app/services/queries/create_service.rb+++ b/app/services/queries/create_service.rb@@ -26,17 +26,4 @@# See COPYRIGHT and LICENSE files for more details.#++-class Queries::CreateService < ::BaseServices::Create- def after_validate(_params, call)- query = call.result- # Check which of the work package IDs exist- ids = query.ordered_work_packages.map(&:work_package_id)- existent_wps = WorkPackage.where(id: ids).pluck(:id).to_set-- query.ordered_work_packages = query.ordered_work_packages.select do |order_item|- existent_wps.include?(order_item.work_package_id)- end-- call- end-end+class Queries::CreateService < ::BaseServices::Create; enddiff --git a/app/services/queries/set_attributes_service.rb b/app/services/queries/set_attributes_service.rbindex 6488d5aed9d..934e12bf53b 100644--- a/app/services/queries/set_attributes_service.rb+++ b/app/services/queries/set_attributes_service.rb@@ -27,6 +27,11 @@#++class Queries::SetAttributesService < ::BaseServices::SetAttributes+ def set_attributes(params)+ set_ordered_work_packages params.delete(:ordered_work_packages)+ super+ end+def set_default_attributes(_params)if model.include_subprojects.nil?model.include_subprojects = Setting.display_subprojects_work_packages?@@ -40,4 +45,18 @@ class Queries::SetAttributesService < ::BaseServices::SetAttributesmodel.user = userendend++ def set_ordered_work_packages(ordered_hash)+ return if ordered_hash.nil?++ available = WorkPackage.where(id: ordered_hash.keys.map(&:to_s)).pluck(:id).to_set++ ordered_hash.each do |key, position|+ # input keys are symbols due to hashie::mash, and AR doesn't like that+ wp_id = key.to_s.to_i+ next unless available.include?(wp_id.to_s.to_i)++ model.ordered_work_packages.build(work_package_id: wp_id, position: position)+ end+ endend