Skip to content

Commit 9dab490

Browse files
committed
log coll events
1 parent b9c583d commit 9dab490

8 files changed

Lines changed: 90 additions & 2 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal:true
2+
3+
module OregonDigital
4+
# permission methods adapted from Hyrax::WorksControllerBehavior
5+
# in order to capture permissions changed events
6+
module CollectionsControllerBehavior
7+
def save_permissions
8+
@saved_permissions =
9+
case collection
10+
when ActiveFedora::Base
11+
collection.permissions.map(&:to_hash)
12+
else
13+
Hyrax::AccessControl.for(resource: collection).permissions
14+
end
15+
end
16+
17+
def permissions_changed?
18+
@saved_permissions !=
19+
case collection
20+
when ActiveFedora::Base
21+
collection.permissions.map(&:to_hash)
22+
else
23+
Hyrax::AccessControl.for(resource: collection).permissions
24+
end
25+
end
26+
end
27+
end

app/jobs/collection_event_job.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal:true
2+
3+
# Similar to work event jobs except collections cannot be passed in
4+
class CollectionEventJob < Hyrax::EventJob
5+
attr_reader :collection
6+
def perform(collid, depositor)
7+
@collection = Collection.find(collid)
8+
super(depositor)
9+
log_event(collection)
10+
end
11+
12+
# Log the event to the object's stream
13+
def log_event(collection)
14+
collection.log_event(event)
15+
end
16+
17+
# log the event to the users profile stream
18+
def log_user_event(depositor)
19+
depositor.log_profile_event(event)
20+
end
21+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal:true
2+
3+
# Provides a permission change message for collections
4+
class CollectionPermissionChangeEventJob < CollectionEventJob
5+
def action
6+
"User #{link_to_profile depositor} has updated permission of #{link_to collection.title.first, Hyrax::Engine.routes.url_helpers.polymorphic_path(collection)} to #{visibility_badge(collection.visibility)}"
7+
end
8+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal:true
2+
3+
# Provides a catch-all update message
4+
class CollectionUpdateEventJob < CollectionEventJob
5+
def action
6+
"User #{link_to_profile depositor} has updated #{link_to collection.title.first, Hyrax::Engine.routes.url_helpers.polymorphic_path(collection)}"
7+
end
8+
end

app/models/collection.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Collection < ActiveFedora::Base
1111
include OregonDigital::CollectionMetadata
1212
include OregonDigital::MetadataDownload
1313
include OregonDigital::AccessControls::Visibility
14+
include Hyrax::WithEvents
1415
self.indexer = OregonDigital::CollectionIndexer
1516

1617
delegate :facet_configurable?, to: :collection_type
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal:true
2+
3+
module OregonDigital
4+
module Listeners
5+
# Listens for published collection events
6+
class CollectionListener
7+
# currently, collections do not have global id, and therefore cannot be passed to jobs
8+
def on_collection_metadata_updated(event)
9+
CollectionUpdateEventJob.perform_later(event[:collection].id, event[:user])
10+
end
11+
12+
def on_collection_metadata_created(event)
13+
CollectionCreateEventJob.perform_later(event[:collection].id, event[:user])
14+
end
15+
end
16+
end
17+
end

config/initializers/hacks/hyrax_collections_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
end
99

1010
Hyrax::Dashboard::CollectionsController.class_eval do
11+
include OregonDigital::CollectionsControllerBehavior
1112
self.form_class = OregonDigital::Forms::CollectionForm
1213
self.presenter_class = OregonDigital::CollectionPresenter
1314

@@ -29,7 +30,8 @@ def update_active_fedora_collection
2930
process_branding
3031
process_facets if collection.facet_configurable? && !params[:facet_configuration].blank?
3132
process_representative_images
32-
33+
# will need to save permissions on valkyrie colls eventually
34+
save_permissions
3335
@collection.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE unless Hyrax::CollectionType.for(collection: @collection).discoverable?
3436
if @collection.update(collection_params.except(:members))
3537
after_update_response
@@ -67,6 +69,9 @@ def after_create_response
6769

6870
# Override after update method to redirect users back to where they updated the collection from
6971
def after_update_response
72+
Hyrax.publisher.publish('collection.metadata.updated', collection: @collection, user: current_user)
73+
# copying strategy for works permission change logging, enqueue job directly without pub/listen
74+
OregonDigital::CollectionPermissionChangeEventJob.perform_later(collection.id, current_user) if permissions_changed?
7075
respond_to do |format|
7176
format.html do
7277
case URI(request.referer).path.split('/')[1]
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Hyrax.publisher.subscribe(OregonDigital::Listeners::MetadataFetchListener.new)
1+
Hyrax.publisher.subscribe(OregonDigital::Listeners::MetadataFetchListener.new)
2+
Hyrax.publisher.subscribe(OregonDigital::Listeners::CollectionListener.new)

0 commit comments

Comments
 (0)