Skip to content

Commit

Permalink
Ensures that new project requests update data sponsor project metadat…
Browse files Browse the repository at this point in the history
…a and provide user-friendly e-mail message bodies (#647)

* setting up submission provenance in the mailer

* setting up submission provenance in the mailer

* [wip] Ensuring that e-mails for Project creations capture the data sponsor and date of submission within the project metadata

Co-authored-by: Jaymee Hyppolite <jaymeeh@users.noreply.github.com>

* Ensures that the mailer HTML and text layout templates are properly
formatted for the message bodies of the e-mails sent in response to the
creation of Projects

Co-authored-by: Jaymee Hyppolite <jaymeeh@users.noreply.github.com>

* Ensuring that the TigerdataMailer RSpec test suite examines the e-mail
message body

Co-authored-by: Jaymee Hyppolite <jaymeeh@users.noreply.github.com>

---------

Co-authored-by: HyppoliteJ <jh6441@princeton.edu>
Co-authored-by: Jaymee Hyppolite <jaymeeh@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 18, 2024
1 parent 1d78ef3 commit 7826906
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Layout/LineLength:
Exclude:
- "spec/system/data_migration/*"

Metrics/AbcSize:
Exclude:
- "app/mailers/tigerdata_mailer.rb"

Metrics/BlockLength:
Exclude:
- "app/models/mediaflux/http/create_asset_request.rb"
Expand All @@ -38,6 +42,7 @@ Metrics/MethodLength:
Max: 15 # default: 10
Exclude:
- app/models/media_flux_client.rb
- "app/mailers/tigerdata_mailer.rb"

Metrics/ParameterLists:
Enabled: false
Expand Down
22 changes: 19 additions & 3 deletions app/mailers/tigerdata_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,29 @@ def project_creation
}

# attaching xml response to the mailer
xml_content = project.to_xml
@xml_content = project.to_xml.html_safe

data_sponsor = project_metadata[:data_sponsor]
created_on = project_metadata[:created_on]
submission_provenance = {
# "RequestedBy": data_sponsor,
"requested_by": data_sponsor,
# "RequestDateTime": created_on
"request_date_time": created_on
}

updated = project_metadata.dup # This is needed to ensure that the Hash is mutable for the Project Model
updated[:submission] = submission_provenance
project.metadata = updated
project.save

attachments["#{filebase}.xml"] = {
mime_type: "application/xml",
content: xml_content
content: @xml_content
}

mail(to: config[:to_email], subject: "Project Creation Request", cc: config[:cc_email])
subject = "New Project Request Ready for Review"
mail(to: config[:to_email], cc: config[:cc_email], subject:)
end

private
Expand Down
7 changes: 6 additions & 1 deletion app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
</head>

<body>
<%= yield %>
<p>The following project request is ready for review:</p>
<pre>
<%= @xml_content %>
</pre>
<p>Please log in to the Presentation Layer to view more details and approve the project.</p>
<p>Gratefully, the RDSS Team</p>
</body>
</html>
8 changes: 7 additions & 1 deletion app/views/layouts/mailer.text.erb
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<%= yield %>
The following project request is ready for review:

<%= @xml_content %>

Please log in to the Presentation Layer to view more details and approve the project.

Gratefully, the RDSS Team
28 changes: 26 additions & 2 deletions spec/mailers/tigerdata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
expect { described_class.with(project_id:).project_creation.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
mail = ActionMailer::Base.deliveries.last

expect(mail.subject).to eq "Project Creation Request"
expect(mail.subject).to eq "New Project Request Ready for Review"
expect(mail.to).to eq ["test@example.com"]
expect(mail.cc).to eq ["test_to@example.com"]
expect(mail.from).to eq ["no-reply@princeton.edu"]
html_body = mail.html_part.body.to_s
expect(html_body).to have_content(project.metadata[:title])
project.metadata.keys.each do |field|
next if ["updated_on", "created_on", "created_by", "updated_by"].include?(field)
next if ["updated_on", "created_on", "created_by", "updated_by", "departments"].include?(field)
value = project.metadata[field]
value = value.sort.join(", ") if value.is_a? Array
expect(html_body).to have_content(value)
Expand All @@ -33,6 +33,30 @@
expect(mail.attachments.second.mime_type).to eq "application/xml"
end

it "creates a provenance entry for the project creation" do

expect { described_class.with(project_id:).project_creation.deliver }.to change { ActionMailer::Base.deliveries.count }.by(1)
mail = ActionMailer::Base.deliveries.last

project.reload
expect(project.metadata).to include("submission")
expect(project.metadata["submission"]).to include("requested_by")
expect(project.metadata["submission"]).to include("request_date_time")

expect(mail.subject).to eq "New Project Request Ready for Review"
expect(mail.to).to eq ["test@example.com"]
expect(mail.cc).to eq ["test_to@example.com"]
expect(mail.from).to eq ["no-reply@princeton.edu"]
html_body = mail.html_part.body.to_s

expect(html_body).not_to be_empty

expect(html_body).to include("The following project request is ready for review:")
expect(html_body).to include("Please log in to the Presentation Layer to view more details and approve the project.")
expect(html_body).to include("Gratefully, the RDSS Team")
expect(html_body).to include(project.to_xml)
end

context "when the project ID is invalid or nil" do
let(:project_id) { "invalid" }

Expand Down

0 comments on commit 7826906

Please sign in to comment.