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
turn toggling into upsert
ulferts45b060d17269
diff --git a/app/components/projects/settings/life_cycles/element_component.html.erb b/app/components/projects/settings/life_cycles/element_component.html.erbindex c582fb0dd6a..7692b0d49df 100644--- a/app/components/projects/settings/life_cycles/element_component.html.erb+++ b/app/components/projects/settings/life_cycles/element_component.html.erb@@ -19,7 +19,6 @@render(Primer::Alpha::ToggleSwitch.new(src: toggle_project_settings_life_cycle_path(project_life_cycle: {- project_id: project.id,definition_id: element.id,type: element.type}diff --git a/app/controllers/projects/settings/life_cycles_controller.rb b/app/controllers/projects/settings/life_cycles_controller.rbindex ff609a753b7..3c89293e659 100644--- a/app/controllers/projects/settings/life_cycles_controller.rb+++ b/app/controllers/projects/settings/life_cycles_controller.rb@@ -32,24 +32,30 @@ class Projects::Settings::LifeCyclesController < Projects::SettingsControllerbefore_action :deny_access_on_feature_flagbefore_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_cyclesdef show; enddef toggle- @life_cycle_element.toggle!(:active)+ element_params = params+ .require(:project_life_cycle)+ .permit(:definition_id, :type)+ .to_h+ .symbolize_keys+ .merge(active: params["value"] == "1")++ upsert_one_step(**element_params)enddef disable_all- upsert_all(active: false)+ upsert_all_steps(active: false)redirect_to action: :showenddef enable_all- upsert_all(active: true)+ upsert_all_steps(active: true)redirect_to action: :showend@@ -60,20 +66,23 @@ class Projects::Settings::LifeCyclesController < Projects::SettingsController@life_cycle_elements = Project::LifeCycleStepDefinition.allend- def load_or_create_life_cycle_element- element_params = params.require(:project_life_cycle).permit(:definition_id, :project_id, :type)-- klass = project_type_for_definition_type(element_params.delete(:type))-- @life_cycle_element = klass.find_or_create_by(element_params)- end-def deny_access_on_feature_flagdeny_access unless OpenProject::FeatureDecisions.stages_and_gates_active?end- def upsert_all(active: true)- Project::LifeCycleStep.upsert_all(+ def upsert_one_step(definition_id:, type:, active: true)+ upsert_all(+ [{+ project_id: @project.id,+ definition_id:,+ active:,+ type: project_type_for_definition_type(type)+ }]+ )+ end++ def upsert_all_steps(active: true)+ upsert_all(@life_cycle_elements.map do |element|{project_id: @project.id,@@ -81,7 +90,13 @@ class Projects::Settings::LifeCyclesController < Projects::SettingsControlleractive:,type: project_type_for_definition_type(element.type)}- end,+ end+ )+ end++ def upsert_all(upserted_steps)+ Project::LifeCycleStep.upsert_all(+ upserted_steps,unique_by: %i[project_id definition_id])end