Skip to content

Commit 2f86f29

Browse files
authored
Merge pull request #3727 from mlibrary/HELIO-4639/file_set_override_retention
HELIO-4639 - rm thumbnail derivative when using Hyrax default
2 parents 7c1f25a + b20432f commit 2f86f29

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

app/assets/stylesheets/application/heliotrope.scss

+9
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,15 @@ footer.press {
16541654
}
16551655
}
16561656

1657+
// Tidy the "Override Thumbnail with svgicon?" checkbox label on the FileSet edit page "thumbnail" tab
1658+
.user_thumbnail_use_default {
1659+
.checkbox {
1660+
input {
1661+
margin-right: 0.5em;
1662+
}
1663+
}
1664+
}
1665+
16571666
// restrict large user-uploaded thumbnails on the asset edit page
16581667
.restricted-width-media-display {
16591668
.representative-media {

app/overrides/hyrax/file_sets_controller_overrides.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ def uploaded_file_from_path
100100
end
101101

102102
def change_thumbnail
103+
dest = Hyrax::DerivativePath.derivative_path_for_reference(params[:id], 'thumbnail')
104+
103105
if params[:user_thumbnail].key?(:custom_thumbnail)
104-
dest = Hyrax::DerivativePath.derivative_path_for_reference(params[:id], 'thumbnail')
105106
FileUtils.mkdir_p(File.dirname(dest))
106107
FileUtils.cp(params[:user_thumbnail][:custom_thumbnail].path, dest)
107108
# Because the file at `params[:user_thumbnail][:custom_thumbnail].path` was created with Tempfile.new (see...
@@ -110,6 +111,7 @@ def change_thumbnail
110111
end
111112
if params[:user_thumbnail].key?(:use_default)
112113
if params[:user_thumbnail][:use_default] == '1'
114+
FileUtils.rm(dest) if File.exist?(dest)
113115
ActiveFedora::SolrService.add(@file_set.to_solr.merge(thumbnail_path_ss: ActionController::Base.helpers.image_path('default.png')), softCommit: true)
114116
else
115117
ActiveFedora::SolrService.add(@file_set.to_solr.merge(thumbnail_path_ss: Hyrax::Engine.routes.url_helpers.download_path(@file_set.id, file: 'thumbnail')), softCommit: true)

app/views/hyrax/file_sets/_thumbnail.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<%= hidden_field_tag('redirect_tab', 'thumbnail') %>
55
<%= simple_fields_for :user_thumbnail do |t| %>
66
<%= t.input :use_default, label: 'Override Thumbnail with svgicon?', as: :boolean,
7+
disabled: !File.exist?(Hyrax::DerivativePath.derivative_path_for_reference(params[:id], 'thumbnail')),
78
input_html: { checked: curation_concern.to_presenter.using_default_thumbnail? } %>
89
<h4>Upload New Thumbnail (JPG/JPEG only!)</h4>
910
<%= t.input :custom_thumbnail, as: :file, wrapper: :vertical_file_input, label: false, required: false,

spec/controllers/hyrax/file_sets_controller_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,16 @@
399399

400400
let(:file_set_doc_derivative) { file_set.to_solr.merge(thumbnail_path_ss: thumbnail_derivative_path) }
401401
let(:thumbnail_derivative_path) { Hyrax::Engine.routes.url_helpers.download_path(file_set.id, file: 'thumbnail') }
402+
let(:thumbnail_path) { Hyrax::DerivativePath.derivative_path_for_reference(file_set.id, 'thumbnail') }
403+
404+
before do
405+
allow(File).to receive(:exist?).and_call_original
406+
allow(File).to receive(:exist?).with(thumbnail_path).and_return(true)
407+
end
402408

403409
it 'sets it to the Hyrax default thumbnail path' do
404410
expect(ActiveFedora::SolrService).to receive(:add).with(file_set_doc_default, softCommit: true)
411+
expect(FileUtils).to receive(:rm).with(thumbnail_path)
405412
post :update, params: { id: file_set, user_thumbnail: { use_default: '1' } }
406413
end
407414
it 'sets it to the thumbnail derivative path' do

0 commit comments

Comments
 (0)