DEV: move max_attachment_size_for_user to private class method

This commit is contained in:
Gabriel Grubba 2024-08-16 10:39:01 -03:00
parent b045591e40
commit 5d5ae0b715
No known key found for this signature in database
GPG Key ID: 5FE41764F62D556C

View File

@ -227,7 +227,7 @@ class UploadsController < ApplicationController
"upload.attachments.too_large_humanized",
max_size:
ActiveSupport::NumberHelper.number_to_human_size(
UploadsController.max_attachment_size_for_user(current_user).kilobytes,
max_attachment_size_for_user(current_user).kilobytes,
),
),
)
@ -276,7 +276,7 @@ class UploadsController < ApplicationController
if url.present? && is_api
maximum_upload_size = [
SiteSetting.max_image_size_kb,
UploadsController.max_attachment_size_for_user(current_user),
max_attachment_size_for_user(current_user),
].max.kilobytes
tempfile =
begin
@ -318,7 +318,7 @@ class UploadsController < ApplicationController
private
def self.max_attachment_size_for_user(user)
def max_attachment_size_for_user(user)
if user.id == Discourse::SYSTEM_USER_ID && !SiteSetting.system_user_max_attachment_size_kb.zero?
SiteSetting.system_user_max_attachment_size_kb
else
@ -331,7 +331,7 @@ class UploadsController < ApplicationController
# they may have already been reduced in size by preprocessors)
def attachment_too_big?(file_name, file_size)
!FileHelper.is_supported_image?(file_name) &&
file_size >= UploadsController.max_attachment_size_for_user(current_user).kilobytes
file_size >= max_attachment_size_for_user(current_user).kilobytes
end
# Gifs are not resized on the client and not reduced in size by UploadCreator