Skip to content

Commit

Permalink
Rollins mediated deposit workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bess committed Jun 9, 2017
1 parent e7a3405 commit 7f20ec4
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 80 deletions.
19 changes: 19 additions & 0 deletions app/services/hyrax/workflow/approved_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Hyrax
module Workflow
class ApprovedNotification < AbstractNotification
private

def subject
'Deposit #{title} has been approved'
end

def message
"#{title} (#{link_to work_id, document_path}) has been approved by #{user.user_key} #{comment}"
end

def users_to_notify
super << user
end
end
end
end
21 changes: 21 additions & 0 deletions app/services/hyrax/workflow/pending_approval_notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Hyrax
module Workflow
class PendingApprovalNotification < AbstractNotification
protected

def subject
"Deposit #{title} is awaiting approval"
end

def message
"#{title} (#{link_to work_id, document_path}) was deposited by #{user.user_key} and is awaiting approval. #{comment}"
end

private

def users_to_notify
super << user
end
end
end
end
102 changes: 102 additions & 0 deletions config/workflows/emory_one_step_approval.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"workflows": [
{
"name": "emory_one_step_approval",
"label": "One-step approval tailored for Emory",
"description": "A single-step workflow for mediated deposit in which all deposits must be approved by an approver. Approver may also send deposits back to the depositor, comment on the work, and hide or unhide a work.",
"allows_access_grant": false,
"actions": [
{
"name": "deposit",
"from_states": [],
"transition_to": "pending_approval",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::PendingApprovalNotification",
"to": ["approving", "depositing"]
}
],
"methods": [
"Hyrax::Workflow::DeactivateObject"
]
}, {
"name": "request_changes",
"from_states": [{"names": ["approved", "pending_approval"], "roles": ["approving"]}],
"transition_to": "changes_required",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::ChangesRequiredNotification",
"to": ["approving"]
}
],
"methods": [
"Hyrax::Workflow::DeactivateObject"
]
}, {
"name": "approve",
"from_states": [{"names": ["pending_approval"], "roles": ["approving"]}],
"transition_to": "approved",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::ApprovedNotification",
"to": ["approving", "depositing"]
}
],
"methods": [
"Hyrax::Workflow::ActivateObject"
]
}, {
"name": "request_review",
"from_states": [{"names": ["changes_required"], "roles": ["depositing"]}],
"transition_to": "pending_approval",
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::PendingReviewNotification",
"to": ["approving"]
}
]
}, {
"name": "comment_only",
"from_states": [
{ "names": ["pending_approval", "approved"], "roles": ["approving"] },
{ "names": ["changes_required"], "roles": ["depositing"] }
]
}, {
"name": "hide",
"from_states": [
{ "names": ["pending_review", "pending_approval", "approved", "changes_required"], "roles": ["reviewing", "approving"] }
],
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::HiddenNotification",
"to": ["approving"]
}
],
"methods": [
"Hyrax::Workflow::HideObject"
]
}, {
"name": "unhide",
"from_states": [
{ "names": ["pending_review", "pending_approval", "approved", "changes_required"], "roles": ["reviewing", "approving"] }
],
"notifications": [
{
"notification_type": "email",
"name": "Hyrax::Workflow::UnhiddenNotification",
"to": ["approving"]
}
],
"methods": [
"Hyrax::Workflow::UnhideObject"
]
}
]
}
]
}
72 changes: 0 additions & 72 deletions config/workflows/mediated_deposit_workflow.json

This file was deleted.

9 changes: 5 additions & 4 deletions lib/workflow_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setup
# Make an AdminSet and assign it a one step mediated deposit workflow
# @param [String] admin_set_title The title of the admin set to create
# @param [String] workflow_name The name of the mediated deposit workflow to enable
def make_mediated_deposit_admin_set(admin_set_title, workflow_name = "one_step_mediated_deposit")
def make_mediated_deposit_admin_set(admin_set_title, workflow_name = "emory_one_step_approval")
a = make_admin_set(admin_set_title)
activate_mediated_deposit(a, workflow_name)
a
Expand Down Expand Up @@ -76,7 +76,7 @@ def users_in_role(admin_set, role)
# @return [AdminSet]
def make_admin_set_from_config(admin_set_title)
config = school_config(admin_set_title)
config["workflow"] || config["workflow"] = "one_step_mediated_deposit"
config["workflow"] || config["workflow"] = "emory_one_step_approval"
admin_set = make_mediated_deposit_admin_set(admin_set_title, config["workflow"])
approving_users = []
config["approving"].each do |approver_email|
Expand Down Expand Up @@ -211,10 +211,11 @@ def load_workflows
abort("Failed to process all workflows:\n #{errors.join('\n ')}") unless errors.empty?
end

