hyku icon indicating copy to clipboard operation
hyku copied to clipboard

Collection thumbnails cannot be updated via Branding UI if an uploaded_thumbnail already exists

Open maxkadel opened this issue 2 months ago • 0 comments

User story

I have an existing older Hyku instance with collection thumbnails at the UploadedCollectionThumbnailPathService.upload_dir path (hyrax-webapp/public/uploads/uploaded_collection_thumbnails/COLLECTION_ID), and I want to update the collection thumbnail via the UI.

Expected behavior

When I upload a new collection thumbnail it is updated and displays in the UI.

Current behavior

When I upload a new collection thumbnail the flash message suggests it has been successful, but the collection thumbnail remains the same

Debugging Evidence

# The thumbnail path service correctly returns the branding path:
CollectionResourceIndexer.thumbnail_path_service.call(collection)
# => "/branding/COLLECTION_ID/thumbnail/my-cool-thumbnail.jpg"

# But the decorator's thumbnail_path method returns the uploaded path:
indexer = Hyrax::Indexers::ResourceIndexer.for(resource: collection)
indexer.send(:thumbnail_path)
# => "/uploads/uploaded_collection_thumbnails/COLLECTION_ID/COLLECTION_ID_card.jpg"

Proposed Solution

Reorder the conditional logic in app/services/hyrax/indexes_thumbnails_decorator.rb to check for branding thumbnails first:

# frozen_string_literal: true

# OVERRIDE Hyrax v5.0.0rc2 to make collection thumbnails uploadable

module Hyrax
  module IndexesThumbnailsDecorator
    # Returns the value for the thumbnail path to put into the solr document
    def thumbnail_path
      object ||= @object || resource
      file_path = CollectionResourceIndexer.thumbnail_path_service.call(object)
      
      # Prefer branding path if it exists
      if file_path&.include?('/branding')
        file_path.gsub(/.*?(\/branding)/, '\1')
      elsif object.try(:collection?) && UploadedCollectionThumbnailPathService.uploaded_thumbnail?(object)
        UploadedCollectionThumbnailPathService.call(object)
      else
        file_path
      end
    end
  end
end

Hyrax::IndexesThumbnails.prepend(Hyrax::IndexesThumbnailsDecorator)

Environment

  • Hyku version: main branch (commit 3904bf33b3136f5cfddc3ad860c930d0d185716f)
  • Tested in: PALNI PALCI Knapsack deployment - issue
  • Persistence: Valkyrie with Postgres adapter

It looks like this behavior may have been introduced in this PR - I'm not sure why the branding and upload paths aren't lining up, this might be something for further investigation.

maxkadel avatar Oct 24 '25 17:10 maxkadel