feat: allow configuring attachment upload limit (#12835)

## Summary
- add a configurable MAXIMUM_FILE_UPLOAD_SIZE installation setting and
surface it through super admin and global config payloads
- apply the configurable limit to attachment validations and shared
upload helpers on dashboard and widget
- introduce a reusable helper with unit tests for parsing the limit and
extend attachment specs for configurability


------
[Codex
Task](https://chatgpt.com/codex/tasks/task_e_6912644786b08326bc8dee9401af6d0a)

---------

Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
Co-authored-by: iamsivin <iamsivin@gmail.com>
This commit is contained in:
Sojan Jose
2025-11-17 14:03:08 -08:00
committed by GitHub
parent 93374f4327
commit bf806f0c28
16 changed files with 204 additions and 46 deletions

View File

@@ -154,4 +154,39 @@ RSpec.describe Attachment do
end
end
end
describe 'file size validation' do
let(:attachment) { message.attachments.new(account_id: message.account_id, file_type: :image) }
before do
allow(GlobalConfigService).to receive(:load).and_call_original
end
it 'respects configured limit' do
allow(GlobalConfigService).to receive(:load)
.with('MAXIMUM_FILE_UPLOAD_SIZE', 40)
.and_return('5')
attachment.errors.clear
attachment.send(:validate_file_size, 4.megabytes)
expect(attachment.errors[:file]).to be_empty
attachment.errors.clear
attachment.send(:validate_file_size, 6.megabytes)
expect(attachment.errors[:file]).to include('size is too big')
end
it 'falls back to default when configured limit is invalid' do
allow(GlobalConfigService).to receive(:load)
.with('MAXIMUM_FILE_UPLOAD_SIZE', 40)
.and_return('-10')
attachment.errors.clear
attachment.send(:validate_file_size, 41.megabytes)
expect(attachment.errors[:file]).to include('size is too big')
end
end
end