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
add bulk actions for project life cycle admin
ulferts801d33ffa3cd
diff --git a/app/components/projects/settings/life_cycles/index_component.html.erb b/app/components/projects/settings/life_cycles/index_component.html.erbindex c0ad7866949..0bd1eebb941 100644--- a/app/components/projects/settings/life_cycles/index_component.html.erb+++ b/app/components/projects/settings/life_cycles/index_component.html.erb@@ -10,6 +10,36 @@I18n.t('projects.settings.life_cycle.section_header')endend+ header_container.with_column(flex_layout: true, justify_content: :flex_end) do |actions_container|+ actions_container.with_column(data: { 'projects--settings--project-custom-fields-mapping-filter-target': 'bulkActionContainer' }) do+ render(Primer::Beta::Button.new(+ tag: :a,+ href: enable_all_project_settings_life_cycle_path(project_id: project),+ scheme: :invisible,+ font_weight: :bold,+ color: :subtle,+ 'aria-label': t('projects.settings.actions.label_enable_all'),+ data: { 'turbo-method': :post, 'turbo': true, test_selector: "enable-all-life-cycle-elements" }+ )) do |button|+ button.with_leading_visual_icon(icon: 'check-circle', color: :subtle)+ t('projects.settings.actions.label_enable_all')+ end+ end+ actions_container.with_column(data: { 'projects--settings--project-custom-fields-mapping-filter-target': 'bulkActionContainer' }) do+ render(Primer::Beta::Button.new(+ tag: :a,+ href: disable_all_project_settings_life_cycle_path(project_id: project),+ scheme: :invisible,+ font_weight: :bold,+ color: :subtle,+ 'aria-label': t('projects.settings.actions.label_disable_all'),+ data: { 'turbo-method': :post, 'turbo': true, test_selector: "disable-all-life-cycle-elements" }+ )) do |button|+ button.with_leading_visual_icon(icon: 'x-circle', color: :subtle)+ t('projects.settings.actions.label_disable_all')+ end+ end+ endendendif life_cycle_elements.empty?diff --git a/app/components/projects/settings/project_custom_field_sections/show_component.html.erb b/app/components/projects/settings/project_custom_field_sections/show_component.html.erbindex 727d8901228..66b42dfbcbb 100644--- a/app/components/projects/settings/project_custom_field_sections/show_component.html.erb+++ b/app/components/projects/settings/project_custom_field_sections/show_component.html.erb@@ -25,11 +25,11 @@scheme: :invisible,font_weight: :bold,color: :subtle,- 'aria-label': t('projects.settings.project_custom_fields.actions.label_enable_all'),+ 'aria-label': t('projects.settings.actions.label_enable_all'),data: { 'turbo-method': :put, 'turbo-stream': true, test_selector: "enable-all-project-custom-field-mappings-#{@project_custom_field_section.id}" })) do |button|button.with_leading_visual_icon(icon: 'check-circle', color: :subtle)- t('projects.settings.project_custom_fields.actions.label_enable_all')+ t('projects.settings.actions.label_enable_all')endendactions_container.with_column(data: { 'projects--settings--project-custom-fields-mapping-filter-target': 'bulkActionContainer' }) do@@ -44,11 +44,11 @@scheme: :invisible,font_weight: :bold,color: :subtle,- 'aria-label': t('projects.settings.project_custom_fields.actions.label_disable_all'),+ 'aria-label': t('projects.settings.actions.label_disable_all'),data: { 'turbo-method': :put, 'turbo-stream': true, test_selector: "disable-all-project-custom-field-mappings-#{@project_custom_field_section.id}" })) do |button|button.with_leading_visual_icon(icon: 'x-circle', color: :subtle)- t('projects.settings.project_custom_fields.actions.label_disable_all')+ t('projects.settings.actions.label_disable_all')endendenddiff --git a/app/controllers/projects/settings/life_cycles_controller.rb b/app/controllers/projects/settings/life_cycles_controller.rbindex 6058e50115b..ff609a753b7 100644--- a/app/controllers/projects/settings/life_cycles_controller.rb+++ b/app/controllers/projects/settings/life_cycles_controller.rb@@ -31,7 +31,7 @@ class Projects::Settings::LifeCyclesController < Projects::SettingsControllerbefore_action :deny_access_on_feature_flag- before_action :load_life_cycle_elements, only: %i[show]+ before_action :load_life_cycle_elements, only: %i[show enable_all disable_all]before_action :load_or_create_life_cycle_element, only: %i[toggle]menu_item :settings_life_cycles@@ -42,6 +42,18 @@ class Projects::Settings::LifeCyclesController < Projects::SettingsController@life_cycle_element.toggle!(:active)end+ def disable_all+ upsert_all(active: false)++ redirect_to action: :show+ end++ def enable_all+ upsert_all(active: true)++ redirect_to action: :show+ end+privatedef load_life_cycle_elements@@ -51,14 +63,7 @@ class Projects::Settings::LifeCyclesController < Projects::SettingsControllerdef load_or_create_life_cycle_elementelement_params = params.require(:project_life_cycle).permit(:definition_id, :project_id, :type)- klass = case element_params.delete(:type)- when Project::StageDefinition.name- Project::Stage- when Project::GateDefinition.name- Project::Gate- else- raise NotImplementedError, "Unknown life cycle element type"- end+ klass = project_type_for_definition_type(element_params.delete(:type))@life_cycle_element = klass.find_or_create_by(element_params)end@@ -66,4 +71,29 @@ class Projects::Settings::LifeCyclesController < Projects::SettingsControllerdef deny_access_on_feature_flagdeny_access unless OpenProject::FeatureDecisions.stages_and_gates_active?end++ def upsert_all(active: true)+ Project::LifeCycleStep.upsert_all(+ @life_cycle_elements.map do |element|+ {+ project_id: @project.id,+ definition_id: element.id,+ active:,+ type: project_type_for_definition_type(element.type)+ }+ end,+ unique_by: %i[project_id definition_id]+ )+ end++ def project_type_for_definition_type(definition_type)+ case definition_type+ when Project::StageDefinition.name+ Project::Stage+ when Project::GateDefinition.name+ Project::Gate+ else+ raise NotImplementedError, "Unknown life cycle element type"+ end+ endenddiff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex e3d39e40d84..89baf66fdd9 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -135,7 +135,7 @@ Rails.application.reloader.to_prepare domap.permission :select_project_life_cycle,{- "projects/settings/life_cycles": %i[show toggle]+ "projects/settings/life_cycles": %i[show toggle enable_all disable_all]},permissible_on: :project,require: :member,diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 3defcab38ed..9e6be75fcfd 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -378,6 +378,9 @@ en:text: "This action will not delete any project the list contains. Are you sure you want to delete this project list?"settings:change_identifier: Change identifier+ actions:+ label_enable_all: "Enable all"+ label_disable_all: "Disable all"activities:no_results_title_text: There are currently no activities available.forums:@@ -408,8 +411,6 @@ en:label_enable_single: "Active in this project, click to disable"label_disable_single: "Inactive in this project, click to enable"remove_from_project: "Remove from project"- label_enable_all: "Enable all"- label_disable_all: "Disable all"is_required_blank_slate:heading: Required in all projectsdescription: This project attribute is activated in all projects since the "Required in all projects" option is checked. It cannot be deactivated for individual projects.diff --git a/config/routes.rb b/config/routes.rbindex 6ac9d0feb86..28810f17128 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -248,6 +248,10 @@ Rails.application.routes.draw domember dopost :toggleend+ collection do+ post :enable_all+ post :disable_all+ endendresource :custom_fields, only: %i[show update]resource :repository, only: %i[show], controller: "repository"diff --git a/db/migrate/20241125161226_unique_index_on_project_life_cycle_steps.rb b/db/migrate/20241125161226_unique_index_on_project_life_cycle_steps.rbnew file mode 100644index 00000000000..517b183985c--- /dev/null+++ b/db/migrate/20241125161226_unique_index_on_project_life_cycle_steps.rb@@ -0,0 +1,8 @@+class UniqueIndexOnProjectLifeCycleSteps < ActiveRecord::Migration[7.1]+ def change+ add_index :project_life_cycle_steps,+ %i[project_id definition_id],+ unique: true,+ name: "index_project_life_cycle_steps_on_project_id_and_definition_id"+ end+enddiff --git a/spec/features/projects/life_cycle/active_in_project_spec.rb b/spec/features/projects/life_cycle/active_in_project_spec.rbindex 66078bddd14..d8e45c6df29 100644--- a/spec/features/projects/life_cycle/active_in_project_spec.rb+++ b/spec/features/projects/life_cycle/active_in_project_spec.rb@@ -46,36 +46,66 @@ RSpec.describe "Projects life cycle settings", :js, :with_cuprite, with_flag: {shared_let(:ready_to_close_gate) { create(:project_gate_definition, name: "Ready to Close") }shared_let(:closing_stage) { create(:project_stage_definition, name: "Closing") }- let(:project_lifecycle_page) { Pages::Projects::Settings::LifeCycle.new(project) }+ let(:project_life_cycle_page) { Pages::Projects::Settings::LifeCycle.new(project) }context "with sufficient permissions" docurrent_user { user_with_permission }it "allows toggling the active/inactive state of lifecycle elements" do- project_lifecycle_page.visit!+ project_life_cycle_page.visit!- project_lifecycle_page.expect_listed(initiating_stage => false,- ready_to_execute_gate => false,- executing_stage => false,- ready_to_close_gate => false,- closing_stage => false)+ project_life_cycle_page.expect_listed(initiating_stage => false,+ ready_to_execute_gate => false,+ executing_stage => false,+ ready_to_close_gate => false,+ closing_stage => false)# Activate the stages to be found within the project- project_lifecycle_page.toggle(initiating_stage)- project_lifecycle_page.toggle(ready_to_close_gate)- project_lifecycle_page.toggle(closing_stage)+ project_life_cycle_page.toggle(initiating_stage)+ project_life_cycle_page.toggle(ready_to_close_gate)+ project_life_cycle_page.toggle(closing_stage)wait_for_network_idle# Expect the activation state to be kept after a reloadvisit home_path- project_lifecycle_page.visit!+ project_life_cycle_page.visit!- project_lifecycle_page.expect_listed(initiating_stage => true,- ready_to_execute_gate => false,- executing_stage => false,- ready_to_close_gate => true,- closing_stage => true)+ project_life_cycle_page.expect_listed(initiating_stage => true,+ ready_to_execute_gate => false,+ executing_stage => false,+ ready_to_close_gate => true,+ closing_stage => true)++ # Disable all stages at once+ project_life_cycle_page.disable_all++ wait_for_network_idle++ # Expect the activation state to be kept after a reload+ visit home_path+ project_life_cycle_page.visit!++ project_life_cycle_page.expect_listed(initiating_stage => false,+ ready_to_execute_gate => false,+ executing_stage => false,+ ready_to_close_gate => false,+ closing_stage => false)++ # Enable all stages at once+ project_life_cycle_page.enable_all++ wait_for_network_idle++ # Expect the activation state to be kept after a reload+ visit home_path+ project_life_cycle_page.visit!++ project_life_cycle_page.expect_listed(initiating_stage => true,+ ready_to_execute_gate => true,+ executing_stage => true,+ ready_to_close_gate => true,+ closing_stage => true)endendenddiff --git a/spec/support/pages/projects/settings/life_cycle.rb b/spec/support/pages/projects/settings/life_cycle.rbindex 7a4a2215d6b..4d076709caf 100644--- a/spec/support/pages/projects/settings/life_cycle.rb+++ b/spec/support/pages/projects/settings/life_cycle.rb@@ -71,6 +71,14 @@ module Pagestoggle_element(element).clickend+ def disable_all+ find_test_selector("disable-all-life-cycle-elements").click+ end++ def enable_all+ find_test_selector("enable-all-life-cycle-elements").click+ end+def life_cycle_test_selector(element)test_selector("project-life-cycle-element-#{element.id}")end