Admin setting for the maximum upload size

- Admin -> Settings: maximum upload size per file (1-1024 MB, default 50),
  stored in a new settings table and read on each use, so a change applies
  to every process at once
- Enforced by attachment validation and the direct-upload endpoint; upload
  forms, bulk upload and Admin -> About show the current limit
- .sam.zip import accepts files up to 1 GB to match

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 09:45:12 -05:00
1 parent 4f548f3874
commit ef7cd2efba
16 files changed
+186 -13

No files matched your search

+5 -2
View File
@@ -7,7 +7,9 @@ module UploadValidation
application/pdf text/plain application/gpx+xml application/xml text/xml
text/csv application/vnd.google-earth.kml+xml application/octet-stream
].freeze
MAX_SIZE = 50.megabytes
# Set by admins (Admin → Settings), default 50 MB.
def self.max_size = Setting.max_upload_bytes
class_methods do
def validates_uploads(*names)
@@ -18,7 +20,8 @@ module UploadValidation
unless ALLOWED_CONTENT_TYPES.include?(att.blob.content_type)
errors.add(name, "#{att.filename} is not an allowed file type")
end
errors.add(name, "#{att.filename} is too large") if att.blob.byte_size > MAX_SIZE
limit = UploadValidation.max_size
errors.add(name, "#{att.filename} is over the #{limit / 1.megabyte} MB upload limit") if att.blob.byte_size > limit
end
end
end
+43
View File
@@ -0,0 +1,43 @@
# App-wide settings an admin can change (Admin → Settings), stored as
# key/value rows. Read straight from the database each time, so a change
# applies to every server process at once.
#
# Setting.max_upload_mb # => 50
# Setting.max_upload_bytes # => 52428800
class Setting < ApplicationRecord
INTEGERS = {
"max_upload_mb" => { default: 50, in: 1..1024, label: "Maximum upload size (MB)" }
}.freeze
validates :key, presence: true, uniqueness: true, inclusion: { in: INTEGERS.keys }
validate :value_in_range
class << self
def max_upload_mb = integer("max_upload_mb")
def max_upload_bytes = max_upload_mb.megabytes
def integer(key)
definition = INTEGERS.fetch(key)
value = find_by(key: key)&.value
value.present? ? value.to_i.clamp(definition[:in]) : definition[:default]
end
# Saves several settings; returns the records (check #errors) or [].
def update_integers(values)
records = values.to_h.slice(*INTEGERS.keys).map do |key, value|
find_or_initialize_by(key: key).tap { _1.value = value.to_s.strip }
end
transaction { records.each { _1.save || raise(ActiveRecord::Rollback) } }
records
end
end
private
def value_in_range
definition = INTEGERS[key] or return
unless value.to_s.match?(/\A\d+\z/) && definition[:in].cover?(value.to_i)
errors.add(:base, "#{definition[:label]} must be a whole number from #{definition[:in].min} to #{definition[:in].max}")
end
end
end
+1
View File
@@ -48,6 +48,7 @@ class SystemInfo
"Single sign-on" => Sso.enabled? ? "#{Sso.label}#{', password sign-in off' unless Sso.password_login?}" : "not configured",
"AI logbook transcription" => ENV["ANTHROPIC_API_KEY"].present? ? "on (#{LogbookTranscriber::MODEL})" : "no API key",
"Email" => MailSettings.configured? ? ActionMailer::Base.delivery_method.to_s.upcase : "not configured",
"Upload limit" => "#{Setting.max_upload_mb} MB per file",
"HTTPS enforced" => Rails.application.config.force_ssl ? "yes" : "no",
"File storage" => ActiveStorage::Blob.service.class.name.demodulize.delete_suffix("Service")
}