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

Ensure only valid durations are accepted

Aaron Contrerasc1e46072e923
diff --git a/app/controllers/work_packages/progress_controller.rb b/app/controllers/work_packages/progress_controller.rb
index e56e7c558d1..d9e5cfa196a 100644
--- a/app/controllers/work_packages/progress_controller.rb
+++ b/app/controllers/work_packages/progress_controller.rb
@@ -131,13 +131,14 @@ class WorkPackages::ProgressController < ApplicationController
def work_package_params
params.require(:work_package)
.permit(allowed_params).tap do |wp_params|
- if wp_params["estimated_hours"].present?
- wp_params["estimated_hours"] =
- DurationConverter.parse(wp_params["estimated_hours"])
- end
- if wp_params["remaining_hours"].present?
- wp_params["remaining_hours"] =
- DurationConverter.parse(wp_params["remaining_hours"])
+ %w[estimated_hours remaining_hours].each do |attr|
+ if wp_params[attr].present?
+ begin
+ wp_params[attr] = DurationConverter.parse(wp_params[attr])
+ rescue ChronicDuration::DurationParseError
+ @work_package.errors.add(attr.to_sym, :invalid)
+ end
+ end
end
end
end
diff --git a/app/services/duration_converter.rb b/app/services/duration_converter.rb
index 8d8a00e4893..0d6ddb66b04 100644
--- a/app/services/duration_converter.rb
+++ b/app/services/duration_converter.rb
@@ -93,6 +93,7 @@ class DurationConverter
"hours"
end
+ ChronicDuration.raise_exceptions = true
ChronicDuration.parse(duration_string,
keep_zero: true,
default_unit:,