FEATURE: allow large icon to be uploaded in wizard

This commit is contained in:
Arpit Jalan 2018-06-19 21:07:02 +05:30
parent ae5d255f83
commit aedc61a3b4
3 changed files with 29 additions and 2 deletions

View File

@ -3843,7 +3843,7 @@ en:
description: "Icon image used to represent your site in web browsers that looks good at small sizes such as 32px by 32px."
apple_touch_icon_url:
label: "Large Icon"
description: "Icon image used to represent your site on modern devices that looks good at larger sizes. Recommended size is at least 144px by 144px."
description: "Icon image used to represent your site on modern devices that looks good at larger sizes. Recommended size is at least 512px by 512px."
homepage:
description: "We recommend showing the latest topics on your homepage, but you can also show categories (groups of topics) on the homepage if you prefer."

View File

@ -169,7 +169,25 @@ class Wizard
step.add_field(id: 'apple_touch_icon_url', type: 'image', value: SiteSetting.apple_touch_icon_url)
step.on_update do |updater|
updater.apply_settings(:favicon_url, :apple_touch_icon_url)
updater.apply_settings(:favicon_url)
if updater.fields[:apple_touch_icon_url] != SiteSetting.apple_touch_icon_url
upload = Upload.find_by_url(updater.fields[:apple_touch_icon_url])
dimensions = 180 # for apple touch icon
if upload && upload.width > dimensions && upload.height > dimensions
updater.update_setting(:large_icon_url, updater.fields[:apple_touch_icon_url])
apple_touch_icon_optimized = OptimizedImage.create_for(upload, dimensions, dimensions, filename: upload.original_filename)
original_file = File.new(Discourse.store.path_for(apple_touch_icon_optimized)) rescue nil
if original_file
apple_touch_icon_upload = UploadCreator.new(original_file, upload.original_filename).create_for(@wizard.user.id)
updater.update_setting(:apple_touch_icon_url, apple_touch_icon_upload.url)
end
apple_touch_icon_optimized.destroy! if apple_touch_icon_optimized.present?
else
updater.apply_settings(:apple_touch_icon_url)
end
end
end
end

View File

@ -237,6 +237,15 @@ describe Wizard::StepUpdater do
expect(SiteSetting.favicon_url).to eq('/uploads/favicon.png')
expect(SiteSetting.apple_touch_icon_url).to eq('/uploads/apple.png')
end
it "updates large_icon_url if the uploaded icon size is greater than 180x180" do
upload = Fabricate(:upload, width: 512, height: 512)
updater = wizard.create_updater('icons', apple_touch_icon_url: upload.url)
updater.update
expect(updater).to be_success
expect(SiteSetting.large_icon_url).to eq(upload.url)
end
end
context "emoji step" do