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:
@@ -1,5 +1,6 @@
|
|||||||
class BulkUpdateRequestProcessor
|
class BulkUpdateRequestProcessor
|
||||||
MAXIMUM_RENAME_COUNT = 200
|
MAXIMUM_RENAME_COUNT = 200
|
||||||
|
MAXIMUM_SCRIPT_LENGTH = 100
|
||||||
|
|
||||||
include ActiveModel::Validations
|
include ActiveModel::Validations
|
||||||
|
|
||||||
@@ -8,6 +9,7 @@ class BulkUpdateRequestProcessor
|
|||||||
attr_reader :bulk_update_request
|
attr_reader :bulk_update_request
|
||||||
delegate :script, :forum_topic, to: :bulk_update_request
|
delegate :script, :forum_topic, to: :bulk_update_request
|
||||||
validate :validate_script
|
validate :validate_script
|
||||||
|
validate :validate_script_length
|
||||||
|
|
||||||
def initialize(bulk_update_request)
|
def initialize(bulk_update_request)
|
||||||
@bulk_update_request = bulk_update_request
|
@bulk_update_request = bulk_update_request
|
||||||
@@ -109,6 +111,12 @@ class BulkUpdateRequestProcessor
|
|||||||
end
|
end
|
||||||
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)
|
def process!(approver)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
commands.map do |command, *args|
|
commands.map do |command, *args|
|
||||||
|
|||||||
@@ -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)
|
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
|
||||||
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
|
end
|
||||||
|
|
||||||
context "when the script is updated" do
|
context "when the script is updated" do
|
||||||
|
|||||||
Reference in New Issue
Block a user