Skip to content

Commit cf2478c

Browse files
committed
Return 'other' if no standard account type is found in API
Also rename variables and comment to clarify that the listed types are not the only ones allowed, just the ones suggested/ mentioned in the CLICS specification (as examples). Closes: #3163
1 parent e453219 commit cf2478c

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

webapp/src/Entity/User.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,24 +434,24 @@ public function getRoleList(): array
434434
#[Serializer\VirtualProperty]
435435
#[Serializer\SerializedName('type')]
436436
#[Serializer\Type('string')]
437-
public function getType(): ?string
437+
public function getType(): string
438438
{
439-
// Types allowed by the CCS Specs Contest API in order of most permissions to least.
439+
// Types suggested by the CCS Specs Contest API in order of most permissions to least.
440440
// Either key=>value where key is the DOMjudge role and value is the API account type or
441441
// only value, where both the DOMjudge role and API type are the same.
442-
$allowedTypes = ['admin', 'api_writer' => 'admin', 'api_reader' => 'admin',
443-
'jury' => 'judge', 'api_source_reader' => 'judge',
444-
'team'];
445-
foreach ($allowedTypes as $role => $allowedType) {
442+
$mappedTypes = ['admin', 'api_writer' => 'admin', 'api_reader' => 'admin',
443+
'jury' => 'judge', 'api_source_reader' => 'judge',
444+
'team'];
445+
foreach ($mappedTypes as $role => $mappedType) {
446446
if (is_numeric($role)) {
447-
$role = $allowedType;
447+
$role = $mappedType;
448448
}
449449
if (in_array($role, $this->getRoleList())) {
450-
return $allowedType;
450+
return $mappedType;
451451
}
452452
}
453453

454-
return null;
454+
return 'other';
455455
}
456456

457457
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ abstract class AccountBaseTestCase extends BaseTestCase
2626
[['type' => 'api_writer'], ['type' => 'admin', 'roles' => ['api_writer']]],
2727
[['type' => 'api_reader'], ['type' => 'admin', 'roles' => ['api_reader']]],
2828
[['type' => 'api_source_reader'], ['type' => 'judge', 'roles' => ['api_source_reader']]],
29-
[['type' => 'balloon'], ['roles' => ['balloon'], 'type' => null]],
30-
[['type' => 'clarification_rw'], ['roles' => ['clarification_rw'], 'type' => null]],
29+
[['type' => 'balloon'], ['roles' => ['balloon'], 'type' => 'other']],
30+
[['type' => 'clarification_rw'], ['roles' => ['clarification_rw'], 'type' => 'other']],
3131
[['type' => 'cds'], ['roles' => ['api_source_reader', 'api_reader', 'api_writer'], 'type' => 'admin']],
3232
[['username' => 'cds', 'type' => 'admin'], ['roles' => ['api_source_reader', 'api_reader', 'api_writer'], 'type' => 'admin']],
3333
[['username' => 'cds', 'type' => 'jury'], ['roles' => ['api_source_reader', 'api_reader', 'api_writer'], 'type' => 'admin']],
3434
];
3535

3636
protected static array $accountAddCombinationsWithoutFile = [
3737
[['username' => 'cds', 'roles' => ['admin']], ['roles' => ['api_source_reader', 'api_reader', 'api_writer'], 'type' => 'admin']],
38-
[['username' => 'another_judgehost', 'roles' => ['judgehost']], ['type' => null]],
38+
[['username' => 'another_judgehost', 'roles' => ['judgehost']], ['type' => 'other']],
3939
];
4040

4141
protected static array $optionalAddKeys = ['id', 'name', 'password'];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AccountControllerTest extends AccountBaseTestCase
2222
"id" => "judgehost",
2323
"username" => "judgehost",
2424
"team_id" => null,
25-
"type" => null,
25+
"type" => "other",
2626
"ip" => null,
2727
],
2828
'demo' => [

0 commit comments

Comments
 (0)