Skip to content

Commit bc0b8d4

Browse files
authored
Merge pull request #2908 from sciencehistory/asset_with_no_content_type_prevents_publishing_work
Asset without a mimetype prevents the work from being published
2 parents f726900 + 8c5d966 commit bc0b8d4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

app/controllers/admin/works_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,10 @@ def unpublishable_file_info(work_array)
593593
problem_asset_ids << asset_id
594594
end
595595
# Image assets published as part of a work need to be tiffs, except if they are in an identified special role
596-
if mime_type.start_with?('image/') && mime_type != 'image/tiff' && !role.in?(['portrait', 'extracted_pdf_page'])
596+
if mime_type.nil? || mime_type.start_with?('image/') && mime_type != 'image/tiff' && !role.in?(['portrait', 'extracted_pdf_page'])
597+
problem = mime_type.nil? ? "has no mime_type" : "is a #{mime_type} instead"
597598
parent = Asset.find_by_friendlier_id(asset_id).parent
598-
Rails.logger.warn("Work '#{parent.friendlier_id}' couldn't be published. Asset '#{asset_id}' should be an image/tiff, but is a #{mime_type}.")
599+
Rails.logger.warn("Work '#{parent.friendlier_id}' couldn't be published. Asset '#{asset_id}' should be an image/tiff, but #{problem}.")
599600
problem_works << parent
600601
problem_asset_ids << asset_id
601602
end

spec/controllers/admin/works_controller_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@
170170
end
171171
end
172172

173+
174+
context "work with an asset with no mimetype" do
175+
let(:no_file_type) { create(:asset_with_faked_file, faked_content_type:nil) }
176+
let(:work_with_no_file_type) { create(:work, :with_complete_metadata, published: false, members: [no_file_type]) }
177+
before do
178+
controller.current_user.works_in_cart << work_with_no_file_type
179+
end
180+
it "refuses to publish: image assets need to be have a mime type." do
181+
expect(no_file_type.content_type).to be_nil
182+
put :batch_publish_toggle, params: { publish: "on" }
183+
expect(response).to redirect_to(admin_cart_items_path)
184+
expect(flash["error"]).to match /contains one or more assets with invalid files./
185+
expect(work_with_no_file_type.reload.published?).to be false
186+
end
187+
end
188+
173189
context "work with a legitimate portrait png" do
174190
let(:portrait_png) { create(:asset, :inline_promoted_file, role: "portrait") }
175191
let(:work) { create(:work, :with_complete_metadata, published: false, members: [portrait_png]) }

0 commit comments

Comments
 (0)