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

Update costlog form and controller to accept entity_id and entity_type properly

Klaus Zanders72d4db2aecfd
diff --git a/modules/costs/app/controllers/costlog_controller.rb b/modules/costs/app/controllers/costlog_controller.rb
index 7589f4c8b4a..9ca6d5d4421 100644
--- a/modules/costs/app/controllers/costlog_controller.rb
+++ b/modules/costs/app/controllers/costlog_controller.rb
@@ -73,7 +73,7 @@ class CostlogController < ApplicationController
elsif @cost_entry.save
flash[:notice] = t(:notice_successful_update)
- redirect_back fallback_location: work_package_path(@cost_entry.entity)
+ redirect_back fallback_location: polymorphic_path(@cost_entry.entity)
else
render action: "edit"
@@ -90,7 +90,7 @@ class CostlogController < ApplicationController
if request.referer.include?("cost_reports")
redirect_to controller: "/cost_reports", action: :index
else
- redirect_back fallback_location: work_package_path(@cost_entry.entity)
+ redirect_back fallback_location: polymorphic_path(@cost_entry.entity)
end
end
@@ -162,14 +162,6 @@ class CostlogController < ApplicationController
end
def cost_entry_params
- params
- .require(:cost_entry)
- .permit(:entity_id, :entity_type, :spent_on, :user_id,
- :cost_type_id, :units, :comments).tap do |permitted_params|
- if params[:cost_entry][:work_package_id]
- permitted_params[:entity_id] = params[:cost_entry][:work_package_id]
- permitted_params[:entity_type] = "WorkPackage"
- end
- end
+ params.expect(cost_entry: %i[user_id entity_id entity_type spent_on cost_type_id units comments])
end
end
diff --git a/modules/costs/app/views/costlog/edit.html.erb b/modules/costs/app/views/costlog/edit.html.erb
index cd78f17c244..5cf6545441b 100644
--- a/modules/costs/app/views/costlog/edit.html.erb
+++ b/modules/costs/app/views/costlog/edit.html.erb
@@ -48,7 +48,8 @@ See COPYRIGHT and LICENSE files for more details.
<%= f.hidden_field :element_id, value: "cost_entry", class: "remote-field--input", data: { "remote-field-key": "element_id" } %>
<div class="form--field -required">
- <%= f.text_field :work_package_id,
+ <%= f.hidden_field :entity_type, value: "WorkPackage" %>
+ <%= f.text_field :entity_id,
size: 6,
required: true,
autofocus: true,