Skip to content

Commit 4684bb6

Browse files
committed
Add config option to disable ranking information for teams.
You likely still want to make the contest non-public to also 'hide' any ranking information from the public.
1 parent dd3244f commit 4684bb6

File tree

7 files changed

+80
-39
lines changed

7 files changed

+80
-39
lines changed

etc/db-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@
318318
2: After first submission
319319
regex: /^\d+$/
320320
error_message: A value between 0 and 2 is required.
321+
- name: enable_ranking
322+
type: bool
323+
default_value: true
324+
public: true
325+
description: If disabled, no ranking information is shown to contestants.
321326
- category: Authentication
322327
description: Options related to authentication.
323328
items:

webapp/src/Controller/API/ScoreboardController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use OpenApi\Attributes as OA;
2323
use Symfony\Component\HttpFoundation\Request;
2424
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
25+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
2526

2627
#[Rest\Route('/contests/{cid}/scoreboard')]
2728
#[OA\Tag(name: 'Scoreboard')]
@@ -106,6 +107,10 @@ public function getScoreboardAction(
106107
#[MapQueryParameter]
107108
bool $strict = false,
108109
): Scoreboard {
110+
if (!$this->config->get('enable_ranking') && !$this->dj->checkrole('jury')) {
111+
throw new BadRequestHttpException('Scoreboard is not available.');
112+
}
113+
109114
$filter = new Filter();
110115
if ($category) {
111116
$filter->categories = [$category];

webapp/src/Controller/Team/ScoreboardController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Service\ScoreboardService;
1010
use Doctrine\ORM\EntityManagerInterface;
1111
use Symfony\Component\ExpressionLanguage\Expression;
12+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1213
use Symfony\Component\Security\Http\Attribute\IsGranted;
1314
use Symfony\Component\HttpFoundation\Request;
1415
use Symfony\Component\HttpFoundation\Response;
@@ -32,6 +33,10 @@ public function __construct(
3233
#[Route(path: '/scoreboard', name: 'team_scoreboard')]
3334
public function scoreboardAction(Request $request): Response
3435
{
36+
if ($this->config->get('enable_ranking')) {
37+
throw new BadRequestHttpException('Scoreboard is not available.');
38+
}
39+
3540
$user = $this->dj->getUser();
3641
$response = new Response();
3742
$contest = $this->dj->getCurrentContest($user->getTeam()->getTeamid());
@@ -51,6 +56,10 @@ public function scoreboardAction(Request $request): Response
5156
#[Route(path: '/team/{teamId<\d+>}', name: 'team_team')]
5257
public function teamAction(Request $request, int $teamId): Response
5358
{
59+
if ($this->config->get('enable_ranking')) {
60+
throw new BadRequestHttpException('Scoreboard is not available.');
61+
}
62+
5463
/** @var Team|null $team */
5564
$team = $this->em->getRepository(Team::class)->find($teamId);
5665
if ($team && $team->getCategory() && !$team->getCategory()->getVisible() && $teamId !== $this->dj->getUser()->getTeamId()) {

webapp/src/Twig/TwigExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public function getGlobals(): array
156156
$this->config->get('data_source') === DOMJudgeService::DATA_SOURCE_CONFIGURATION_AND_LIVE_EXTERNAL,
157157
'doc_links' => $this->dj->getDocLinks(),
158158
'allow_registration' => $selfRegistrationCategoriesCount !== 0,
159+
'enable_ranking' => $this->config->get('enable_ranking'),
159160
];
160161
}
161162

webapp/templates/partials/scoreboard_summary.html.twig

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
{% if showAffiliationLogos %}
66
{% set summaryColspan = summaryColspan + 1 %}
77
{% endif %}
8+
{% if not enable_ranking %}
9+
{% set summaryColspan = summaryColspan - 1 %}
10+
{% endif %}
811
<td class="scoresummary" title="Summary" colspan="{{ summaryColspan }}">Summary</td>
9-
{% if scoreboard.showPoints %}
10-
<td class="scorenc"></td>
11-
{% else %}
12-
<td title="total solved" class="scorenc">
13-
{{ scoreboard.summary.numberOfPoints(sortOrder) }}
14-
</td>
12+
{% if enable_ranking %}
13+
{% if scoreboard.showPoints %}
14+
<td class="scorenc"></td>
15+
{% else %}
16+
<td title="total solved" class="scorenc">
17+
{{ scoreboard.summary.numberOfPoints(sortOrder) }}
18+
</td>
19+
{% endif %}
20+
<td></td>
1521
{% endif %}
16-
<td></td>
1722
{% for problem in scoreboard.problems %}
1823
{% set summary = scoreboard.summary.problem(problem.probid) %}
1924
<td style="text-align: left;">

webapp/templates/partials/scoreboard_table.html.twig

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
3333
{# output table column groups (for the styles) #}
3434
<colgroup>
35-
<col id="scorerank"/>
35+
{% if enable_ranking %}
36+
<col id="scorerank"/>
37+
{% endif %}
3638
{% if showFlags %}
3739
<col id="scoreflags"/>
3840
{% else %}
@@ -43,10 +45,12 @@
4345
{% endif %}
4446
<col id="scoreteamname"/>
4547
</colgroup>
46-
<colgroup>
47-
<col id="scoresolv"/>
48-
<col id="scoretotal"/>
49-
</colgroup>
48+
{% if enable_ranking %}
49+
<colgroup>
50+
<col id="scoresolv"/>
51+
<col id="scoretotal"/>
52+
</colgroup>
53+
{% endif %}
5054
<colgroup>
5155
{% if showTeamSubmissions or jury %}
5256
{% for problem in problems %}
@@ -62,9 +66,13 @@
6266
6367
<thead>
6468
<tr class="scoreheader" data-static="{{ static }}">
65-
<th title="rank" scope="col">rank</th>
69+
{% if enable_ranking %}
70+
<th title="rank" scope="col">rank</th>
71+
{% endif %}
6672
<th title="team name" scope="col" colspan="{{ teamColspan }}">team</th>
67-
<th title="# solved / penalty time" colspan="2" scope="col">score</th>
73+
{% if enable_ranking %}
74+
<th title="# solved / penalty time" colspan="2" scope="col">score</th>
75+
{% endif %}
6876
{% if showTeamSubmissions or jury %}
6977
{% for problem in problems %}
7078
{% set link = null %}
@@ -127,16 +135,18 @@
127135
{% set color = score.team.category.color %}
128136
{% endif %}
129137
<tr class="{{ classes | join(' ') }}" id="team:{{ score.team.teamid }}">
130-
<td class="scorepl {{medalColor}}">
131-
{# Only print rank when score is different from the previous team #}
132-
{% if not displayRank %}
133-
?
134-
{% elseif previousTeam is null or scoreboard.scores[previousTeam.teamid].rank != score.rank %}
135-
{{ score.rank }}
136-
{% else %}
137-
{% endif %}
138-
{% set previousTeam = score.team %}
139-
</td>
138+
{% if enable_ranking %}
139+
<td class="scorepl {{medalColor}}">
140+
{# Only print rank when score is different from the previous team #}
141+
{% if not displayRank %}
142+
?
143+
{% elseif previousTeam is null or scoreboard.scores[previousTeam.teamid].rank != score.rank %}
144+
{{ score.rank }}
145+
{% else %}
146+
{% endif %}
147+
{% set previousTeam = score.team %}
148+
</td>
149+
{% endif %}
140150
<td class="scoreaf">
141151
{% if showFlags %}
142152
{% if score.team.affiliation %}
@@ -220,12 +230,14 @@
220230
{% if scoreInSeconds %}
221231
{% set totalTime = totalTime | printTimeRelative %}
222232
{% endif %}
223-
{% set totalPoints = score.numPoints %}
224-
<td class="scorenc">{{ totalPoints }}</td>
225-
{% if scoreboard.getRuntimeAsScoreTiebreaker() %}
226-
<td class="scorett">{{ "%0.3f s" | format(score.totalRuntime/1000.0) }}</td>
227-
{% else %}
228-
<td class="scorett">{{ totalTime }}</td>
233+
{% if enable_ranking %}
234+
{% set totalPoints = score.numPoints %}
235+
<td class="scorenc">{{ totalPoints }}</td>
236+
{% if scoreboard.getRuntimeAsScoreTiebreaker() %}
237+
<td class="scorett">{{ "%0.3f s" | format(score.totalRuntime/1000.0) }}</td>
238+
{% else %}
239+
<td class="scorett">{{ totalTime }}</td>
240+
{% endif %}
229241
{% endif %}
230242
231243
{% if showTeamSubmissions or jury %}
@@ -235,11 +247,13 @@
235247
{% set matrixItem = scoreboard.matrix[score.team.teamid][problem.probid] %}
236248
{% if matrixItem.isCorrect %}
237249
{% set scoreCssClass = 'score_correct' %}
238-
{% if not scoreboard.getRuntimeAsScoreTiebreaker() and scoreboard.solvedFirst(score.team, problem) %}
239-
{% set scoreCssClass = scoreCssClass ~ ' score_first' %}
240-
{% endif %}
241-
{% if scoreboard.getRuntimeAsScoreTiebreaker() and scoreboard.isFastestSubmission(score.team, problem) %}
242-
{% set scoreCssClass = scoreCssClass ~ ' score_first' %}
250+
{% if enable_ranking %}
251+
{% if not scoreboard.getRuntimeAsScoreTiebreaker() and scoreboard.solvedFirst(score.team, problem) %}
252+
{% set scoreCssClass = scoreCssClass ~ ' score_first' %}
253+
{% endif %}
254+
{% if scoreboard.getRuntimeAsScoreTiebreaker() and scoreboard.isFastestSubmission(score.team, problem) %}
255+
{% set scoreCssClass = scoreCssClass ~ ' score_first' %}
256+
{% endif %}
243257
{% endif %}
244258
{% elseif showPending and matrixItem.numSubmissionsPending > 0 %}
245259
{% set scoreCssClass = 'score_pending' %}

webapp/templates/team/menu.html.twig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
href="{{ path('team_print') }}"><i class="fas fa-file-alt"></i> Print</a>
3737
</li>
3838
{% endif %}
39-
<li class="nav-item">
40-
<a class="nav-link{% if current_route in ['team_scoreboard', 'team_team'] %} active{% endif %}"
41-
href="{{ path('team_scoreboard') }}"><i class="fas fa-list-ol"></i> Scoreboard</a>
42-
</li>
39+
{% if enable_ranking %}
40+
<li class="nav-item">
41+
<a class="nav-link{% if current_route in ['team_scoreboard', 'team_team'] %} active{% endif %}"
42+
href="{{ path('team_scoreboard') }}"><i class="fas fa-list-ol"></i> Scoreboard</a>
43+
</li>
44+
{% endif %}
4345
{% if doc_links is not empty %}
4446
<li class="nav-item">
4547
<a class="nav-link{% if current_route in ['team_docs'] %} active{% endif %}"

0 commit comments

Comments
 (0)