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[Op#55507]: ensure unique mapping insert
Kabiru Mwenjae0b3cd54ee17
diff --git a/app/services/project_custom_field_project_mappings/bulk_create_service.rb b/app/services/project_custom_field_project_mappings/bulk_create_service.rbindex bd022cf0227..356c2c3594c 100644--- a/app/services/project_custom_field_project_mappings/bulk_create_service.rb+++ b/app/services/project_custom_field_project_mappings/bulk_create_service.rb@@ -74,7 +74,9 @@ module ProjectCustomFieldProjectMappingsenddef perform_bulk_create(service_call)- ProjectCustomFieldProjectMapping.import(service_call.result, validate: false)+ ProjectCustomFieldProjectMapping.insert_all(+ service_call.result.map { |model| model.attributes.slice("project_id", "custom_field_id") }+ )service_callend@@ -85,12 +87,12 @@ module ProjectCustomFieldProjectMappingsenddef incoming_projects- @projects.each_with_object([]) do |project, projects_array|+ @projects.each_with_object(Set.new) do |project, projects_set|next unless project.active?- projects_array << project- projects_array.concat(project.active_subprojects.to_a) if @include_sub_projects- end+ projects_set << project+ projects_set.merge(project.active_subprojects.to_a) if @include_sub_projects+ end.to_aenddef existing_project_mappings(project_ids)diff --git a/spec/services/project_custom_field_project_mappings/bulk_create_service_spec.rb b/spec/services/project_custom_field_project_mappings/bulk_create_service_spec.rbindex b6060939551..a8ec9fee4cd 100644--- a/spec/services/project_custom_field_project_mappings/bulk_create_service_spec.rb+++ b/spec/services/project_custom_field_project_mappings/bulk_create_service_spec.rb@@ -65,6 +65,23 @@ RSpec.describe ProjectCustomFieldProjectMappings::BulkCreateService doendendend++ context "with multiple projects including subprojects" do+ let(:project) { create(:project) }+ let!(:subproject) { create(:project, parent: project) }++ it "creates the mappings for the project and sub-projects" do+ create_service = described_class.new(user:, projects: [project.reload, subproject], project_custom_field:,+ include_sub_projects: true)++ expect { create_service.call }.to change(ProjectCustomFieldProjectMapping, :count).by(2)++ aggregate_failures "creates the mapping for the correct project and custom field" do+ expect(ProjectCustomFieldProjectMapping.where(project_custom_field:).pluck(:project_id))+ .to contain_exactly(project.id, subproject.id)+ end+ end+ endendcontext "with non-admin but sufficient permissions" do