Skip to content

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

better handling being called with empty list of definitions

Ivan Kuchin7eea425b48dd
diff --git a/app/services/project_life_cycle_steps/activation_service.rb b/app/services/project_life_cycle_steps/activation_service.rb
index 0426a8709c8..c7f088000f0 100644
--- a/app/services/project_life_cycle_steps/activation_service.rb
+++ b/app/services/project_life_cycle_steps/activation_service.rb
@@ -47,10 +47,8 @@ module ProjectLifeCycleSteps
upsert(active:)
- first_changed_phase = project.phases.find_by(definition_id: definitions.min_by(&:position)&.id)
-
- if first_changed_phase
- UpdateService.new(user:, model: first_changed_phase).call
+ if (first_phase = find_first_phase)
+ UpdateService.new(user:, model: first_phase).call
else
project.touch_and_save_journals
@@ -71,6 +69,13 @@ module ProjectLifeCycleSteps
)
end
+ def find_first_phase
+ definition_id = definitions.min_by(&:position)&.id
+ return unless definition_id
+
+ project.phases.find_by(definition_id:)
+ end
+
def default_contract_class
ProjectLifeCycleSteps::ActivationContract
end