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 694ed19 commit 4f677f5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
22 changes: 22 additions & 0 deletions app/services/sufia/workflow/changes_required_notification.rb
@@ -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: 30 additions & 3 deletions lib/generators/sufia/templates/workflow.json.erb
Expand Up @@ -3,7 +3,7 @@
{
"name": "one_step_mediated_deposit",
"label": "One-step mediated deposit workflow",
"description": "A single-step workflow for mediated deposit",
"description": "A single-step workflow for mediated deposit in which all deposits must be approved by a reviewer. Reviewer may also send deposits back to the depositor.",
"actions": [
{
"name": "deposit",
Expand All @@ -15,9 +15,25 @@
"name": "Sufia::Workflow::PendingReviewNotification",
"to": ["approving"]
}
],
"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"]
}
],
"methods": [
"CurationConcerns::Workflow::DeactivateObject"
]
}, {
"name": "approve",
"from_states": [{"names": ["pending_review"], "roles": ["approving"]}],
"transition_to": "complete",
Expand All @@ -31,6 +47,17 @@
"methods": [
"CurationConcerns::Workflow::ActivateObject"
]
}, {
"name": "request_review",
"from_states": [{"names": ["changes_required"], "roles": ["depositing"]}],
"transition_to": "pending_review",
"notifications": [
{
"notification_type": "email",
"name": "Sufia::Workflow::PendingReviewNotification",
"to": ["approving"]
}
]
}
]
}
Expand Down
32 changes: 32 additions & 0 deletions spec/services/sufia/workflow/changes_required_notification_spec.rb
@@ -0,0 +1,32 @@
require 'spec_helper'

RSpec.describe Sufia::Workflow::ChangesRequiredNotification do
let(:approver) { create(:user) }
let(:depositor) { create(:user) }
let(:to_user) { 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' => [to_user], 'cc' => [cc_user] } }

describe ".send_notification" do
it 'sends a message to all users' 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)
.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

0 comments on commit 4f677f5

Please sign in to comment.