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

Allow status_id being set in ProgressController

Aaron Contreras61435a40fa5e
diff --git a/app/components/work_packages/progress/status_based/modal_body_component.html.erb b/app/components/work_packages/progress/status_based/modal_body_component.html.erb
index be9c218c967..329d75c0fff 100644
--- a/app/components/work_packages/progress/status_based/modal_body_component.html.erb
+++ b/app/components/work_packages/progress/status_based/modal_body_component.html.erb
@@ -1,7 +1,7 @@
<%= turbo_frame_tag "work_package_progress_modal" do %>
<%= primer_form_with(
model: work_package,
- url: work_package_progress_path(work_package),
+ url: submit_path,
class: 'progress-form',
id: 'progress-form',
data: { 'application-target': "dynamic",
diff --git a/app/components/work_packages/progress/status_based/modal_body_component.rb b/app/components/work_packages/progress/status_based/modal_body_component.rb
index dfc10266e79..83c959022b1 100644
--- a/app/components/work_packages/progress/status_based/modal_body_component.rb
+++ b/app/components/work_packages/progress/status_based/modal_body_component.rb
@@ -55,6 +55,10 @@ module WorkPackages
private
+ def submit_path
+ work_package.persisted? ? work_package_progress_path(work_package) : work_package_progress_path
+ end
+
def map_field(field)
# Scenarios when a field is not provided occur after a
# form submission since the last focused element
diff --git a/app/controllers/work_packages/progress_controller.rb b/app/controllers/work_packages/progress_controller.rb
index 5d982683a3e..b1d338cf0c3 100644
--- a/app/controllers/work_packages/progress_controller.rb
+++ b/app/controllers/work_packages/progress_controller.rb
@@ -29,25 +29,28 @@
# ++
class WorkPackages::ProgressController < ApplicationController
+ ERROR_PRONE_ATTRIBUTES = %i[status_id
+ estimated_hours
+ remaining_hours
+ done_ratio].freeze
+
layout false
before_action :set_work_package
helper_method :modal_class
def edit
+ build_up_new_work_package
+
render modal_class.new(@work_package, focused_field: params[:field])
end
def create
- service_call = WorkPackages::SetAttributesService
- .new(user: current_user,
- model: @work_package,
- contract_class: WorkPackages::CreateContract)
- .call(create_work_package_params)
+ service_call = build_up_new_work_package
if service_call.errors
.map(&:attribute)
- .intersect?(%i[status_id estimated_hours remaining_hours done_ratio])
+ .intersect?(ERROR_PRONE_ATTRIBUTES)
respond_to do |format|
format.turbo_stream do
# Bundle 422 status code into stream response so
@@ -99,18 +102,34 @@ class WorkPackages::ProgressController < ApplicationController
def set_work_package
@work_package = WorkPackage.find(params[:work_package_id])
rescue ActiveRecord::RecordNotFound
- @work_package = WorkPackage.new(create_work_package_params)
+ @work_package = WorkPackage.new
end
def create_work_package_params
params.require(:work_package)
- .permit(%i[estimated_hours remaining_hours])
+ .permit(allowed_params)
.compact_blank
end
def update_work_package_params
params.require(:work_package)
- .permit(%i[estimated_hours remaining_hours])
+ .permit(allowed_params)
+ end
+
+ def allowed_params
+ if WorkPackage.use_status_for_done_ratio?
+ %i[estimated_hours status_id]
+ else
+ %i[estimated_hours remaining_hours]
+ end
+ end
+
+ def build_up_new_work_package
+ WorkPackages::SetAttributesService
+ .new(user: current_user,
+ model: @work_package,
+ contract_class: WorkPackages::CreateContract)
+ .call(create_work_package_params)
end
def formatted_duration(hours)
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts
index b55c7f291f8..2ec8c6bd053 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/progress-popover-edit-field.component.ts
@@ -207,6 +207,8 @@ export class ProgressPopoverEditFieldComponent extends ProgressEditFieldComponen
url.searchParams.set('work_package[estimated_hours]', this.formatter(this.resource.estimatedTime));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
url.searchParams.set('work_package[remaining_hours]', this.formatter(this.resource.remainingTime));
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ url.searchParams.set('work_package[status_id]', this.resource.status.id as string);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
this.frameSrc = url.toString();