From 283307ce04b0fc8ed36f36e89369b293f68752ac Mon Sep 17 00:00:00 2001 From: cubercsl <2014cais01@gmail.com> Date: Mon, 3 Mar 2025 21:52:37 +0800 Subject: [PATCH 1/3] refactor(printing): code cleanup Since we list all available languages in the print form, getting the submittable languages is not necessary. https://github.com/DOMjudge/domjudge/blob/1400212da97354dfa7a7eb373a8583d781d38a5a/webapp/src/Form/Type/PrintType.php#L21 Signed-off-by: cubercsl <2014cais01@gmail.com> --- webapp/src/Controller/Jury/PrintController.php | 9 --------- webapp/src/Controller/Team/MiscController.php | 5 ----- 2 files changed, 14 deletions(-) diff --git a/webapp/src/Controller/Jury/PrintController.php b/webapp/src/Controller/Jury/PrintController.php index 94d1991d15..e9ea3f550e 100644 --- a/webapp/src/Controller/Jury/PrintController.php +++ b/webapp/src/Controller/Jury/PrintController.php @@ -62,17 +62,8 @@ public function showAction(Request $request): Response ]); } - /** @var Language[] $languages */ - $languages = $this->em->createQueryBuilder() - ->from(Language::class, 'l') - ->select('l') - ->andWhere('l.allowSubmit = 1') - ->getQuery() - ->getResult(); - return $this->render('jury/print.html.twig', [ 'form' => $form, - 'languages' => $languages, ]); } } diff --git a/webapp/src/Controller/Team/MiscController.php b/webapp/src/Controller/Team/MiscController.php index 68ad4a292a..1ad3d4e7a1 100644 --- a/webapp/src/Controller/Team/MiscController.php +++ b/webapp/src/Controller/Team/MiscController.php @@ -190,13 +190,8 @@ public function printAction(Request $request): Response ]); } - $currentContest = $this->dj->getCurrentContest(); - /** @var Language[] $languages */ - $languages = $this->dj->getAllowedLanguagesForContest($currentContest); - return $this->render('team/print.html.twig', [ 'form' => $form, - 'languages' => $languages, ]); } From 047f4f726b9c3ca56d3dcc529c20015de3c93bd7 Mon Sep 17 00:00:00 2001 From: cubercsl <2014cais01@gmail.com> Date: Mon, 3 Mar 2025 21:56:36 +0800 Subject: [PATCH 2/3] fix(printing API): Allow printing in any language Since the UI allows selecting any available language or plain text, the API should also keep consistent behavior. Signed-off-by: cubercsl <2014cais01@gmail.com> --- webapp/src/Controller/API/PrintController.php | 4 ---- webapp/src/Service/DOMJudgeService.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/webapp/src/Controller/API/PrintController.php b/webapp/src/Controller/API/PrintController.php index ca4b0fb879..901015a04b 100644 --- a/webapp/src/Controller/API/PrintController.php +++ b/webapp/src/Controller/API/PrintController.php @@ -83,14 +83,10 @@ public function printAsTeam( ->createQueryBuilder() ->from(Language::class, "l") ->select("l.langid") - ->andWhere("l.allowSubmit = 1") ->andWhere("l.name = :name") ->setParameter("name", $print->language) ->getQuery() ->getOneOrNullResult(AbstractQuery::HYDRATE_SINGLE_SCALAR); - if ($langid === null) { - throw new BadRequestHttpException("Programming language not found."); - } } $decodedFile = base64_decode($print->fileContents, true); diff --git a/webapp/src/Service/DOMJudgeService.php b/webapp/src/Service/DOMJudgeService.php index 0f33af6659..faa9163285 100644 --- a/webapp/src/Service/DOMJudgeService.php +++ b/webapp/src/Service/DOMJudgeService.php @@ -766,7 +766,7 @@ public function printFile( $replaces = [ '[file]' => escapeshellarg($filename), '[original]' => escapeshellarg($origname), - '[language]' => escapeshellarg($language), + '[language]' => escapeshellarg($language ?? ''), '[username]' => escapeshellarg($username), '[teamname]' => escapeshellarg($teamname ?? ''), '[teamid]' => escapeshellarg($teamid ?? ''), From 64b47ec9c2e58210d6ce3e31a0414d1f9a08bd35 Mon Sep 17 00:00:00 2001 From: cubercsl <2014cais01@gmail.com> Date: Mon, 3 Mar 2025 21:58:54 +0800 Subject: [PATCH 3/3] fix(submit client): Allow printing in any language It is not necessary to select entry_porint when printing. Signed-off-by: cubercsl <2014cais01@gmail.com> --- submit/submit | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/submit/submit b/submit/submit index 5017ed230c..a0cafc6da8 100755 --- a/submit/submit +++ b/submit/submit @@ -506,7 +506,7 @@ elif contests: languages: list = [] problems: list = [] if my_contest and baseurl: - if 'allow_submit' in my_contest and not my_contest['allow_submit']: + if not args.print and 'allow_submit' in my_contest and not my_contest['allow_submit']: warn_user('Submissions for contest (temporarily) disabled') exit(1) languages = read_languages() @@ -610,23 +610,25 @@ for problem in problems: if not my_problem and not args.print: usage('No known problem specified or detected.') +if not args.print: # Guess entry point if not already specified. -if not entry_point and my_language['entry_point_required']: - if my_language['name'] == 'Java': - entry_point = filebase - elif my_language['name'] == 'Kotlin': - entry_point = kotlin_base_entry_point(filebase) + "Kt" - elif my_language['name'] == 'Python 3': - entry_point = filebase + "." + ext + if not entry_point and my_language['entry_point_required']: + if my_language['name'] == 'Java': + entry_point = filebase + elif my_language['name'] == 'Kotlin': + entry_point = kotlin_base_entry_point(filebase) + "Kt" + elif my_language['name'] == 'Python 3': + entry_point = filebase + "." + ext -if not entry_point and my_language['entry_point_required']: - error('Entry point required but not specified nor detected.') + if not entry_point and my_language['entry_point_required']: + error('Entry point required but not specified nor detected.') logging.debug(f"contest is `{my_contest['shortname']}'") if not args.print: logging.debug(f"problem is `{my_problem['label']}'") -logging.debug(f"language is `{my_language['name']}'") -logging.debug(f"entry_point is `{entry_point or ''}'") +logging.debug(f"language is `{my_language.get('name', '')}'") +if not args.print: + logging.debug(f"entry_point is `{entry_point or ''}'") logging.debug(f"url is `{baseurl}'") if args.print: