-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🎁 Add listener to remove PCDM Collection from Featured #2154
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# Generated by hyrax:listeners | ||
# | ||
# The Hyrax engine uses a publish/subscribe programming model to allow | ||
# pluggable behavior in response to certain repository events. A range of events | ||
# are published on a topic based event bus. | ||
# | ||
# This listener provides a template. | ||
# | ||
# For simple use cases, it's fine to add behavior to the `#on_*` methods in this | ||
# Listener. If you have more than trivial behavior here, you probably want to add | ||
# new classes that are named narrowly scoped and named for what the listener is | ||
# for. | ||
# | ||
# When writing listener methods, it's important to carefully consider error, | ||
# handling. Unhandled exceptions short-circuit behavior for other listeners, | ||
# so it's a good idea to be paying attention to failure cases. | ||
# | ||
# @see https://github.com/samvera/hyrax/wiki/Hyrax's-Event-Bus-(Hyrax::Publisher) | ||
# @see https://www.rubydoc.info/gems/hyrax/Hyrax/Publisher | ||
# @see https://dry-rb.org/gems/dry-events | ||
class HyraxListener | ||
# def on_batch_created | ||
# end | ||
|
||
## | ||
# Remove the event's associated collection from the {FeaturedCollection}. | ||
# | ||
# @param event [Dry::Events::Event] | ||
# | ||
# @see FeaturedCollection.destroy_for | ||
def on_collection_deleted(event) | ||
collection = event[:collection] | ||
return false unless collection | ||
|
||
FeaturedCollection.destroy_for(collection:) | ||
end | ||
|
||
## | ||
# Conditionally remove the event's associated collection from the {FeaturedCollection}. | ||
# | ||
# @param event [Dry::Events::Event] | ||
# | ||
# @see FeaturedCollection.destroy_for | ||
def on_collection_metadata_updated(event) | ||
collection = event[:collection] | ||
return false unless collection | ||
return false unless collection.private? | ||
|
||
FeaturedCollection.destroy_for(collection:) | ||
end | ||
|
||
# def on_collection_membership_update | ||
# end | ||
|
||
# def on_file_characterized | ||
# end | ||
|
||
# def on_file_downloaded | ||
# end | ||
|
||
# def on_file_metadata_updated | ||
# end | ||
|
||
# def on_file_metadata_deleted | ||
# end | ||
|
||
# def on_file_uploaded | ||
# end | ||
|
||
# def on_file_set_audited | ||
# end | ||
|
||
# def on_file_set_attached | ||
# end | ||
|
||
# def on_file_set_url_imported | ||
# end | ||
|
||
# def on_file_set_restored | ||
# end | ||
|
||
# def on_object_deleted | ||
# end | ||
|
||
# def on_object_failed_deposit | ||
# end | ||
|
||
# def on_object_deposited | ||
# end | ||
|
||
# def on_object_acl_updated | ||
# end | ||
|
||
# def on_object_membership_updated | ||
# end | ||
|
||
# def on_object_metadata_updated | ||
# 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
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,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe HyraxListener do | ||
let(:instance) { HyraxListener.new } | ||
let(:collection) { Hyrax::PcdmCollection.new } | ||
let(:event) { Dry::Events::Event.new(event_type, { collection: }) } | ||
|
||
describe "on_collection_deleted" do | ||
let(:event_type) { :on_collection_deleted } | ||
|
||
it 'destroys the featured collection instance' do | ||
expect(FeaturedCollection).to receive(:destroy_for).with(collection:) | ||
|
||
instance.on_collection_metadata_updated(event) | ||
end | ||
end | ||
|
||
describe "on_collection_metadata_updated" do | ||
let(:event_type) { :on_collection_metadata_updated } | ||
|
||
context 'when the collection is private' do | ||
it 'destroys the featured collection instance' do | ||
expect(collection).to receive(:private?).and_return(true) | ||
expect(FeaturedCollection).to receive(:destroy_for).with(collection:) | ||
|
||
instance.on_collection_metadata_updated(event) | ||
end | ||
end | ||
|
||
context 'when the resource is not private' do | ||
it "does not destroy the featured collection" do | ||
expect(collection).to receive(:private?).and_return(false) | ||
expect(FeaturedCollection).not_to receive(:destroy_for) | ||
|
||
instance.on_collection_metadata_updated(event) | ||
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Hyrax::PcdmCollection do | ||
subject(:collection) { described_class.new } | ||
|
||
it_behaves_like 'a Hyrax::PcdmCollection' | ||
|
||
context 'with Hyrax::Permissions::Readable' do | ||
subject { described_class.new } | ||
it { is_expected.to respond_to :public? } | ||
it { is_expected.to respond_to :private? } | ||
it { is_expected.to respond_to :restricted? } | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this method get called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is called via some callbacks defined inside the class but outside the scope of this diff.