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
[#55507] Not possible to add multiple projects at the same time
Kabiru Mwenja9741e0296e4c
diff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rbindex 8844d1b4f72..98c345f83c3 100644--- a/app/controllers/admin/settings/project_custom_fields_controller.rb+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb@@ -43,7 +43,7 @@ module Admin::Settingsbefore_action :prepare_custom_option_position, only: %i(update create)before_action :find_custom_option, only: :delete_optionbefore_action :project_custom_field_mappings_query, only: %i[project_mappings unlink]- before_action :find_link_project_custom_field_mapping, only: :link+ before_action :find_custom_field_projects_to_link, only: :linkbefore_action :find_unlink_project_custom_field_mapping, only: :unlink# rubocop:enable Rails/LexicallyScopedActionFilter@@ -75,7 +75,7 @@ module Admin::Settingsdef linkcreate_service = ProjectCustomFieldProjectMappings::BulkCreateService- .new(user: current_user, project: @project, project_custom_field: @custom_field,+ .new(user: current_user, projects: @projects, project_custom_field: @custom_field,include_sub_projects: include_sub_projects?).call@@ -195,8 +195,8 @@ module Admin::Settingsrespond_with_turbo_streamsend- def find_link_project_custom_field_mapping- @project = Project.find(permitted_params.project_custom_field_project_mapping[:project_id])+ def find_custom_field_projects_to_link+ @projects = Project.where(id: permitted_params.project_custom_field_project_mapping[:project_ids])rescue ActiveRecord::RecordNotFoundupdate_flash_message_via_turbo_stream(message: t(:notice_file_not_found), full: true, dismiss_scheme: :hide, scheme: :dangerdiff --git a/app/forms/projects/custom_fields/custom_field_mapping_form.rb b/app/forms/projects/custom_fields/custom_field_mapping_form.rbindex 2d0501ee2c4..f1c0eb2e3ab 100644--- a/app/forms/projects/custom_fields/custom_field_mapping_form.rb+++ b/app/forms/projects/custom_fields/custom_field_mapping_form.rb@@ -37,9 +37,10 @@ module Projects::CustomFieldsautocomplete_options: {openDirectly: false,focusDirectly: false,+ multiple: true,dropdownPosition: "bottom",disabledProjects: projects_with_custom_field_mapping,- inputName: "project_custom_field_project_mapping[project_id]"+ inputName: "project_custom_field_project_mapping[project_ids]"})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 f9bb4b7f530..620662f9d76 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@@ -30,10 +30,10 @@module ProjectCustomFieldProjectMappingsclass BulkCreateService < ::BaseServices::BaseCallable- def initialize(user:, project:, project_custom_field:, include_sub_projects: false)+ def initialize(user:, projects:, project_custom_field:, include_sub_projects: false)super()@user = user- @project = project+ @projects = projects@project_custom_field = project_custom_field@include_sub_projects = include_sub_projectsend@@ -49,7 +49,7 @@ module ProjectCustomFieldProjectMappingsprivatedef validate_permissions- if @user.allowed_in_project?(:select_project_custom_fields, projects)+ if @user.allowed_in_project?(:select_project_custom_fields, incoming_projects)ServiceResult.successelseServiceResult.failure(errors: { base: :error_unauthorized })@@ -81,13 +81,16 @@ module ProjectCustomFieldProjectMappingsenddef incoming_mapping_ids- project_ids = projects.pluck(:id)+ project_ids = incoming_projects.pluck(:id)project_ids - existing_project_mappings(project_ids)end- def projects- [@project].tap do |projects_array|- projects_array.concat(@project.active_subprojects.to_a) if @include_sub_projects+ def incoming_projects+ @projects.each_with_object([]) do |project, projects_array|+ next unless project.active?++ projects_array << project+ projects_array.concat(project.active_subprojects.to_a) if @include_sub_projectsendenddiff --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 464f6c3663b..205b7ed15d5 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@@ -36,7 +36,7 @@ RSpec.describe ProjectCustomFieldProjectMappings::BulkCreateService docontext "with a single project" dolet(:project) { create(:project) }- let(:instance) { described_class.new(user:, project:, project_custom_field:) }+ let(:instance) { described_class.new(user:, projects: [project], project_custom_field:) }it "creates the mappings" doexpect { instance.call }.to change(ProjectCustomFieldProjectMapping, :count).by(1)@@ -49,19 +49,19 @@ RSpec.describe ProjectCustomFieldProjectMappings::BulkCreateService doendcontext "with subprojects" do- let(:project) { create(:project) }- let!(:subproject) { create(:project, parent: project) }+ let(:projects) { create_list(:project, 2) }+ let!(:subproject) { create(:project, parent: projects.first) }let!(:subproject2) { create(:project, parent: subproject) }it "creates the mappings for the project and sub-projects" do- create_service = described_class.new(user:, project: project.reload, project_custom_field:,+ create_service = described_class.new(user:, projects: projects.map(&:reload), project_custom_field:,include_sub_projects: true)- expect { create_service.call }.to change(ProjectCustomFieldProjectMapping, :count).by(3)+ expect { create_service.call }.to change(ProjectCustomFieldProjectMapping, :count).by(4)aggregate_failures "creates the mapping for the correct project and custom field" doexpect(ProjectCustomFieldProjectMapping.where(project_custom_field:).pluck(:project_id))- .to contain_exactly(project.id, subproject.id, subproject2.id)+ .to contain_exactly(*projects.map(&:id), subproject.id, subproject2.id)endendend@@ -80,7 +80,7 @@ RSpec.describe ProjectCustomFieldProjectMappings::BulkCreateService doendlet(:project) { create(:project) }- let(:instance) { described_class.new(user:, project:, project_custom_field:) }+ let(:instance) { described_class.new(user:, projects: [project], project_custom_field:) }it "creates the mappings" doexpect { instance.call }.to change(ProjectCustomFieldProjectMapping, :count).by(1)@@ -103,7 +103,7 @@ RSpec.describe ProjectCustomFieldProjectMappings::BulkCreateService do})endlet(:project) { create(:project) }- let(:instance) { described_class.new(user:, project:, project_custom_field:) }+ let(:instance) { described_class.new(user:, projects: [project], project_custom_field:) }it "does not create the mappings" doexpect { instance.call }.not_to change(ProjectCustomFieldProjectMapping, :count)