Creator Settings: Removed SVG files as an option for logo upload (#15662)

This commit is contained in:
Nick Taylor 2021-12-03 10:47:42 -05:00 committed by GitHub
parent 8c126ca2e0
commit 6d79fc94a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 18 deletions

View file

@ -20,8 +20,7 @@ module Admin
if settings_params[:logo]
logo_uploader = upload_logo(settings_params[:logo])
::Settings::General.original_logo = logo_uploader.url
# An SVG will not be resized, hence we apply the OR statements below to populate SETTINGS consistently.
::Settings::General.resized_logo = logo_uploader.resized_logo.url || logo_uploader.url
::Settings::General.resized_logo = logo_uploader.resized_logo.url
end
end
current_user.update!(

View file

@ -26,9 +26,6 @@ class BaseUploader < CarrierWave::Uploader::Base
# strip EXIF (and GPS) data
def strip_exif
# svg's do not contain exif or gps data
return if file.content_type.include?("svg")
manipulate! do |image|
image.strip unless image.frames.count > FRAME_STRIP_MAX
image = yield(image) if block_given?

View file

@ -1,9 +1,9 @@
class LogoUploader < BaseUploader
MAX_FILE_SIZE = 3.megabytes
STORE_DIRECTORY = "uploads/logos/".freeze
EXTENSION_ALLOWLIST = %w[svg png jpg jpeg jpe].freeze
IMAGE_TYPE_ALLOWLIST = %i[svg png jpg jpeg jpe].freeze
CONTENT_TYPE_ALLOWLIST = %w[image/svg+xml image/png image/jpg image/jpeg].freeze
EXTENSION_ALLOWLIST = %w[png jpg jpeg jpe].freeze
IMAGE_TYPE_ALLOWLIST = %i[png jpg jpeg jpe].freeze
CONTENT_TYPE_ALLOWLIST = %w[image/png image/jpg image/jpeg].freeze
def store_dir
STORE_DIRECTORY
@ -31,7 +31,7 @@ class LogoUploader < BaseUploader
"original_logo_#{random_string}.#{file.extension}" if original_filename
end
version :resized_logo, if: :not_svg? do
version :resized_logo do
process resize_to_limit: [nil, 80]
def full_filename(_for_file = file)
"resized_logo_#{random_string}.#{file.extension}" if original_filename
@ -43,8 +43,4 @@ class LogoUploader < BaseUploader
def random_string
SecureRandom.alphanumeric(20)
end
def not_svg?(file)
file.content_type.exclude?("svg")
end
end

View file

@ -11,7 +11,7 @@
<%= label_tag :logo, class: "crayons-field__label" do %>
Logo
<span class="crayons-field__required crayons-tooltip" data-tooltip="This will set the logo for your Forem" aria-describedby="logo-subtitle"></span>
<p id="logo-subtitle" class="crayons-field__description">Ideally SVG, but PNG or JPEG will work, too.</p>
<p id="logo-subtitle" class="crayons-field__description">You can upload a PNG or JPEG image.</p>
<% end %>
<div class="flex flex-1 gap-4">
<%= file_field_tag :logo, accept: @logo_allowed_types.to_s, data: { "max-file-size-mb": @max_file_size.to_s, action: "change->creator-settings#previewLogo" }, aria: { describedby: "logo-subtitle" } %>

View file

@ -32,7 +32,7 @@ describe LogoUploader, type: :uploader do
describe "formats" do
it "permits a set of extensions" do
expect(uploader.extension_allowlist).to eq(%w[svg png jpg jpeg jpe])
expect(uploader.extension_allowlist).to eq(%w[png jpg jpeg jpe])
end
it "permits jpegs" do
@ -45,9 +45,8 @@ describe LogoUploader, type: :uploader do
expect(uploader).to be_format("png")
end
it "permits svgs" do
uploader.store!(image_svg)
expect(uploader).to be_format("svg")
it "rejects unsupported formats like SVG" do
expect { uploader.store!(image_svg) }.to raise_error(CarrierWave::IntegrityError)
end
it "rejects unsupported formats like webp" do