From 59cce07601cbac40c8e6f5af593ea957a57d209f Mon Sep 17 00:00:00 2001 From: slice Date: Sat, 30 Mar 2019 20:03:56 -0700 Subject: Add thumbnail, hero, and mascot back to Form::AdminSettings::KEYS (#10430) These will allow these images to be uploaded again on the admin settings page. --- app/models/form/admin_settings.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/models/form') diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 2d3aa726d..85a6e6dff 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -25,6 +25,9 @@ class Form::AdminSettings preview_sensitive_media custom_css profile_directory + thumbnail + hero + mascot ).freeze BOOLEAN_KEYS = %i( -- cgit From 85973f4f37c8b94422f267654018d0d7f88ba32b Mon Sep 17 00:00:00 2001 From: slice Date: Sun, 31 Mar 2019 22:30:46 -0700 Subject: Improvements to image upload validation and creation (#10431) * Check if image value is nil? before creating an image Check if uploaded images aren't nil before creating SiteUpload models for them. * Validate presence of file in SiteUpload * Fix file presence validation * Fabricate SiteUpload#file * Add link to Creative Commons license --- app/models/form/admin_settings.rb | 2 +- app/models/site_upload.rb | 1 + spec/fabricators/assets/TEAPOT | 6 ++++++ spec/fabricators/assets/utah_teapot.png | Bin 0 -> 248232 bytes spec/fabricators/site_upload_fabricator.rb | 1 + 5 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 spec/fabricators/assets/TEAPOT create mode 100644 spec/fabricators/assets/utah_teapot.png (limited to 'app/models/form') diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 85a6e6dff..d3af8c30f 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -67,7 +67,7 @@ class Form::AdminSettings KEYS.each do |key| value = instance_variable_get("@#{key}") - if UPLOAD_KEYS.include?(key) + if UPLOAD_KEYS.include?(key) && !value.nil? upload = SiteUpload.where(var: key).first_or_initialize(var: key) upload.update(file: value) else diff --git a/app/models/site_upload.rb b/app/models/site_upload.rb index 14d683767..cf10b30fc 100644 --- a/app/models/site_upload.rb +++ b/app/models/site_upload.rb @@ -18,6 +18,7 @@ class SiteUpload < ApplicationRecord has_attached_file :file validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/ + validates :file, presence: true validates :var, presence: true, uniqueness: true before_save :set_meta diff --git a/spec/fabricators/assets/TEAPOT b/spec/fabricators/assets/TEAPOT new file mode 100644 index 000000000..e624ecb4c --- /dev/null +++ b/spec/fabricators/assets/TEAPOT @@ -0,0 +1,6 @@ +This "Utah teapot" photograph is licensed under the Creative Commons +Attribution-Share Alike 3.0 Unported license: + https://creativecommons.org/licenses/by-sa/3.0/deed.en + +Original source of work: + https://commons.wikimedia.org/wiki/File:Utah_teapot_simple_2.png diff --git a/spec/fabricators/assets/utah_teapot.png b/spec/fabricators/assets/utah_teapot.png new file mode 100644 index 000000000..6708361e5 Binary files /dev/null and b/spec/fabricators/assets/utah_teapot.png differ diff --git a/spec/fabricators/site_upload_fabricator.rb b/spec/fabricators/site_upload_fabricator.rb index 4a171486f..2efc57e28 100644 --- a/spec/fabricators/site_upload_fabricator.rb +++ b/spec/fabricators/site_upload_fabricator.rb @@ -1,2 +1,3 @@ Fabricator(:site_upload) do + file { File.open(File.join(Rails.root, 'spec', 'fabricators', 'assets', 'utah_teapot.png')) } end -- cgit