Skip to content

Commit

Permalink
Merge branch 'main' into divide-analytics-collecting-and-reporting-re…
Browse files Browse the repository at this point in the history
…base
  • Loading branch information
orangewolf authored May 24, 2024
2 parents c4758d0 + 7197138 commit 2d8d616
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 12 deletions.
4 changes: 4 additions & 0 deletions app/indexers/hyrax/indexers/file_set_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def to_solr # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Met

# attributes set by fits for video
solr_doc['aspect_ratio_tesim'] = file_metadata.aspect_ratio if file_metadata.aspect_ratio.present?

# support for derivatives download
derivatives = resource.extensions_and_mime_types
solr_doc['extensions_and_mime_types_ssm'] = derivatives.to_json if derivatives.present?
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/hyrax/solr_document_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def lease_enforced?
self['visibility_ssi'] == indexed_lease_visibility
end

def extensions_and_mime_types
JSON.parse(self['extensions_and_mime_types_ssm'].first).map(&:with_indifferent_access) if self['extensions_and_mime_types_ssm']
end

private

def model_classifier(classifier)
Expand Down
26 changes: 26 additions & 0 deletions app/models/hyrax/file_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ def extracted_text_id
extracted_text&.id
end

##
# @return [Array] All ids, extensions, mime types, names, and uses
# @example
# [{:id=>"123", :extension=>"pdf", :mime_type=>"application/pdf", :name=>nil, :use=>"OriginalFile"},
# {:id=>"234", :extension=>"jpeg", :mime_type=>"application/octet-stream", :name=>"thumbnail", :use=>"ThumbnailImage"}]
# rubocop:disable Metrics/MethodLength
def extensions_and_mime_types
return [] if file_ids.empty?
Hyrax.query_service.find_many_by_ids(ids: file_ids).each_with_object([]) do |fm, arr|
next unless fm.original_filename
extension = File.extname(fm.original_filename)
next if extension.empty?

use = fm.pcdm_use.first.to_s.split("#").last
name = use == 'OriginalFile' ? nil : File.basename(fm.original_filename, extension).split('-').last
arr << {
id: fm.id.to_s,
extension: extension[1..], # remove leading '.'
mime_type: fm.mime_type,
name: name,
use: use
}
end
# rubocop:enable Metrics/MethodLength
end

##
# @return [Valkyrie::ID]
def representative_id
Expand Down
3 changes: 2 additions & 1 deletion app/presenters/hyrax/file_set_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def initialize(solr_document, current_ability, request = nil)

# CurationConcern methods
delegate :stringify_keys, :human_readable_type, :collection?, :image?, :video?,
:audio?, :pdf?, :office_document?, :representative_id, :to_s, to: :solr_document
:audio?, :pdf?, :office_document?, :representative_id, :to_s,
:extensions_and_mime_types, to: :solr_document

# Methods used by blacklight helpers
delegate :has?, :first, :fetch, to: :solr_document
Expand Down
10 changes: 9 additions & 1 deletion app/views/hyrax/file_sets/_actions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@
class: "download",
data: { label: file_set.id, work_id: @presenter.id, collection_ids: @presenter.member_of_collection_ids } %>
</li>
<% end %>

<% file_set.extensions_and_mime_types&.each do |hash| %>
<% next unless hash[:name] %>
<li class ="dropdown-item" role="menuitem" tabindex="-1">
<a href="<%= download_url(id: file_set.id, locale: 'en', file: hash[:name], mime_type: hash[:mime_type]) %>" download>
Download <em>(as <%= hash[:name] %>)</em>
</a>
</li>
<% end %>
<% end %>
</ul>
</div>
<% end %>
Expand Down
14 changes: 4 additions & 10 deletions spec/features/deposit_agreements_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true
RSpec.describe 'Deposit Agreement options', :js, :workflow, :clean_repo do
let(:user) { create(:user) }
let(:admin_user) { create(:admin) }
# let(:adminset) { create(:admin_set) }
let!(:ability) { ::Ability.new(user) }
let(:permission_template) { create(:permission_template, with_admin_set: true, with_active_workflow: true) }

Expand All @@ -15,19 +13,15 @@

context "with activate deposit agreement off" do
before do
sign_in admin_user
# Disable active agreements
visit "/admin/features"
first("tr[data-feature='active-deposit-agreement-acceptance'] input[value='off']").click

allow(Flipflop).to receive(:active_deposit_agreement_acceptance?).and_return(false)
sign_in user
end

it "allows saving work when active deposit agreement is off" do
click_link 'Works'
find('#add-new-work-button').click
choose "payload_concern", option: "GenericWork"
click_button 'Create work'
end

it "allows saving work when active deposit agreement is off" do
expect(page).to have_selector('input[name="save_with_files"][disabled]')

# Fill in required metadata
Expand Down
28 changes: 28 additions & 0 deletions spec/models/hyrax/file_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,32 @@
expect(file_set.human_readable_type).to eq 'File Set'
end
end

describe '#extensions_and_mime_types' do
let(:original_file) do
FactoryBot.valkyrie_create(:hyrax_file_metadata,
file_identifier: 'disk:///app/samvera/hyrax-webapp/storage/files/path/to/my_file.pdf',
mime_type: "application/pdf",
original_filename: 'my_file.pdf')
end
let(:thumbnail) do
FactoryBot.valkyrie_create(:hyrax_file_metadata,
use: :thumbnail_file,
file_identifier: 'disk:///app/samvera/hyrax-webapp/storage/files/path/to/thumbnail_file.jpg',
mime_type: "image/jpeg",
original_filename: 'thumbnail_file.jpg')
end
let(:files) { [original_file, thumbnail] }
let(:file_ids) { files.map(&:id) }
let(:results_array) do
[{ id: thumbnail.id.to_s, extension: "jpg", mime_type: "image/jpeg", name: "thumbnail_file", use: "ThumbnailImage" },
{ id: original_file.id.to_s, extension: "pdf", mime_type: "application/pdf", name: nil, use: "OriginalFile" }]
end

before { file_set.file_ids = file_ids }

it 'builds an array of extensions_and_mime_types' do
expect(file_set.extensions_and_mime_types).to match_array results_array
end
end
end

0 comments on commit 2d8d616

Please sign in to comment.