BURs: impose a maximum size limit on BURs.

Enforce a maximum size limit of 100 lines per BUR. Larger BURs should be
split into smaller chunks.
This commit is contained in:
evazion
2020-12-03 14:34:43 -06:00
parent 8a959b44df
commit 19adf92a39
2 changed files with 17 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
class BulkUpdateRequestProcessor
MAXIMUM_RENAME_COUNT = 200
MAXIMUM_SCRIPT_LENGTH = 100
include ActiveModel::Validations
@@ -8,6 +9,7 @@ class BulkUpdateRequestProcessor
attr_reader :bulk_update_request
delegate :script, :forum_topic, to: :bulk_update_request
validate :validate_script
validate :validate_script_length
def initialize(bulk_update_request)
@bulk_update_request = bulk_update_request
@@ -109,6 +111,12 @@ class BulkUpdateRequestProcessor
end
end
def validate_script_length
if commands.size > MAXIMUM_SCRIPT_LENGTH
errors[:base] << "Bulk update request is too long (maximum size: #{MAXIMUM_SCRIPT_LENGTH} lines). Split your request into smaller chunks and try again."
end
end
def process!(approver)
ActiveRecord::Base.transaction do
commands.map do |command, *args|

View File

@@ -373,6 +373,15 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
assert_equal(["Can't create implication a -> b ('a' must have a wiki page; 'b' must have a wiki page)"], @bur.errors.full_messages)
end
end
context "a bulk update request that is too long" do
should "fail" do
@bur = build(:bulk_update_request, script: "nuke touhou\n" * 200)
assert_equal(false, @bur.valid?)
assert_equal(["Bulk update request is too long (maximum size: 100 lines). Split your request into smaller chunks and try again."], @bur.errors.full_messages)
end
end
end
context "when the script is updated" do