Skip to content

Commit

Permalink
refactoring #approve_project (#641)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
JaymeeH and carolyncole authored Apr 15, 2024
1 parent 6fbef75 commit e74d767
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 0 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions app/models/project_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/models/project_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit e74d767

Please sign in to comment.