From e74d7670f0120415d2bd81bb88c2bc2a4df7efca Mon Sep 17 00:00:00 2001 From: Jaymee Hyppolite <54775395+JaymeeH@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:35:31 -0400 Subject: [PATCH] refactoring #approve_project (#641) * refactoring #approve_project * Update spec/models/project_metadata_spec.rb Co-authored-by: carolyncole <1599081+carolyncole@users.noreply.github.com> --------- Co-authored-by: carolyncole <1599081+carolyncole@users.noreply.github.com> --- app/controllers/projects_controller.rb | 2 -- app/models/project_metadata.rb | 6 ++++++ spec/models/project_metadata_spec.rb | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2b46dcb8..43aea663 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -120,8 +120,6 @@ def update project #Approve action if params.key?("mediaflux_id") - project.mediaflux_id = params["mediaflux_id"] - project.metadata_json["status"] = Project::APPROVED_STATUS project_metadata = ProjectMetadata.new(project: project, current_user:) project_params = params.dup project_metadata.approve_project(params: project_params) diff --git a/app/models/project_metadata.rb b/app/models/project_metadata.rb index 77190d14..4a091563 100644 --- a/app/models/project_metadata.rb +++ b/app/models/project_metadata.rb @@ -15,6 +15,12 @@ def update_metadata(params:) end def approve_project(params:) + #approve a project by recording the mediaflux id & setting the status to 'approved' + project.mediaflux_id = params[:mediaflux_id] + project.metadata_json["status"] = Project::APPROVED_STATUS + project.save! + + #create two provenance events, one for approving the project and another for changing the status of the project project.provenance_events.create(event_type: ProvenanceEvent::APPROVAL_EVENT_TYPE, event_person: current_user.uid, event_details: "Approved by #{current_user.display_name_safe}") project.provenance_events.create(event_type: ProvenanceEvent::STATUS_UPDATE_EVENT_TYPE, event_person: current_user.uid, event_details: "The Status of this project has been set to approved") end diff --git a/spec/models/project_metadata_spec.rb b/spec/models/project_metadata_spec.rb index 73909c3b..ee4f9dec 100644 --- a/spec/models/project_metadata_spec.rb +++ b/spec/models/project_metadata_spec.rb @@ -145,6 +145,16 @@ end describe "#approve_project" do + it "Records the mediaflux id and sets the status to approved" do + project_metadata = described_class.new(current_user: current_user, project:) + params = {mediaflux_id: 001 } + project_metadata.approve_project(params:) + + project.reload + + expect(project.mediaflux_id).not_to be_nil + expect(project.metadata_json["status"]).to eq Project::APPROVED_STATUS + end it "Creates a Provenance Event: Approval" do project_metadata = described_class.new(current_user: current_user, project:) params = {data_sponsor: "abc", data_manager: "def", departments: "dep", directory: "dir", title: "title abc", description: "description 123" }