From c832e188edf0b9160e4b8035dab74af6eaf3a0c2 Mon Sep 17 00:00:00 2001 From: John Pinto Date: Mon, 28 Mar 2022 15:23:48 +0100 Subject: [PATCH 1/3] DCC Bug 711 - Fix for broken creation of a Plan using the V0 API. Issue fixed DCC bug for /api/v0/plans for creating a Plan given a template id https://github.com/DigitalCurationCentre/DMPonline-Service/issues/711 Changes: - in app/controllers/api/v0/base_controller.rb: added strong parameters function plan_params. - in app/controllers/api/v0/plans_controller.rb: in method create() added @plan.org = @user.org and replaced @plan.assign_creator(plan_user) by @plan.add_user!(plan_user.id, :creator). --- app/controllers/api/v0/base_controller.rb | 4 ++++ app/controllers/api/v0/plans_controller.rb | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v0/base_controller.rb b/app/controllers/api/v0/base_controller.rb index 058babfe1c..fb8309bd39 100644 --- a/app/controllers/api/v0/base_controller.rb +++ b/app/controllers/api/v0/base_controller.rb @@ -74,6 +74,10 @@ def page_params params.permit(:page, :per_page) end + def plan_params + params.permit(:template_id, :plan[:title], :plan[:email]) + end + # The resource class based on the controller # # Returns Object diff --git a/app/controllers/api/v0/plans_controller.rb b/app/controllers/api/v0/plans_controller.rb index 51a77456a3..f81c0e7f68 100644 --- a/app/controllers/api/v0/plans_controller.rb +++ b/app/controllers/api/v0/plans_controller.rb @@ -29,6 +29,7 @@ def create # initialize the plan @plan = Plan.new + @plan.org = @user.org # Attach the user as the PI and Data Contact @plan.contributors << Contributor.new( @@ -48,8 +49,9 @@ def create end @plan.template = @template @plan.title = params[:plan][:title] + if @plan.save - @plan.assign_creator(plan_user) + @plan.add_user!(plan_user.id, :creator) respond_with @plan else # the plan did not save From 9883fcdb7cf32dcf83f1604f9a89f891cd51e9e8 Mon Sep 17 00:00:00 2001 From: briri Date: Thu, 31 Mar 2022 08:27:44 -0700 Subject: [PATCH 2/3] fix for broken test --- spec/services/api/v1/deserialization/plan_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/api/v1/deserialization/plan_spec.rb b/spec/services/api/v1/deserialization/plan_spec.rb index 9738140ac1..e7b940541d 100644 --- a/spec/services/api/v1/deserialization/plan_spec.rb +++ b/spec/services/api/v1/deserialization/plan_spec.rb @@ -53,7 +53,7 @@ ], dmp_id: { type: 'doi', identifier: @identifier.value }, extension: [ - "#{@app_name}": { + "dmproadmap": { template: { id: @template.id, title: @template.title } } ] From 9302d3d365b075b393fe112641ea4bfdb8a96264 Mon Sep 17 00:00:00 2001 From: briri Date: Thu, 31 Mar 2022 08:45:50 -0700 Subject: [PATCH 3/3] appease rubocop --- spec/services/api/v1/deserialization/plan_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/api/v1/deserialization/plan_spec.rb b/spec/services/api/v1/deserialization/plan_spec.rb index e7b940541d..f8937952d1 100644 --- a/spec/services/api/v1/deserialization/plan_spec.rb +++ b/spec/services/api/v1/deserialization/plan_spec.rb @@ -53,7 +53,7 @@ ], dmp_id: { type: 'doi', identifier: @identifier.value }, extension: [ - "dmproadmap": { + dmproadmap: { template: { id: @template.id, title: @template.title } } ]