# Activate the one_step_mediated_deposit workflow for the given admin_set.
# Activate a mediated deposit workflow for the given admin_set.
# Default is emory_one_step_approval, but a different value can be passed in.
# The activate! method will DEactivate it if it was already active, so be careful.
# @return [Boolean] true if successful
def activate_mediated_deposit(admin_set, workflow_name = "one_step_mediated_deposit")
def activate_mediated_deposit(admin_set, workflow_name = "emory_one_step_approval")
osmd = admin_set.permission_template.available_workflows.where(name: workflow_name).first
if osmd.active == true
@logger.debug "AdminSet #{admin_set.title.first} already had workflow #{admin_set.permission_template.available_workflows.where(active: true).first.name}. Not making any changes."
Expand Down
103 changes: 103 additions & 0 deletions spec/features/rollins_workflow_etd_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Generated via
# `rails generate hyrax:work Etd`
require 'rails_helper'
require 'active_fedora/cleaner'
require 'workflow_setup'
include Warden::Test::Helpers

RSpec.feature 'Create a Rollins ETD' do
let(:user) { create :user }
let(:w) { WorkflowSetup.new("#{fixture_path}/config/emory/superusers.yml", "#{fixture_path}/config/emory/", "#{::Rails.root}/config/emory/schools.yml", "/dev/null") }
let(:superuser) { w.superusers.first }
context 'a logged in user' do
before do
ActiveFedora::Cleaner.clean!
w.setup
login_as user
end

scenario "Miranda submits a thesis and an approver approves it" do
visit("/concern/etds/new")
expect(page).to have_css('input#etd_title.required')
expect(page).not_to have_css('input#etd_title.multi_value')
expect(page).to have_css('input#etd_creator.required')
expect(page).not_to have_css('input#etd_creator.multi_value')
title = "Global Public Health #{rand}"
fill_in 'Title', with: title
fill_in 'Student Name', with: 'Park, Miranda'
fill_in "Department", with: "Global Health"
fill_in "School", with: "Rollins School of Public Health"
select('CDC', from: 'Partnering agency')
choose('open')
check('agreement')
click_on('My PDF')
page.attach_file('files[]', "#{fixture_path}/miranda/miranda_thesis.pdf")
# TODO: Miranda fixture folder has supplementary files. Add these when we're ready
click_on("Review")
select("Rollins School of Public Health", from: "Add as member of administrative set")
click_on('Save')
expect(page).to have_content title
expect(page).to have_content 'Pending approval'

# Check the ETD was assigned the right workflow
etd = Etd.where(title: [title]).first
expect(etd.active_workflow.name).to eq "emory_one_step_approval"
expect(etd.to_sipity_entity.reload.workflow_state_name).to eq "pending_approval"

# Check workflow permissions for depositing user
available_workflow_actions = Hyrax::Workflow::PermissionQuery.scope_permitted_workflow_actions_available_for_current_state(user: user, entity: etd.to_sipity_entity).pluck(:name)
expect(available_workflow_actions.include?("mark_as_reviewed")).to eq false
expect(available_workflow_actions.include?("approve")).to eq false
expect(available_workflow_actions.include?("request_changes")).to eq false
expect(available_workflow_actions.include?("comment_only")).to eq false
expect(available_workflow_actions.include?("hide")).to eq false
expect(available_workflow_actions.include?("unhide")).to eq false

# Check notifications for depositing user
visit("/notifications?locale=en")
expect(page).to have_content "#{title} (#{etd.id}) was deposited by #{user.email} and is awaiting approval."

# Check notifications for approving user
logout
approving_user = User.where(email: "rollinsadmin@emory.edu").first
login_as approving_user
visit("/notifications?locale=en")
expect(page).to have_content "#{title} (#{etd.id}) was deposited by #{user.email} and is awaiting approval."

