Skip to content

Commit

Permalink
Limit number of submissions that can be created with batch create.
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanzdosilovic committed Jan 16, 2020
1 parent 87859b5 commit 595c7e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ def create
end

def batch_create
number_of_submissions = params[:_json].try(:size).to_i

if number_of_submissions > Config::MAX_SUBMISSION_BATCH_SIZE
render json: {
error: "number of submissions in batch create should be less than or equal to #{Config::MAX_SUBMISSION_BATCH_SIZE}"
}, status: :bad_request
return
elsif number_of_submissions == 0
render json: {
error: "there should be at least one submission in batch create"
}, status: :bad_request
return
end

submissions = params[:_json].each.collect { |p| Submission.new(submission_params(p)) }

response = []
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module Config
MAX_NUMBER_OF_RUNS = (ENV['MAX_NUMBER_OF_RUNS'].presence || 20).to_i
REDIRECT_STDERR_TO_STDOUT = ENV['REDIRECT_STDERR_TO_STDOUT'] == "true"
MAX_EXTRACT_SIZE = (ENV['MAX_EXTRACT_SIZE'].presence || 10240).to_i
MAX_SUBMISSION_BATCH_SIZE = (ENV['MAX_SUBMISSION_BATCH_SIZE'].presence || 20).to_i

def self.config_info
@@default_confg ||= {
Expand Down Expand Up @@ -62,7 +63,8 @@ def self.config_info
"number_of_runs": NUMBER_OF_RUNS,
"max_number_of_runs": MAX_NUMBER_OF_RUNS,
"redirect_stderr_to_stdout": REDIRECT_STDERR_TO_STDOUT,
"max_extract_size": MAX_EXTRACT_SIZE
"max_extract_size": MAX_EXTRACT_SIZE,
"max_submission_batch_size": MAX_SUBMISSION_BATCH_SIZE
}
end
end
6 changes: 5 additions & 1 deletion judge0-api.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,8 @@ REDIRECT_STDERR_TO_STDOUT=

# Maximum total size (in kilobytes) of extracted files from archive.
# Default: 10240, i.e. maximum of 10MB in total can be extracted.
MAX_EXTRACT_SIZE=
MAX_EXTRACT_SIZE=

# Maximum number of submissions that can be created with batch create.
# Default: 20
MAX_SUBMISSION_BATCH_SIZE=

0 comments on commit 595c7e1

Please sign in to comment.