Skip to content

Commit

Permalink
Adding approval provenance (#634)
Browse files Browse the repository at this point in the history
* refining sysadmin dashboard
only displaying the sysadmin dashboard, and combining the two separate divs into one

* separating javascript into the application js, and the styling into the settings scss
fixing the collapsing mechanism in the show more button
additional styling

* javascript cleanup

* updating sysadmin tests

* allowing superusers to continue to see the project dashboard

* updating superuser specs

* js lint

* adding an approval provenance event
displaying submission and approval provenance events on the project details page

---------
  • Loading branch information
JaymeeH authored Apr 11, 2024
1 parent 706401e commit 10ce5da
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def show
user_model_names = @data_users.map(&:display_name_safe)
@data_user_names = user_model_names.join(", ")

@submission_events = project.provenance_events.where(event_type: ProvenanceEvent::SUBMISSION_EVENT_TYPE)
@provenance_events = project.provenance_events.where.not(event_type: ProvenanceEvent::STATUS_UPDATE_EVENT_TYPE)
@project_status = project.metadata[:status]

@approve_status = Project::APPROVE_STATUS
Expand Down Expand Up @@ -122,6 +122,9 @@ def update
if params.key?("mediaflux_id")
project.mediaflux_id = params["mediaflux_id"]
project.metadata_json["status"] = Project::APPROVE_STATUS
project_metadata = ProjectMetadata.new(project: project, current_user:)
project_params = params.dup
project_metadata.approve_project(params: project_params)
end

#Edit action
Expand Down
5 changes: 5 additions & 0 deletions app/models/project_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def update_metadata(params:)
form_metadata
end

def approve_project(params:)
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

def create( params:)
project.metadata = update_metadata(params:)
if project.valid? && project.metadata["project_id"].blank?
Expand Down
1 change: 1 addition & 0 deletions app/models/provenance_event.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true
class ProvenanceEvent < ApplicationRecord
SUBMISSION_EVENT_TYPE = "Submission"
APPROVAL_EVENT_TYPE = "Approved"
STATUS_UPDATE_EVENT_TYPE = "Status Update"
belongs_to :project
end
2 changes: 1 addition & 1 deletion app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Project Details:
<h2> Provenance </h2>
<dl>
<dt> Submission</dt>
<% @submission_events.each do |event| %>
<% @provenance_events.each do |event| %>
<dd> <%= event.event_details %>, <%=event.created_at.to_time.in_time_zone("America/New_York").iso8601%> </dd>
<% end %>
<dd></dd>
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/provenance_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
event_type { ProvenanceEvent::SUBMISSION_EVENT_TYPE }
event_details { "Requested by #{FFaker::Name.name}" }
end
factory :approval_event do
event_type { ProvenanceEvent::APPROVAL_EVENT_TYPE }
event_details { "The project was approved by #{FFaker::Name.name}" }
end
factory :status_update_event do
event_type { ProvenanceEvent::STATUS_UPDATE_EVENT_TYPE }
event_details { "The Status was updated from pending to approved" }
Expand Down
15 changes: 15 additions & 0 deletions spec/models/project_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,20 @@
expect(doi).to eq("aaabbb123")
end
end

describe "#approve_project" do
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" }
project_metadata.approve_project(params: {}) # doesn't call the doi service twice

project.reload
expect(project.provenance_events.count).to eq 2
approval_event = project.provenance_events.first #testing the approval Event
expect(approval_event.event_type).to eq ProvenanceEvent::APPROVAL_EVENT_TYPE
expect(approval_event.event_person).to eq current_user.uid
expect(approval_event.event_details).to eq "Approved by #{current_user.display_name_safe}"
end
end
end
end
7 changes: 7 additions & 0 deletions spec/models/provenance_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
pe.event_person = "abc123"
pe.save
end
it "An approval event has the expected values" do
pe = described_class.new
pe.event_type = ProvenanceEvent::APPROVAL_EVENT_TYPE
pe.event_details = "Approved by Jane Doe, 2023-01-19T12:00:00"
pe.event_person = "abc123"
pe.save
end
it "A status update event has the expected values" do
pe = described_class.new
pe.event_type = ProvenanceEvent::STATUS_UPDATE_EVENT_TYPE
Expand Down

0 comments on commit 10ce5da

Please sign in to comment.