# Check workflow permissions for approving user
available_workflow_actions = Hyrax::Workflow::PermissionQuery.scope_permitted_workflow_actions_available_for_current_state(user: approving_user, entity: etd.to_sipity_entity).pluck(:name)
expect(available_workflow_actions.include?("mark_as_reviewed")).to eq false # this workflow step should only exist for Laney
expect(available_workflow_actions.include?("approve")).to eq true
expect(available_workflow_actions.include?("request_changes")).to eq true
expect(available_workflow_actions.include?("comment_only")).to eq true
expect(available_workflow_actions.include?("hide")).to eq true
expect(available_workflow_actions.include?("unhide")).to eq true

# Last superuser should have all workflow options available. (First superuser gets these by virtue of owning the admin sets.)
expect(w.superusers.count).to be > 1 # This test is meaningless if there is only one superuser
available_workflow_actions = Hyrax::Workflow::PermissionQuery.scope_permitted_workflow_actions_available_for_current_state(user: w.superusers.last, entity: etd.to_sipity_entity).pluck(:name)
expect(available_workflow_actions.include?("mark_as_reviewed")).to eq false # this workflow step should only exist for Laney
expect(available_workflow_actions.include?("approve")).to eq true
expect(available_workflow_actions.include?("request_changes")).to eq true
expect(available_workflow_actions.include?("comment_only")).to eq true
expect(available_workflow_actions.include?("hide")).to eq true
expect(available_workflow_actions.include?("unhide")).to eq true

# The approving user marks the etd as approved
subject = Hyrax::WorkflowActionInfo.new(etd, approving_user)
sipity_workflow_action = PowerConverter.convert_to_sipity_action("approve", scope: subject.entity.workflow) { nil }
Hyrax::Workflow::WorkflowActionService.run(subject: subject, action: sipity_workflow_action, comment: nil)
expect(etd.to_sipity_entity.reload.workflow_state_name).to eq "approved"

# Check notifications for approving user
visit("/notifications?locale=en")
expect(page).to have_content "#{title} (#{etd.id}) has been approved by"

# Check notifications for depositor again
logout
login_as user
visit("/notifications?locale=en")
expect(page).to have_content "#{title} (#{etd.id}) has been approved by"
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
workflow:
- emory_one_step_approval
approving:
- rollinsadmin@emory.edu
- rollinsadmin2@emory.edu
Binary file added spec/fixtures/miranda/miranda_thesis.pdf
Binary file not shown.
Binary file added spec/fixtures/miranda/rural_clinics.zip
Binary file not shown.
8 changes: 4 additions & 4 deletions spec/lib/workflow_setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@
w.load_superusers
a = w.make_admin_set(admin_set_title)
expect(AdminSet.where(title: admin_set_title).count).to eq 1
expect(a.permission_template.available_workflows.where(name: "one_step_mediated_deposit").count).to eq 1
expect(a.permission_template.available_workflows.where(name: "emory_one_step_approval").count).to eq 1
w.activate_mediated_deposit(a)
expect(a.active_workflow.name).to eq "one_step_mediated_deposit"
expect(a.active_workflow.name).to eq "emory_one_step_approval"
end
it "makes a mediated deposit admin set" do
new_title = "A Different Title"
w.make_superuser(superuser_email)
admin_set = w.make_mediated_deposit_admin_set(new_title)
expect(admin_set).to be_instance_of AdminSet
expect(AdminSet.where(title: new_title).count).to eq 1
expect(admin_set.active_workflow.name).to eq "one_step_mediated_deposit"
expect(admin_set.active_workflow.name).to eq "emory_one_step_approval"
end

context "schools config" do
Expand All @@ -96,7 +96,7 @@
w.load_superusers
admin_set = w.make_admin_set_from_config("Fake School")
workflow = admin_set.permission_template.available_workflows.where(active: true).first
expect(workflow.name).to eq "one_step_mediated_deposit"
expect(workflow.name).to eq "emory_one_step_approval"
approving_role = Sipity::Role.where(name: "approving").first
wf_role = Sipity::WorkflowRole.find_by(workflow: workflow, role_id: approving_role)
approving_agents = wf_role.workflow_responsibilities.pluck(:agent_id)
Expand Down

0 comments on commit 7f20ec4

Please sign in to comment.