Commit b0a16320 authored by Douwe Maan's avatar Douwe Maan

Rename BlobViewer max_size to overridable_max_size and absolute_max_size to max_size

parent acffc062
...@@ -226,7 +226,7 @@ module BlobHelper ...@@ -226,7 +226,7 @@ module BlobHelper
def open_raw_blob_button(blob) def open_raw_blob_button(blob)
return if blob.empty? return if blob.empty?
if blob.raw_binary? || blob.stored_externally? if blob.raw_binary? || blob.stored_externally?
icon = icon('download') icon = icon('download')
title = 'Download' title = 'Download'
...@@ -242,9 +242,9 @@ module BlobHelper ...@@ -242,9 +242,9 @@ module BlobHelper
case viewer.render_error case viewer.render_error
when :too_large when :too_large
max_size = max_size =
if viewer.absolutely_too_large? if viewer.can_override_max_size?
viewer.absolute_max_size viewer.overridable_max_size
elsif viewer.too_large? else
viewer.max_size viewer.max_size
end end
"it is larger than #{number_to_human_size(max_size)}" "it is larger than #{number_to_human_size(max_size)}"
......
...@@ -5,8 +5,8 @@ module BlobViewer ...@@ -5,8 +5,8 @@ module BlobViewer
included do included do
self.loading_partial_name = 'loading_auxiliary' self.loading_partial_name = 'loading_auxiliary'
self.type = :auxiliary self.type = :auxiliary
self.overridable_max_size = 100.kilobytes
self.max_size = 100.kilobytes self.max_size = 100.kilobytes
self.absolute_max_size = 100.kilobytes
end end
end end
end end
...@@ -2,7 +2,7 @@ module BlobViewer ...@@ -2,7 +2,7 @@ module BlobViewer
class Base class Base
PARTIAL_PATH_PREFIX = 'projects/blob/viewers'.freeze PARTIAL_PATH_PREFIX = 'projects/blob/viewers'.freeze
class_attribute :partial_name, :loading_partial_name, :type, :extensions, :file_types, :load_async, :binary, :switcher_icon, :switcher_title, :max_size, :absolute_max_size class_attribute :partial_name, :loading_partial_name, :type, :extensions, :file_types, :load_async, :binary, :switcher_icon, :switcher_title, :overridable_max_size, :max_size
self.loading_partial_name = 'loading' self.loading_partial_name = 'loading'
...@@ -59,16 +59,24 @@ module BlobViewer ...@@ -59,16 +59,24 @@ module BlobViewer
self.class.load_async? && render_error.nil? self.class.load_async? && render_error.nil?
end end
def too_large? def exceeds_overridable_max_size?
max_size && blob.raw_size > max_size overridable_max_size && blob.raw_size > overridable_max_size
end end
def absolutely_too_large? def exceeds_max_size?
absolute_max_size && blob.raw_size > absolute_max_size max_size && blob.raw_size > max_size
end end
def can_override_max_size? def can_override_max_size?
too_large? && !absolutely_too_large? exceeds_overridable_max_size? && !exceeds_max_size?
end
def too_large?
if override_max_size
exceeds_max_size?
else
exceeds_overridable_max_size?
end
end end
# This method is used on the server side to check whether we can attempt to # This method is used on the server side to check whether we can attempt to
...@@ -83,7 +91,7 @@ module BlobViewer ...@@ -83,7 +91,7 @@ module BlobViewer
# binary from `blob_raw_url` and does its own format validation and error # binary from `blob_raw_url` and does its own format validation and error
# rendering, especially for potentially large binary formats. # rendering, especially for potentially large binary formats.
def render_error def render_error
if override_max_size ? absolutely_too_large? : too_large? if too_large?
:too_large :too_large
end end
end end
......
...@@ -4,8 +4,8 @@ module BlobViewer ...@@ -4,8 +4,8 @@ module BlobViewer
included do included do
self.load_async = false self.load_async = false
self.max_size = 10.megabytes self.overridable_max_size = 10.megabytes
self.absolute_max_size = 50.megabytes self.max_size = 50.megabytes
end end
end end
end end
...@@ -4,8 +4,8 @@ module BlobViewer ...@@ -4,8 +4,8 @@ module BlobViewer
included do included do
self.load_async = true self.load_async = true
self.max_size = 2.megabytes self.overridable_max_size = 2.megabytes
self.absolute_max_size = 5.megabytes self.max_size = 5.megabytes
end end
def prepare! def prepare!
......
...@@ -5,7 +5,7 @@ module BlobViewer ...@@ -5,7 +5,7 @@ module BlobViewer
self.partial_name = 'text' self.partial_name = 'text'
self.binary = false self.binary = false
self.max_size = 1.megabyte self.overridable_max_size = 1.megabyte
self.absolute_max_size = 10.megabytes self.max_size = 10.megabytes
end end
end end
...@@ -118,8 +118,8 @@ describe BlobHelper do ...@@ -118,8 +118,8 @@ describe BlobHelper do
Class.new(BlobViewer::Base) do Class.new(BlobViewer::Base) do
include BlobViewer::ServerSide include BlobViewer::ServerSide
self.max_size = 1.megabyte self.overridable_max_size = 1.megabyte
self.absolute_max_size = 5.megabytes self.max_size = 5.megabytes
self.type = :rich self.type = :rich
end end
end end
......
...@@ -11,8 +11,8 @@ describe BlobViewer::Base, model: true do ...@@ -11,8 +11,8 @@ describe BlobViewer::Base, model: true do
self.extensions = %w(pdf) self.extensions = %w(pdf)
self.binary = true self.binary = true
self.max_size = 1.megabyte self.overridable_max_size = 1.megabyte
self.absolute_max_size = 5.megabytes self.max_size = 5.megabytes
end end
end end
...@@ -69,45 +69,45 @@ describe BlobViewer::Base, model: true do ...@@ -69,45 +69,45 @@ describe BlobViewer::Base, model: true do
end end
end end
describe '#too_large?' do describe '#exceeds_overridable_max_size?' do
context 'when the blob size is larger than the max size' do context 'when the blob size is larger than the overridable max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
it 'returns true' do it 'returns true' do
expect(viewer.too_large?).to be_truthy expect(viewer.exceeds_overridable_max_size?).to be_truthy
end end
end end
context 'when the blob size is smaller than the max size' do context 'when the blob size is smaller than the overridable max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) }
it 'returns false' do it 'returns false' do
expect(viewer.too_large?).to be_falsey expect(viewer.exceeds_overridable_max_size?).to be_falsey
end end
end end
end end
describe '#absolutely_too_large?' do describe '#exceeds_max_size?' do
context 'when the blob size is larger than the absolute max size' do context 'when the blob size is larger than the max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) }
it 'returns true' do it 'returns true' do
expect(viewer.absolutely_too_large?).to be_truthy expect(viewer.exceeds_max_size?).to be_truthy
end end
end end
context 'when the blob size is smaller than the absolute max size' do context 'when the blob size is smaller than the max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
it 'returns false' do it 'returns false' do
expect(viewer.absolutely_too_large?).to be_falsey expect(viewer.exceeds_max_size?).to be_falsey
end end
end end
end end
describe '#can_override_max_size?' do describe '#can_override_max_size?' do
context 'when the blob size is larger than the max size' do context 'when the blob size is larger than the overridable max size' do
context 'when the blob size is larger than the absolute max size' do context 'when the blob size is larger than the max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) }
it 'returns false' do it 'returns false' do
...@@ -115,7 +115,7 @@ describe BlobViewer::Base, model: true do ...@@ -115,7 +115,7 @@ describe BlobViewer::Base, model: true do
end end
end end
context 'when the blob size is smaller than the absolute max size' do context 'when the blob size is smaller than the max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
it 'returns true' do it 'returns true' do
...@@ -124,7 +124,7 @@ describe BlobViewer::Base, model: true do ...@@ -124,7 +124,7 @@ describe BlobViewer::Base, model: true do
end end
end end
context 'when the blob size is smaller than the max size' do context 'when the blob size is smaller than the overridable max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) }
it 'returns false' do it 'returns false' do
...@@ -139,7 +139,7 @@ describe BlobViewer::Base, model: true do ...@@ -139,7 +139,7 @@ describe BlobViewer::Base, model: true do
viewer.override_max_size = true viewer.override_max_size = true
end end
context 'when the blob size is larger than the absolute max size' do context 'when the blob size is larger than the max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 10.megabytes) }
it 'returns :too_large' do it 'returns :too_large' do
...@@ -147,7 +147,7 @@ describe BlobViewer::Base, model: true do ...@@ -147,7 +147,7 @@ describe BlobViewer::Base, model: true do
end end
end end
context 'when the blob size is smaller than the absolute max size' do context 'when the blob size is smaller than the max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
it 'returns nil' do it 'returns nil' do
...@@ -157,7 +157,7 @@ describe BlobViewer::Base, model: true do ...@@ -157,7 +157,7 @@ describe BlobViewer::Base, model: true do
end end
context 'when the max size is not overridden' do context 'when the max size is not overridden' do
context 'when the blob size is larger than the max size' do context 'when the blob size is larger than the overridable max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 2.megabytes) }
it 'returns :too_large' do it 'returns :too_large' do
...@@ -165,7 +165,7 @@ describe BlobViewer::Base, model: true do ...@@ -165,7 +165,7 @@ describe BlobViewer::Base, model: true do
end end
end end
context 'when the blob size is smaller than the max size' do context 'when the blob size is smaller than the overridable max size' do
let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) } let(:blob) { fake_blob(path: 'file.pdf', size: 10.kilobytes) }
it 'returns nil' do it 'returns nil' do
......
...@@ -10,8 +10,8 @@ describe 'projects/blob/_viewer.html.haml', :view do ...@@ -10,8 +10,8 @@ describe 'projects/blob/_viewer.html.haml', :view do
include BlobViewer::Rich include BlobViewer::Rich
self.partial_name = 'text' self.partial_name = 'text'
self.max_size = 1.megabyte self.overridable_max_size = 1.megabyte
self.absolute_max_size = 5.megabytes self.max_size = 5.megabytes
self.load_async = true self.load_async = true
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment