diff options
author | Claire <claire.github-309c@sitedethib.com> | 2023-01-05 14:16:25 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2023-01-05 14:16:25 +0100 |
commit | 6c20dad201efdfaec59c37ce3f3ca4c7702b5274 (patch) | |
tree | b1df234db04b93b7d0c241d120019f03368850f4 /app/models/form | |
parent | 7e9d5bdbb9125197afb5b3df69ce49a79451d697 (diff) | |
parent | 18d00055f4f7e28a9a4cc81d3159072e9beb779d (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `README.md`: Upstream updated its README, while we have a completely different one. Kept our README. - `app/controllers/concerns/web_app_controller_concern.rb`: Conflict because of glitch-soc's theming system. Additionally, glitch-soc has different behavior regarding moved accounts. Ported some of the changes, but kept our overall behavior. - `app/javascript/packs/admin.js`: Code changes actually applied to `app/javascript/core/admin.js`
Diffstat (limited to 'app/models/form')
-rw-r--r-- | app/models/form/admin_settings.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index b53a82db2..b595529f8 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -83,6 +83,7 @@ class Form::AdminSettings validates :show_domain_blocks_rationale, inclusion: { in: %w(disabled users all) }, if: -> { defined?(@show_domain_blocks_rationale) } validates :media_cache_retention_period, :content_cache_retention_period, :backups_retention_period, numericality: { only_integer: true }, allow_blank: true, if: -> { defined?(@media_cache_retention_period) || defined?(@content_cache_retention_period) || defined?(@backups_retention_period) } validates :site_short_description, length: { maximum: 200 }, if: -> { defined?(@site_short_description) } + validate :validate_site_uploads KEYS.each do |key| define_method(key) do @@ -104,11 +105,16 @@ class Form::AdminSettings define_method("#{key}=") do |file| value = public_send(key) value.file = file + rescue Mastodon::DimensionsValidationError => e + errors.add(key.to_sym, e.message) end end def save - return false unless valid? + # NOTE: Annoyingly, files are processed and can error out before + # validations are called, and `valid?` clears errors… + # So for now, return early if errors aren't empty. + return false unless errors.empty? && valid? KEYS.each do |key| next if PSEUDO_KEYS.include?(key) || !instance_variable_defined?("@#{key}") @@ -141,4 +147,16 @@ class Form::AdminSettings value end end + + def validate_site_uploads + UPLOAD_KEYS.each do |key| + next unless instance_variable_defined?("@#{key}") + upload = instance_variable_get("@#{key}") + next if upload.valid? + + upload.errors.each do |error| + errors.import(error, attribute: key) + end + end + end end |