Skip to content

Commit

Permalink
add notion of 'depositor review' to one step mediated deposit workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Gum committed Dec 1, 2016
1 parent 5d58988 commit 3e1b81c
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/services/sufia/workflow/abstract_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def message
private

def users_to_notify
recipients[:to] + recipients[:cc]
recipients.fetch('to', []) + recipients.fetch('cc', [])
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions app/services/sufia/workflow/changes_required_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Sufia
module Workflow
class ChangesRequiredNotification < AbstractNotification
protected

def subject
'Your deposit requires changes'
end

def message
"#{title} (#{work_id}) requires additional changes before approval.\n\n '#{comment}'"
end

private

def users_to_notify
user_key = ActiveFedora::Base.find(work_id).depositor
super << ::User.find_by(email: user_key)
end
end
end
end
33 changes: 31 additions & 2 deletions lib/generators/sufia/templates/workflow.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,26 @@
"to": ["approving"],
"cc": []
}
],
"methods": [
"CurationConcerns::Workflow::DeactivateObject"
]
},
{
}, {
"name": "request_changes",
"from_states": [{"names": ["complete", "pending_review"], "roles": ["approving"]}],
"transition_to": "changes_required",
"notifications": [
{
"notification_type": "email",
"name": "Sufia::Workflow::ChangesRequiredNotification",
"to": ["approving"],
"cc": []
}
],
"methods": [
"CurationConcerns::Workflow::DeactivateObject"
]
}, {
"name": "approve",
"from_states": [{"names": ["pending_review"], "roles": ["approving"]}],
"transition_to": "complete",
Expand All @@ -33,6 +50,18 @@
"methods": [
"CurationConcerns::Workflow::ActivateObject"
]
}, {
"name": "request_review",
"from_states": [{"names": ["changes_requested"], "roles": ["depositing"]}],
"transition_to": "pending_review",
"notifications": [
{
"notification_type": "email",
"name": "Sufia::Workflow::PendingReviewNotification",
"to": ["approving"],
"cc": []
}
]
}
]
}
Expand Down
28 changes: 28 additions & 0 deletions spec/services/sufia/workflow/changes_required_notification_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'spec_helper'

RSpec.describe Sufia::Workflow::ChangesRequiredNotification do
let(:depositor) { create(:user) }
let(:cc_user) { create(:user) }
let(:work) { create(:generic_work, user: depositor) }
let(:entity) { create(:sipity_entity, proxy_for_global_id: work.to_global_id.to_s) }
let(:comment) { double("comment", comment: 'A pleasant read') }
let(:recipients) { { 'to' => [depositor], 'cc' => [cc_user] } }

describe ".send_notification" do
it 'sends a message to all users' do
expect(depositor).to receive(:send_message).once.and_call_original

expect { described_class.send_notification(entity: entity, user: depositor, comment: comment, recipients: recipients) }
.to change { depositor.mailbox.inbox.count }.by(1)
.and change { cc_user.mailbox.inbox.count }.by(1)
end
context 'without carbon-copied users' do
let(:recipients) { { 'to' => [depositor] } }
it 'sends a message to the to user(s)' do
expect(depositor).to receive(:send_message).once.and_call_original
expect { described_class.send_notification(entity: entity, user: depositor, comment: comment, recipients: recipients) }
.to change { depositor.mailbox.inbox.count }.by(1)
end
end
end
end
11 changes: 10 additions & 1 deletion spec/services/sufia/workflow/complete_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:work) { create(:generic_work, user: depositor) }
let(:entity) { create(:sipity_entity, proxy_for_global_id: work.to_global_id.to_s) }
let(:comment) { double("comment", comment: 'A pleasant read') }
let(:recipients) { { to: [to_user], cc: [cc_user] } }
let(:recipients) { { 'to' => [to_user], 'cc' => [cc_user] } }

describe ".send_notification" do
it 'sends a message to all users' do
Expand All @@ -19,5 +19,14 @@
.and change { to_user.mailbox.inbox.count }.by(1)
.and change { cc_user.mailbox.inbox.count }.by(1)
end
context 'without carbon-copied users' do
let(:recipients) { { 'to' => [to_user] } }
it 'sends a message to the to user(s)' do
expect(approver).to receive(:send_message).once.and_call_original
expect { described_class.send_notification(entity: entity, user: approver, comment: comment, recipients: recipients) }
.to change { depositor.mailbox.inbox.count }.by(1)
.and change { to_user.mailbox.inbox.count }.by(1)
end
end
end
end
11 changes: 10 additions & 1 deletion spec/services/sufia/workflow/pending_review_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:work) { create(:generic_work, user: depositor) }
let(:entity) { create(:sipity_entity, proxy_for_global_id: work.to_global_id.to_s) }
let(:comment) { double("comment", comment: 'A pleasant read') }
let(:recipients) { { to: [to_user], cc: [cc_user] } }
let(:recipients) { { 'to' => [to_user], 'cc' => [cc_user] } }

describe ".send_notification" do
it 'sends a message to all users except depositor' do
Expand All @@ -18,5 +18,14 @@
.and change { to_user.mailbox.inbox.count }.by(1)
.and change { cc_user.mailbox.inbox.count }.by(1)
end
context 'without carbon-copied users' do
let(:recipients) { { 'to' => [to_user] } }
it 'sends a message to the to user(s)' do
expect(depositor).to receive(:send_message).once.and_call_original
expect { described_class.send_notification(entity: entity, user: depositor, comment: comment, recipients: recipients) }
.to change { depositor.mailbox.inbox.count }.by(1)
.and change { to_user.mailbox.inbox.count }.by(1)
end
end
end
end

0 comments on commit 3e1b81c

Please sign in to comment.