Skip to content

Commit 11d2823

Browse files
committed
Implement Jaap his feedback
1 parent 265be80 commit 11d2823

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

webapp/config/packages/security.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ security:
44
role_hierarchy:
55
ROLE_JURY: [ROLE_CLARIFICATION_RW, ROLE_API, ROLE_API_READER, ROLE_API_SOURCE_READER]
66
ROLE_ADMIN: [ROLE_JURY, ROLE_JUDGEHOST, ROLE_API_WRITER,
7-
ROLE_API_PROBLEM_CHANGE, ROLE_API_CONTEST_CHANGE]
7+
ROLE_API_PROBLEM_EDITOR, ROLE_API_CONTEST_EDITOR]
88
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
99

1010
# https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords

webapp/migrations/Version20240629154640.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99

1010
final class Version20240629154640 extends AbstractMigration
1111
{
12-
private const NEW_ROLES = ['api_problem_change' => 'API Problem Changer',
13-
'api_contest_change' => 'API Contest Changer'];
12+
private const NEW_ROLES = ['api_problem_editor' => 'API Problem Editor',
13+
'api_contest_editor' => 'API Contest Editor'];
1414

1515
public function getDescription(): string
1616
{
17-
return 'Add new roles to the database.';
17+
return "Add new roles to the database.
18+
Problem editor can add/delete/edit anything related to problems; files, testcases.
19+
Contest editor can add/delete/edit the time & connected problems, but not the files
20+
or testcases of those problems.
21+
They are a subset of the ADMIN role in the API but not a proper superset of the API_WRITER
22+
as that also has access to push teams etc.";
1823
}
1924

2025
public function up(Schema $schema): void

webapp/src/Controller/API/ContestController.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct(
7474
* Add a new contest.
7575
* @throws BadRequestHttpException
7676
*/
77-
#[IsGranted('ROLE_API_CONTEST_CHANGE')]
77+
#[IsGranted('ROLE_API_CONTEST_EDITOR')]
7878
#[Rest\Post('')]
7979
#[OA\RequestBody(
8080
required: true,
@@ -200,7 +200,7 @@ public function bannerAction(Request $request, string $cid): Response
200200
/**
201201
* Delete the banner for the given contest.
202202
*/
203-
#[IsGranted('ROLE_API_CONTEST_CHANGE')]
203+
#[IsGranted('ROLE_API_CONTEST_EDITOR')]
204204
#[Rest\Delete('/{cid}/banner', name: 'delete_contest_banner')]
205205
#[OA\Response(response: 204, description: 'Deleting banner succeeded')]
206206
#[OA\Parameter(ref: '#/components/parameters/cid')]
@@ -220,7 +220,7 @@ public function deleteBannerAction(Request $request, string $cid): Response
220220
/**
221221
* Set the banner for the given contest.
222222
*/
223-
#[IsGranted('ROLE_API_CONTEST_CHANGE')]
223+
#[IsGranted('ROLE_API_CONTEST_EDITOR')]
224224
#[Rest\Post("/{cid}/banner", name: 'post_contest_banner')]
225225
#[Rest\Put("/{cid}/banner", name: 'put_contest_banner')]
226226
#[OA\RequestBody(
@@ -268,7 +268,7 @@ public function setBannerAction(Request $request, string $cid, ValidatorInterfac
268268
/**
269269
* Delete the problemset document for the given contest.
270270
*/
271-
#[IsGranted('ROLE_API_CONTEST_CHANGE')]
271+
#[IsGranted('ROLE_API_CONTEST_EDITOR')]
272272
#[Rest\Delete('/{cid}/problemset', name: 'delete_contest_problemset')]
273273
#[OA\Response(response: 204, description: 'Deleting problemset document succeeded')]
274274
#[OA\Parameter(ref: '#/components/parameters/cid')]
@@ -288,7 +288,7 @@ public function deleteProblemsetAction(Request $request, string $cid): Response
288288
/**
289289
* Set the problemset document for the given contest.
290290
*/
291-
#[IsGranted('ROLE_API_CONTEST_CHANGE')]
291+
#[IsGranted('ROLE_API_CONTEST_EDITOR')]
292292
#[Rest\Post("/{cid}/problemset", name: 'post_contest_problemset')]
293293
#[Rest\Put("/{cid}/problemset", name: 'put_contest_problemset')]
294294
#[OA\RequestBody(
@@ -384,7 +384,7 @@ public function problemsetAction(Request $request, string $cid): Response
384384
* Change the start time or unfreeze (thaw) time of the given contest.
385385
* @throws NonUniqueResultException
386386
*/
387-
#[IsGranted(new Expression("is_granted('ROLE_API_WRITER') or is_granted('ROLE_API_CONTEST_CHANGE')"))]
387+
#[IsGranted(new Expression("is_granted('ROLE_API_WRITER') or is_granted('ROLE_API_CONTEST_EDITOR')"))]
388388
#[Rest\Patch('/{cid}')]
389389
#[OA\RequestBody(
390390
required: true,

webapp/src/Controller/API/ProblemController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(
6161
* @throws BadRequestHttpException
6262
* @throws NonUniqueResultException
6363
*/
64-
#[IsGranted('ROLE_API_PROBLEM_CHANGE')]
64+
#[IsGranted('ROLE_API_PROBLEM_EDITOR')]
6565
#[Rest\Post('/add-data')]
6666
#[OA\RequestBody(
6767
required: true,
@@ -176,7 +176,7 @@ public function listAction(Request $request): Response
176176
* @return array{problem_id: string, messages: array<string, string[]>}
177177
* @throws NonUniqueResultException
178178
*/
179-
#[IsGranted('ROLE_API_PROBLEM_CHANGE')]
179+
#[IsGranted('ROLE_API_PROBLEM_EDITOR')]
180180
#[Rest\Post('')]
181181
#[OA\RequestBody(
182182
required: true,
@@ -237,7 +237,7 @@ public function addProblemAction(Request $request): array
237237
/**
238238
* Unlink a problem from this contest.
239239
*/
240-
#[IsGranted('ROLE_API_PROBLEM_CHANGE')]
240+
#[IsGranted('ROLE_API_PROBLEM_EDITOR')]
241241
#[Rest\Delete('/{id}')]
242242
#[OA\Response(response: 204, description: 'Problem unlinked from contest succeeded')]
243243
#[OA\Parameter(ref: '#/components/parameters/id')]
@@ -290,7 +290,7 @@ public function unlinkProblemAction(Request $request, string $id): Response
290290
/**
291291
* Link an existing problem to this contest.
292292
*/
293-
#[IsGranted('ROLE_API_PROBLEM_CHANGE')]
293+
#[IsGranted('ROLE_API_PROBLEM_EDITOR')]
294294
#[Rest\Put('/{id}')]
295295
#[OA\Response(
296296
response: 200,

webapp/src/DataFixtures/DefaultData/RoleFixture.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function load(ObjectManager $manager): void
2929
'api_writer' => 'API writer',
3030
'api_source_reader' => 'Source code reader',
3131
'clarification_rw' => 'Clarification handler',
32-
'api_problem_change' => 'API Problem Changer',
33-
'api_contest_change' => 'API Contest Changer'
32+
'api_problem_editor' => 'API Problem Editor',
33+
'api_contest_editor' => 'API Contest Editor'
3434
];
3535
foreach ($roles as $roleName => $description) {
3636
if (!($role = $manager->getRepository(Role::class)->findOneBy(['dj_role' => $roleName]))) {

webapp/tests/Unit/Controller/API/ContestControllerAdminTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class ContestControllerAdminTest extends ContestControllerTest
2222
{
2323
protected ?string $apiUser = 'admin';
24-
protected static string $testedRole = 'api_contest_change';
24+
protected static string $testedRole = 'api_contest_editor';
2525

2626
private function parseSortYaml(string $yamlString): array
2727
{
@@ -326,7 +326,7 @@ public function provideChangeTimes(): Generator
326326

327327
// Show that this works for both roles
328328
yield [['id' => 1, 'scoreboard_thaw_time' => '-14 seconds'], 200, 'Demo contest', [], true, true, ['admin']];
329-
yield [['id' => 1, 'scoreboard_thaw_time' => '-13 seconds'], 200, 'Demo contest', [], true, true, ['api_contest_change']];
329+
yield [['id' => 1, 'scoreboard_thaw_time' => '-13 seconds'], 200, 'Demo contest', [], true, true, ['api_contest_editor']];
330330
}
331331

332332
/**

webapp/tests/Unit/Controller/API/ProblemControllerAdminTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class ProblemControllerAdminTest extends ProblemControllerTest
1212
{
1313
protected ?string $apiUser = 'admin';
14-
protected static string $testedRole = 'api_problem_change';
14+
protected static string $testedRole = 'api_problem_editor';
1515

1616
protected function setUp(): void
1717
{

0 commit comments

Comments
 (0)