Skip to content

Commit ddfb933

Browse files
committed
CWS API: Allow admin to override max number / min time checks
1 parent 2794f15 commit ddfb933

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

cms/server/contest/handlers/api.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,23 @@ def post(self, task_name: str):
158158
if self.impersonated_by_admin:
159159
try:
160160
official = self.get_boolean_argument('override_official', official)
161+
override_max_number = self.get_boolean_argument('override_max_number', False)
162+
override_min_interval = self.get_boolean_argument('override_min_interval', False)
161163
except ValueError as err:
162164
self.json({"error": str(err)}, 400)
163165
return
166+
else:
167+
override_max_number = False
168+
override_min_interval = False
164169

165170
try:
166171
submission = accept_submission(
167172
self.sql_session, self.service.file_cacher, self.current_user,
168173
task, self.timestamp, self.request.files,
169-
self.get_argument("language", None), official)
174+
self.get_argument("language", None), official,
175+
override_max_number=override_max_number,
176+
override_min_interval=override_min_interval,
177+
)
170178
self.sql_session.commit()
171179
except UnacceptableSubmission as e:
172180
logger.info("API submission rejected: `%s' - `%s'",

cms/server/contest/submission/workflow.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def accept_submission(
8686
tornado_files: dict[str, list["HTTPFile"]],
8787
language_name: str | None,
8888
official: bool,
89+
override_max_number: bool = False,
90+
override_min_interval: bool = False,
8991
) -> Submission:
9092
"""Process a contestant's request to submit a submission.
9193
@@ -105,6 +107,8 @@ def accept_submission(
105107
official: whether the submission was sent in during a regular
106108
contest phase (and should be counted towards the score/rank) or
107109
during the analysis mode.
110+
override_max_number: skip checks for the maximum number of submissions
111+
override_min_interval: skip checks for the minimum interval between submissions
108112
109113
return: the resulting submission, if all went well.
110114
@@ -118,23 +122,24 @@ def accept_submission(
118122

119123
# Check whether the contestant is allowed to submit.
120124

121-
if not check_max_number(sql_session, contest.max_submission_number,
122-
participation, contest=contest):
123-
raise UnacceptableSubmission(
124-
N_("Too many submissions!"),
125-
N_("You have reached the maximum limit of "
126-
"at most %d submissions among all tasks."),
127-
contest.max_submission_number)
125+
if not override_max_number:
126+
if not check_max_number(sql_session, contest.max_submission_number,
127+
participation, contest=contest):
128+
raise UnacceptableSubmission(
129+
N_("Too many submissions!"),
130+
N_("You have reached the maximum limit of "
131+
"at most %d submissions among all tasks."),
132+
contest.max_submission_number)
128133

129-
if not check_max_number(sql_session, task.max_submission_number,
130-
participation, task=task):
131-
raise UnacceptableSubmission(
132-
N_("Too many submissions!"),
133-
N_("You have reached the maximum limit of "
134-
"at most %d submissions on this task."),
135-
task.max_submission_number)
134+
if not check_max_number(sql_session, task.max_submission_number,
135+
participation, task=task):
136+
raise UnacceptableSubmission(
137+
N_("Too many submissions!"),
138+
N_("You have reached the maximum limit of "
139+
"at most %d submissions on this task."),
140+
task.max_submission_number)
136141

137-
if not is_last_minutes(timestamp, participation):
142+
if not override_min_interval and not is_last_minutes(timestamp, participation):
138143
if not check_min_interval(sql_session, contest.min_submission_interval,
139144
timestamp, participation, contest=contest):
140145
raise UnacceptableSubmission(

0 commit comments

Comments
 (0)