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 #create action to permit minimal params

Alexander Brandon Coles7266897a15ec
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index f4d0d7a23e8..55dc5234c2c 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -170,7 +170,7 @@ class ProjectsController < ApplicationController
def create_blank
service_call = Projects::CreateService
.new(user: current_user)
- .call(permitted_params.project)
+ .call(permitted_params.new_project)
@new_project = service_call.result
@@ -183,12 +183,12 @@ class ProjectsController < ApplicationController
end
def create_from_template # rubocop:disable Metrics/AbcSize
- @copy_options = Projects::CopyOptions.new(copy_options_params)
+ @copy_options = Projects::CopyOptions.new(permitted_params.copy_project_options)
service_call = Projects::EnqueueCopyService
.new(user: current_user, model: @template)
.call(
- target_project_params: permitted_params.project.to_h,
+ target_project_params: permitted_params.new_project.to_h,
only: @copy_options.dependencies,
send_notifications: @copy_options.send_notifications
)
@@ -238,9 +238,5 @@ class ProjectsController < ApplicationController
::Exports::Register.list_formats(Project).map(&:to_s)
end
- def copy_options_params
- params.expect(copy_options: [[dependencies: []], :send_notifications])
- end
-
helper_method :supported_export_formats
end
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index 7761c4af7b7..c6912e3edbd 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -292,6 +292,16 @@ class PermittedParams
whitelist.merge(custom_field_values(:project))
end
+ def new_project
+ params
+ .expect(project: %i[name parent_id])
+ .merge(custom_field_values(:project))
+ end
+
+ def copy_project_options
+ params.expect(copy_options: [[dependencies: []], :send_notifications])
+ end
+
def project_phase
params.require(:project_phase).permit(%i[start_date finish_date])
end
diff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rb
index cf1f8ffcbfd..a46b4c7ada5 100644
--- a/spec/models/permitted_params_spec.rb
+++ b/spec/models/permitted_params_spec.rb
@@ -256,6 +256,52 @@ RSpec.describe PermittedParams do
it_behaves_like "allows params"
end
+ describe "#new_project" do
+ let(:attribute) { :new_project }
+ let(:hash_key) { "project" }
+
+ context "with minimal params" do
+ let(:hash) { { "name" => "Brand New Project" } }
+
+ it_behaves_like "allows params"
+ end
+
+ context "with parent_id" do
+ let(:hash) { { "name" => "Brand New Project", "parent_id" => "19" } }
+
+ it_behaves_like "allows params"
+ end
+
+ context "with custom_field_values" do
+ let(:hash) { { "name" => "Brand New Project", "custom_field_values" => { "4" => "21" } } }
+
+ it_behaves_like "allows params"
+ end
+ end
+
+ describe "#copy_project_options" do
+ let(:attribute) { :copy_project_options }
+ let(:hash_key) { "copy_options" }
+
+ context "with minimal params" do
+ let(:hash) { { "dependencies" => [] } }
+
+ it_behaves_like "allows params"
+ end
+
+ context "with dependencies" do
+ let(:hash) { { "dependencies" => ["members"] } }
+
+ it_behaves_like "allows params"
+ end
+
+ context "with send_notifications" do
+ let(:hash) { { "dependencies" => [], "send_notifications" => "1" } }
+
+ it_behaves_like "allows params"
+ end
+ end
+
describe "#projects_type_ids" do
let(:attribute) { :projects_type_ids }
let(:hash_key) { "project" }