Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

Commit

Permalink
Sending email and minting ARKs when records are completed
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Oct 29, 2015
1 parent 18f835d commit 6492ad0
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ gem 'posix-spawn'
gem 'openseadragon'
gem 'sidekiq'
gem "omniauth-cas"
gem 'ezid-client'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ GEM
nokogiri (>= 1.4.3)
erubis (2.7.0)
execjs (2.6.0)
ezid-client (1.1.1)
factory_girl (4.5.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.5.0)
Expand Down Expand Up @@ -676,6 +677,7 @@ DEPENDENCIES
curation_concerns!
devise
devise-guests (~> 0.3)
ezid-client
factory_girl_rails
hydra-collections!
hydra-derivatives!
Expand Down
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: Plum.config[:email][:from_address]
layout 'mailer'
end
6 changes: 6 additions & 0 deletions app/mailers/reviewer_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ReviewerMailer < ApplicationMailer
def completion_email(curation_concern)
@curation_concern = curation_concern
mail(to: Plum.config[:email][:reviewer_address], subject: "[plum] #{@curation_concern.human_readable_type} #{@curation_concern.id} is complete")
end
end
12 changes: 12 additions & 0 deletions app/models/concerns/common_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ module CommonMetadata
extend ActiveSupport::Concern

included do
before_update :check_completion

property :sort_title, predicate: ::OpaqueMods.titleForSort, multiple: false
property :portion_note, predicate: ::RDF::SKOS.scopeNote, multiple: false
property :description, predicate: ::RDF::DC.abstract, multiple: false
property :identifier, predicate: ::RDF::DC.identifier, multiple: false
property :access_policy, predicate: ::RDF::DC.accessRights, multiple: false
property :use_and_reproduction, predicate: ::RDF::DC.rights, multiple: false
property :source_metadata_identifier, predicate: ::PULTerms.metadata_id, multiple: false
Expand All @@ -34,6 +37,10 @@ def apply_remote_metadata
self.attributes = remote_data.attributes
end

def check_completion
complete_record if self.state_changed? && state == 'complete'
end

private

def remote_data
Expand All @@ -50,5 +57,10 @@ def source_metadata_identifier_or_title
errors.add(:title, "You must provide a source metadata id or a title")
errors.add(:source_metadata_identifier, "You must provide a source metadata id or a title")
end

def complete_record
self.identifier = Ezid::Identifier.create.id unless identifier
ReviewerMailer.completion_email(self).deliver_now
end
end
end
5 changes: 5 additions & 0 deletions app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions app/views/layouts/mailer.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= yield %>
17 changes: 17 additions & 0 deletions app/views/reviewer_mailer/completion_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<p>The following <%= @curation_concern.human_readable_type %> has been marked complete:</p>

<table>
<tr>
<th>ID</th>
<td><%= @curation_concern.id %></td>
</tr>
<tr>
<th>Title</th>
<td><%= @curation_concern.title.first %></td>
</tr>
<tr>
<th>URL</th>
<% url = polymorphic_url [main_app, :curation_concerns, @curation_concern] %>
<td><%= link_to url, url %></td>
</tr>
</table>
5 changes: 5 additions & 0 deletions app/views/reviewer_mailer/completion_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The following <%= @curation_concern.human_readable_type %> has been marked complete:

ID...: <%= @curation_concern.id %>
Title: <%= @curation_concern.title.first %>
URL..: <%= polymorphic_url([main_app, :curation_concerns, @curation_concern]) %>
3 changes: 3 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defaults: &defaults
email:
from_address: plum@princeton.edu
reviewer_address: cams@princeton.edu
iiif_url: <%= ENV["PLUM_IIIF_URL"] || "http://192.168.99.100:5004" %>
jp2_recipes:
default_color: >
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.action_mailer.default_url_options = { host: "127.0.0.1:3000" }
config.action_mailer.default_url_options = { host: "localhost:3000" }
end
5 changes: 5 additions & 0 deletions config/initializers/ezid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Ezid::Client.configure do |conf|
conf.default_shoulder = 'ark:/99999/fk4' unless ENV['EZID_DEFAULT_SHOULDER']
conf.user = 'apitest' unless ENV['EZID_USER']
conf.password = 'apitest' unless ENV['EZID_PASSWORD']
end
40 changes: 40 additions & 0 deletions spec/cassettes/ezid.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion spec/features/edit_multi_volume_work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
expect(page).to have_text('Manage Your Work')
end

scenario "User can edit a multi-volume work" do
scenario "User can edit a multi-volume work", vcr: { cassette_name: "ezid" } do
Ezid::Client.configure do |conf| conf.logger = Logger.new(File::NULL); end

visit edit_polymorphic_path [:curation_concerns, multi_volume_work]
fill_in 'multi_volume_work_source_metadata_identifier', with: '1234568'
fill_in 'multi_volume_work_portion_note', with: 'new portion note'
Expand Down
18 changes: 18 additions & 0 deletions spec/mailers/reviewer_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "rails_helper"

RSpec.describe ReviewerMailer, type: :mailer do
describe '#completion_email' do
let(:curation_concern) { FactoryGirl.create(:scanned_resource) }
before(:each) do
ActionMailer::Base.deliveries = []
described_class.completion_email(curation_concern).deliver_now
end

it 'sends an email' do
expect(ActionMailer::Base.deliveries.count).to eq 1
expect(ActionMailer::Base.deliveries.first.from).to eq ['plum@princeton.edu']
expect(ActionMailer::Base.deliveries.first.to).to eq [Plum.config[:email][:reviewer_address]]
expect(ActionMailer::Base.deliveries.first.subject).to eq "[plum] #{curation_concern.human_readable_type} #{curation_concern.id} is complete"
end
end
end
28 changes: 28 additions & 0 deletions spec/models/scanned_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,32 @@
expect(subject.valid?).to eq false
end
end

describe "#check_completion" do
it "completes record when state changes to 'complete'", vcr: { cassette_name: "ezid" } do
allow(subject).to receive("state_changed?").and_return true
subject.state = 'complete'
expect { subject.check_completion }.to change { ActionMailer::Base.deliveries.count }.by(1)
expect(subject.identifier).to eq 'ark:/99999/fk4445wg45'
end
it "does not complete record when state doesn't change" do
allow(subject).to receive("state_changed?").and_return false
subject.state = 'complete'
expect(subject).not_to receive(:complete_record)
expect { subject.check_completion }.not_to change { ActionMailer::Base.deliveries.count }
end
it "does not complete record when state isn't 'complete'" do
subject.state = 'pending'
expect(subject).not_to receive(:complete_record)
expect { subject.check_completion }.not_to change { ActionMailer::Base.deliveries.count }
end
it "does not overwrite existing identifier" do
allow(subject).to receive("state_changed?").and_return true
subject.state = 'complete'
subject.identifier = '1234'
expect(subject).not_to receive("identifier=")
expect { subject.check_completion }.to change { ActionMailer::Base.deliveries.count }.by(1)
expect(subject.identifier).to eq('1234')
end
end
end

0 comments on commit 6492ad0

Please sign in to comment.