Skip to content

Commit 99a1a18

Browse files
committed
CWS API: Allow admin to override official status of submissions
1 parent 00bafa5 commit 99a1a18

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

cms/server/contest/handlers/api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ def post(self, task_name: str):
153153
# analysis mode.
154154
official = self.r_params["actual_phase"] == 0
155155

156+
# If the submission is performed by the administrator acting on behalf
157+
# of a contestant, allow overriding.
158+
if self.impersonated_by_admin:
159+
try:
160+
official = self.get_boolean_argument('override_official', official)
161+
except ValueError as err:
162+
self.json({"error": str(err)}, 400)
163+
return
164+
156165
try:
157166
submission = accept_submission(
158167
self.sql_session, self.service.file_cacher, self.current_user,

cms/server/contest/handlers/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ def is_api(self):
183183
"""Return whether it's an API request."""
184184
return self.api_request
185185

186+
def get_boolean_argument(self, name: str, default: bool) -> bool:
187+
"""Parse a Boolean request argument."""
188+
189+
arg = self.get_argument(name, "")
190+
if arg == "":
191+
return default
192+
193+
if arg == '0':
194+
return False
195+
elif arg == '1':
196+
return True
197+
else:
198+
raise ValueError(f"Cannot parse boolean argument {name}")
199+
186200

187201
class ContestListHandler(BaseHandler):
188202
def get(self):

0 commit comments

Comments
 (0)