-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from curationexperts/invoke-workflow-rebased
Use mira_publication_workflow and hyrax actor stack for self-deposit contributions
- Loading branch information
Showing
16 changed files
with
314 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Hyrax | ||
module Workflow | ||
class MiraNotification < AbstractNotification | ||
# regardless of what is passed in, set the recipients according to this notification's requirements | ||
def initialize(entity, comment, user, recipients) | ||
super | ||
@recipients = workflow_recipients | ||
end | ||
|
||
def workflow_recipients | ||
raise NotImplementedError, "Implement workflow_recipients in a child class" | ||
end | ||
|
||
# The Users who have an admin role | ||
# @return [<Array>::User] an Array of Hyrax::User objects | ||
def admins | ||
Role.where(name: 'admin').first_or_create.users.to_a | ||
end | ||
|
||
# The Hyrax::User who desposited the work | ||
# @return [Hyrax::User] | ||
def depositor | ||
::User.find_by(email: document.depositor) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Hyrax | ||
module Workflow | ||
# Notification of state change to "approved". | ||
# Should notify users with the approving role for the work's AdminSet, plus super users. | ||
class PublishedNotification < MiraNotification | ||
def workflow_recipients | ||
{ "to" => (admins << depositor) } | ||
end | ||
|
||
private | ||
|
||
def subject | ||
"Deposit #{title} has been published" | ||
end | ||
|
||
def message | ||
"#{title} (#{link_to work_id, document_path}) has been published by #{user.display_name}. #{comment}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Hyrax | ||
module Workflow | ||
class SelfDepositNotification < MiraNotification | ||
def workflow_recipients | ||
{ "to" => (admins << depositor) } | ||
end | ||
|
||
private | ||
|
||
def subject | ||
"Deposit #{title} awaiting publication" | ||
end | ||
|
||
def message | ||
"#{title} (#{link_to work_id, document_path}) has been deposited by #{depositor.display_name} (#{depositor.user_key}) and is awaiting publication." | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Hyrax | ||
module Workflow | ||
# Notification of state change to "approved". | ||
# Should notify users with the approving role for the work's AdminSet, plus super users. | ||
class UnpublishedNotification < MiraNotification | ||
def workflow_recipients | ||
{ "to" => admins } | ||
end | ||
|
||
private | ||
|
||
def subject | ||
"Deposit #{title} has been unpublished" | ||
end | ||
|
||
def message | ||
"#{title} (#{link_to work_id, document_path}) has been unpublished by #{user.display_name}. #{comment}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
require 'ffaker' | ||
|
||
FactoryGirl.define do | ||
factory :pdf do | ||
id { ActiveFedora::Noid::Service.new.mint } | ||
title ['Test'] | ||
title [FFaker::Book.title] | ||
visibility Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated via | ||
# `rails generate hyrax:work Pdf` | ||
require 'rails_helper' | ||
require 'ffaker' | ||
require 'tufts/workflow_setup' | ||
require 'import_export/deposit_type_importer.rb' | ||
include Warden::Test::Helpers | ||
|
||
# NOTE: If you generated more than one work, you have to set "js: true" | ||
RSpec.feature 'Create a PDF', :clean, js: true do | ||
context 'a logged in admin user' do | ||
let(:user) { FactoryGirl.create(:user) } | ||
let(:title) { FFaker::Movie.title } | ||
before do | ||
Tufts::WorkflowSetup.setup | ||
importer = DepositTypeImporter.new('./config/deposit_type_seed.csv') | ||
importer.import_from_csv | ||
Pdf.delete_all | ||
Hyrax::UploadedFile.delete_all | ||
login_as user | ||
end | ||
|
||
scenario "a new user contributes a capstone project" do | ||
visit '/contribute' | ||
select 'Fletcher School Capstone Project', from: 'deposit_type' | ||
click_button "Begin" | ||
attach_file('contribution_attachment', File.absolute_path(file_fixture('pdf-sample.pdf'))) | ||
fill_in "Capstone project title", with: title | ||
fill_in "Contributor", with: user.display_name | ||
select 'Master of Arts', from: 'contribution_degree' | ||
fill_in "Short description", with: FFaker::Lorem.paragraph | ||
click_button "Agree & Deposit" | ||
created_pdf = Pdf.last | ||
expect(created_pdf.title.first).to eq title | ||
expect(created_pdf.contributor.first).to eq user.display_name | ||
expect(created_pdf.depositor).to eq user.user_key | ||
expect(created_pdf.admin_set.title.first).to eq "Default Admin Set" | ||
expect(created_pdf.active_workflow.name).to eq "mira_publication_workflow" | ||
expect(created_pdf.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
spec/services/hyrax/workflow/published_notification_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
libdir = File.expand_path('../../../../', __FILE__) | ||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) | ||
require 'rails_helper' | ||
require 'active_fedora/cleaner' | ||
require 'tufts/workflow_setup' | ||
require 'database_cleaner' | ||
|
||
RSpec.describe Hyrax::Workflow::PublishedNotification do | ||
before :all do | ||
Tufts::WorkflowSetup.setup | ||
end | ||
let(:depositor) { FactoryGirl.create(:user) } | ||
let(:admin) { FactoryGirl.create(:admin) } | ||
let(:work) { FactoryGirl.create(:pdf, depositor: depositor.user_key) } | ||
let(:ability) { ::Ability.new(depositor) } | ||
let(:recipients) do | ||
{ 'to' => [depositor] } | ||
end | ||
let(:notification) do | ||
current_ability = ::Ability.new(depositor) | ||
admin # ensure admin user exists | ||
attributes = {} | ||
env = Hyrax::Actors::Environment.new(work, current_ability, attributes) | ||
Hyrax::CurationConcern.actor.create(env) | ||
work_global_id = work.to_global_id.to_s | ||
entity = Sipity::Entity.where(proxy_for_global_id: work_global_id).first | ||
described_class.new(entity, '', depositor, recipients) | ||
end | ||
it "can instantiate" do | ||
expect(notification).to be_instance_of(described_class) | ||
end | ||
it "can find depositor" do | ||
expect(notification.depositor).to be_instance_of(::User) | ||
expect(notification.depositor.email).to eq depositor.user_key | ||
end | ||
it "can find admins" do | ||
expect(notification.admins).to be_instance_of(Array) | ||
expect(notification.admins.pluck(:id)).to contain_exactly(admin.id) | ||
end | ||
it "sends notifications to the depositor, application admins and no one else" do | ||
expect(notification.recipients["to"].pluck(:email)).to contain_exactly(depositor.user_key, admin.user_key) | ||
end | ||
end |
Oops, something went wrong.