mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Guard against invariable file types
Australian production had one JPG image which was not recognised as such. The `content_type` was missing and trying to generate a URL for a variant raised an error and crashed the page. Testing for `variable?` includes testing for `attached?` and is more defensive.
This commit is contained in:
@@ -277,7 +277,7 @@ class Enterprise < ApplicationRecord
|
||||
end
|
||||
|
||||
def logo_url(name)
|
||||
return unless logo.attached?
|
||||
return unless logo.variable?
|
||||
|
||||
Rails.application.routes.url_helpers.url_for(
|
||||
logo.variant(LOGO_SIZES[name])
|
||||
@@ -285,7 +285,7 @@ class Enterprise < ApplicationRecord
|
||||
end
|
||||
|
||||
def promo_image_url(name)
|
||||
return unless promo_image.attached?
|
||||
return unless promo_image.variable?
|
||||
|
||||
Rails.application.routes.url_helpers.url_for(
|
||||
promo_image.variant(PROMO_IMAGE_SIZES[name])
|
||||
|
||||
@@ -89,7 +89,7 @@ module Api
|
||||
# medium: LOGO_MEDIUM_URL
|
||||
# }
|
||||
def attachment_urls(attachment, styles)
|
||||
return unless attachment.attached?
|
||||
return unless attachment.variable?
|
||||
|
||||
styles.transform_values do |transformation|
|
||||
Rails.application.routes.url_helpers.
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
%header
|
||||
.row
|
||||
.small-12.columns
|
||||
= image_tag @group.promo_image.variant(resize_to_limit: [1200, 260]) if @group.promo_image.attached?
|
||||
= image_tag @group.promo_image.variant(resize_to_limit: [1200, 260]) if @group.promo_image.variable?
|
||||
.row
|
||||
.small-12.columns.group-header.pad-top
|
||||
- if @group.logo.attached?
|
||||
- if @group.logo.variable?
|
||||
= image_tag @group.logo.variant(resize_to_limit: [100, 100]), class: "group-logo"
|
||||
- else
|
||||
= image_tag "/noimage/group.png", class: "group-logo"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
%distributor.details.row
|
||||
.small-12.medium-12.large-8.columns
|
||||
#distributor_title
|
||||
- if distributor.logo.attached?
|
||||
- if distributor.logo.variable?
|
||||
= image_tag distributor.logo_url(:thumb), class: "left"
|
||||
= render DistributorTitleComponent.new(name: distributor.name)
|
||||
%location= distributor.address.city
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
%td{ :align => "left" }
|
||||
%h4
|
||||
= t :tax_invoice
|
||||
- if @order.distributor.display_invoice_logo? && @order.distributor.logo.attached?
|
||||
- if @order.distributor.display_invoice_logo? && @order.distributor.logo.variable?
|
||||
%td{ :align => "right", rowspan: 2 }
|
||||
= wicked_pdf_image_tag @order.distributor.logo.variant(resize_to_limit: [150, 150])
|
||||
%tr{ valign: "top" }
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
= t(".customer_greeting", name: @order.bill_address.firstname)
|
||||
%h4
|
||||
= t(".instructions_html", distributor: @order.distributor.name )
|
||||
- if @order.distributor.logo.attached?
|
||||
- if @order.distributor.logo.variable?
|
||||
= image_tag @order.distributor.logo_url(:medium)
|
||||
|
||||
%p.callout
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%table.column{:align => "left"}
|
||||
%tr
|
||||
%td{:align => "right"}
|
||||
- if @order.distributor.logo.attached?
|
||||
- if @order.distributor.logo.variable?
|
||||
= image_tag @order.distributor.logo_url(:medium), class: "float-right"
|
||||
%span.clear
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%table.column{:align => "left"}
|
||||
%tr
|
||||
%td{:align => "right"}
|
||||
- if @order.distributor.logo.attached?
|
||||
- if @order.distributor.logo.variable?
|
||||
= image_tag @order.distributor.logo_url(:medium), class: "float-right"
|
||||
%span.clear
|
||||
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
%table.column{:align => "left"}
|
||||
%tr
|
||||
%td{:align => "right"}
|
||||
- if @order.distributor.logo.attached?
|
||||
- if @order.distributor.logo.variable?
|
||||
= image_tag @order.distributor.logo_url(:medium), class: "float-right"
|
||||
%span.clear
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%table.column{:align => "left"}
|
||||
%tr
|
||||
%td{:align => "right"}
|
||||
- if @shop.logo.attached?
|
||||
- if @shop.logo.variable?
|
||||
= image_tag @shop.logo_url(:medium), class: "float-right"
|
||||
%span.clear
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
%table.column{:align => "left"}
|
||||
%tr
|
||||
%td{:align => "right"}
|
||||
- if @shop.logo.attached?
|
||||
- if @shop.logo.variable?
|
||||
= image_tag @shop.logo_variant(:medium), class: "float-right"
|
||||
%span.clear
|
||||
|
||||
|
||||
Reference in New Issue
Block a user