Skip to content

Commit

Permalink
Merge pull request #15744 from opf/bug/55431-display-an-error-when-du…
Browse files Browse the repository at this point in the history
…ration-input-is-invalid

[#55431] Display an inline error when duration input is not a duration
  • Loading branch information
cbliard authored Jun 5, 2024
2 parents ae0e262 + c1e4607 commit 235e2b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/controllers/work_packages/progress_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ def extract_persisted_progress_attributes
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
Expand Down
1 change: 1 addition & 0 deletions app/services/duration_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def parse(duration_string)
"hours"
end

ChronicDuration.raise_exceptions = true
ChronicDuration.parse(duration_string,
keep_zero: true,
default_unit:,
Expand Down

0 comments on commit 235e2b9

Please sign in to comment.