This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add link to collection Actions tab to enqueue publish/unpublish job; …
- Loading branch information
Jim Coble
committed
Oct 19, 2016
1 parent
94298d8
commit afb6970
Showing
14 changed files
with
216 additions
and
20 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
19 changes: 19 additions & 0 deletions
19
app/controllers/concerns/dul_hydra/controller/publication_behavior.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,19 @@ | ||
module DulHydra | ||
module Controller | ||
module PublicationBehavior | ||
|
||
def publish | ||
Resque.enqueue(PublishJob, current_object.id, current_user.email) | ||
flash[:success] = "Collection (and descendants) queued to be published" | ||
redirect_to action: :show | ||
end | ||
|
||
def unpublish | ||
Resque.enqueue(UnPublishJob, current_object.id, current_user.email) | ||
flash[:success] = "Collection (and descendants) queued to be un-published" | ||
redirect_to action: :show | ||
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,9 @@ | ||
class PublicationJob | ||
|
||
def self.send_notification(email:, subject: 'Publication Job', message:) | ||
mail = JobMailer.basic(to: email, | ||
subject: subject, | ||
message: message) | ||
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 @@ | ||
class PublishJob < PublicationJob | ||
|
||
@queue = :publication | ||
|
||
def self.perform(id, email_addr) | ||
obj = ActiveFedora::Base.find(id) | ||
obj.publish! | ||
send_notification(email: email_addr, | ||
subject: 'Publication Job COMPLETED', | ||
message: "Publication of #{id} (and its descendants) has completed.") | ||
end | ||
|
||
def self.on_failure_send_notification(id, email_addr) | ||
send_notification(email: email_addr, | ||
subject: 'Publication Job FAILED', | ||
message: "Publication of #{id} (and its descendants) FAILED.") | ||
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 @@ | ||
class UnPublishJob < PublicationJob | ||
|
||
@queue = :publication | ||
|
||
def self.perform(id, email_addr) | ||
obj = ActiveFedora::Base.find(id) | ||
obj.unpublish! | ||
send_notification(email: email_addr, | ||
subject: 'Un-Publication Job COMPLETED', | ||
message: "Un-Publication of #{id} (and its descendants) has completed.") | ||
end | ||
|
||
def self.on_failure_send_notification(id, email_addr) | ||
send_notification(email: email_addr, | ||
subject: 'Un-Publication Job FAILED', | ||
message: "Un-Publication of #{id} (and its descendants) FAILED.") | ||
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
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,24 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe PublishJob, type: :job do | ||
|
||
describe ".perform" do | ||
let!(:obj) { double(id: 'test-1', publish!: nil) } | ||
let(:email) { '[email protected]' } | ||
let(:expected_msg) { "Publication of #{obj.id} (and its descendants) has completed." } | ||
before do | ||
allow(ActiveFedora::Base).to receive(:find).with(obj.id) { obj } | ||
end | ||
it "should call 'publish!' on the object" do | ||
expect(obj).to receive(:publish!) | ||
described_class.perform('test-1', email) | ||
end | ||
it "should generate an email" do | ||
expect(JobMailer).to receive(:basic).with(to: email, | ||
subject: 'Publication Job COMPLETED', | ||
message: expected_msg) | ||
described_class.perform('test-1', email) | ||
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,23 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe UnPublishJob, type: :job do | ||
|
||
describe ".perform" do | ||
let!(:obj) { double(id: 'test-1', unpublish!: nil) } | ||
let(:email) { '[email protected]' } | ||
let(:expected_msg) { "Un-Publication of #{obj.id} (and its descendants) has completed." } | ||
before do | ||
allow(ActiveFedora::Base).to receive(:find).with(obj.id) { obj } | ||
end | ||
it "should call 'unpublish!' on the object" do | ||
expect(obj).to receive(:unpublish!) | ||
described_class.perform('test-1', email) | ||
end | ||
it "should generate an email" do | ||
expect(JobMailer).to receive(:basic).with(to: email, | ||
subject: 'Un-Publication Job COMPLETED', | ||
message: expected_msg) | ||
described_class.perform('test-1', email) | ||
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,11 @@ | ||
require 'spec_helper' | ||
|
||
module Mailers | ||
|
||
RSpec.describe JobMailer, type: :mailer do | ||
it "should generate an email" do | ||
JobMailer.basic(subject: 'Job', to: '[email protected]', message: 'Job completed').deliver! | ||
expect(ActionMailer::Base.deliveries).not_to be_empty | ||
end | ||
end | ||
end |