Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions app/V1Module/presenters/AssignmentSolutionReviewsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,14 @@
namespace App\V1Module\Presenters;

use App\Helpers\MetaFormats\Attributes\Post;
use App\Helpers\MetaFormats\Attributes\Query;
use App\Helpers\MetaFormats\Attributes\Path;
use App\Helpers\MetaFormats\Type;
use App\Helpers\MetaFormats\Validators\VArray;
use App\Helpers\MetaFormats\Validators\VBool;
use App\Helpers\MetaFormats\Validators\VDouble;
use App\Helpers\MetaFormats\Validators\VEmail;
use App\Helpers\MetaFormats\Validators\VInt;
use App\Helpers\MetaFormats\Validators\VMixed;
use App\Helpers\MetaFormats\Validators\VString;
use App\Helpers\MetaFormats\Validators\VTimestamp;
use App\Helpers\MetaFormats\Validators\VUuid;
use App\Exceptions\BadRequestException;
use App\Exceptions\InternalServerException;
use App\Exceptions\InvalidArgumentException;
use App\Exceptions\InvalidStateException;
use App\Exceptions\NotFoundException;
use App\Exceptions\NotReadyException;
use App\Exceptions\ForbiddenRequestException;
use App\Helpers\Notifications\ReviewsEmailsSender;
use App\Helpers\Validators;
use App\Model\Entity\AssignmentSolution;
use App\Model\Entity\ReviewComment;
use App\Model\Repository\AssignmentSolutions;
Expand Down
10 changes: 5 additions & 5 deletions app/V1Module/presenters/AssignmentSolutionsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use App\Helpers\MetaFormats\Validators\VUuid;
use App\Exceptions\BadRequestException;
use App\Exceptions\InternalServerException;
use App\Exceptions\InvalidArgumentException;
use App\Exceptions\InvalidApiArgumentException;
use App\Exceptions\InvalidStateException;
use App\Exceptions\NotFoundException;
use App\Exceptions\NotReadyException;
Expand Down Expand Up @@ -341,7 +341,7 @@ public function checkSetBonusPoints(string $id)
* Returns array of solution entities that has been changed by this.
* @POST
* @throws NotFoundException
* @throws InvalidArgumentException
* @throws InvalidApiArgumentException
* @throws InvalidStateException
*/
#[Post("bonusPoints", new VInt(), "New amount of bonus points, can be negative number")]
Expand Down Expand Up @@ -381,8 +381,8 @@ public function actionSetBonusPoints(string $id)
if (empty($overriddenPoints)) {
$solution->setOverriddenPoints(null);
} else {
throw new InvalidArgumentException(
"overridenPoints",
throw new InvalidApiArgumentException(
'overridenPoints',
"The value '$overriddenPoints' is not null|numericint"
);
}
Expand Down Expand Up @@ -524,7 +524,7 @@ public function actionSetFlag(string $id, string $flag)
throw new NotFoundException("Group for assignment '$id' was not found");
}

$resSolutions = [ $id => $this->assignmentSolutionViewFactory->getSolutionData($solution) ];
$resSolutions = [$id => $this->assignmentSolutionViewFactory->getSolutionData($solution)];
if ($resetedSolution) {
$resSolutions[$resetedSolution->getId()] =
$this->assignmentSolutionViewFactory->getSolutionData($resetedSolution);
Expand Down
19 changes: 8 additions & 11 deletions app/V1Module/presenters/AssignmentsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
namespace App\V1Module\Presenters;

use App\Helpers\MetaFormats\Attributes\Post;
use App\Helpers\MetaFormats\Attributes\Query;
use App\Helpers\MetaFormats\Attributes\Path;
use App\Helpers\MetaFormats\Type;
use App\Helpers\MetaFormats\Validators\VArray;
use App\Helpers\MetaFormats\Validators\VBool;
use App\Helpers\MetaFormats\Validators\VDouble;
use App\Helpers\MetaFormats\Validators\VEmail;
use App\Helpers\MetaFormats\Validators\VInt;
use App\Helpers\MetaFormats\Validators\VMixed;
use App\Helpers\MetaFormats\Validators\VString;
use App\Helpers\MetaFormats\Validators\VTimestamp;
use App\Helpers\MetaFormats\Validators\VUuid;
use App\Exceptions\BadRequestException;
use App\Exceptions\ForbiddenRequestException;
use App\Exceptions\InvalidArgumentException;
use App\Exceptions\InvalidApiArgumentException;
use App\Exceptions\InvalidStateException;
use App\Exceptions\NotFoundException;
use App\Exceptions\FrontendErrorMappings;
Expand Down Expand Up @@ -209,7 +205,7 @@ public function checkUpdateDetail(string $id)
* Update details of an assignment
* @POST
* @throws BadRequestException
* @throws InvalidArgumentException
* @throws InvalidApiArgumentException
* @throws NotFoundException
*/
#[Post("version", new VInt(), "Version of the edited assignment")]
Expand Down Expand Up @@ -312,7 +308,7 @@ public function actionUpdateDetail(string $id)

// localized texts cannot be empty
if (count($req->getPost("localizedTexts")) == 0) {
throw new InvalidArgumentException("No entry for localized texts given.");
throw new InvalidApiArgumentException('localizedTexts', "No entry for localized texts given.");
}

if ($this->isRequestJson()) {
Expand All @@ -334,7 +330,7 @@ public function actionUpdateDetail(string $id)
if ($req->getPost($name) !== null) {
$value = (int)$req->getPost($name);
if ($value < $min || $value > $max) {
throw new InvalidArgumentException("Attribute '$name' value $value is out of range [$min,$max].");
throw new InvalidApiArgumentException($name, "Value $value is out of range [$min,$max].");
}
}
}
Expand Down Expand Up @@ -381,7 +377,8 @@ public function actionUpdateDetail(string $id)
$maxPointsDeadlineInterpolation = false;
}
if ($allowSecondDeadline && $firstDeadlineTimestamp >= $secondDeadlineTimestamp) {
throw new InvalidArgumentException(
throw new InvalidApiArgumentException(
'secondDeadline',
"When the second deadline is allowed, it must be after the first deadline."
);
}
Expand Down Expand Up @@ -435,15 +432,15 @@ public function actionUpdateDetail(string $id)
$lang = $localization["locale"];

if (array_key_exists($lang, $localizedTexts)) {
throw new InvalidArgumentException("Duplicate entry for language $lang in localizedTexts");
throw new InvalidApiArgumentException('localizedTexts', "Duplicate entry for language '$lang'");
}

// create all new localized texts
$assignmentExercise = $assignment->getExercise();
$localizedExercise = $assignmentExercise ? $assignmentExercise->getLocalizedTextByLocale($lang) : null;
$externalAssignmentLink = trim(Arrays::get($localization, "link", ""));
if ($externalAssignmentLink !== "" && !Validators::isUrl($externalAssignmentLink)) {
throw new InvalidArgumentException("External assignment link is not a valid URL");
throw new InvalidApiArgumentException('link', "External assignment link is not a valid URL");
}

$localizedTexts[$lang] = new LocalizedExercise(
Expand Down
21 changes: 6 additions & 15 deletions app/V1Module/presenters/ExerciseFilesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@
namespace App\V1Module\Presenters;

use App\Helpers\MetaFormats\Attributes\Post;
use App\Helpers\MetaFormats\Attributes\Query;
use App\Helpers\MetaFormats\Attributes\Path;
use App\Helpers\MetaFormats\Type;
use App\Helpers\MetaFormats\Validators\VArray;
use App\Helpers\MetaFormats\Validators\VBool;
use App\Helpers\MetaFormats\Validators\VDouble;
use App\Helpers\MetaFormats\Validators\VEmail;
use App\Helpers\MetaFormats\Validators\VInt;
use App\Helpers\MetaFormats\Validators\VMixed;
use App\Helpers\MetaFormats\Validators\VString;
use App\Helpers\MetaFormats\Validators\VTimestamp;
use App\Helpers\MetaFormats\Validators\VUuid;
use App\Exceptions\ForbiddenRequestException;
use App\Exceptions\InvalidArgumentException;
use App\Exceptions\InvalidApiArgumentException;
use App\Exceptions\NotFoundException;
use App\Exceptions\SubmissionFailedException;
use App\Helpers\ExerciseConfig\ExerciseConfigChecker;
Expand Down Expand Up @@ -99,7 +90,7 @@ public function checkUploadSupplementaryFiles(string $id)
* Associate supplementary files with an exercise and upload them to remote file server
* @POST
* @throws ForbiddenRequestException
* @throws InvalidArgumentException
* @throws InvalidApiArgumentException
* @throws SubmissionFailedException
*/
#[Post("files", new VMixed(), "Identifiers of supplementary files", nullable: true)]
Expand Down Expand Up @@ -140,16 +131,16 @@ public function actionUploadSupplementaryFiles(string $id)

$fileCountLimit = $this->restrictionsConfig->getSupplementaryFileCountLimit();
if ($totalFileCount > $fileCountLimit) {
throw new InvalidArgumentException(
"files",
throw new InvalidApiArgumentException(
'files',
"The number of files would exceed the configured limit ($fileCountLimit)"
);
}

$sizeLimit = $this->restrictionsConfig->getSupplementaryFileSizeLimit();
if ($totalFileSize > $sizeLimit) {
throw new InvalidArgumentException(
"files",
throw new InvalidApiArgumentException(
'files',
"The total size of files would exceed the configured limit ($sizeLimit)"
);
}
Expand Down
39 changes: 17 additions & 22 deletions app/V1Module/presenters/ExercisesConfigPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@
namespace App\V1Module\Presenters;

use App\Helpers\MetaFormats\Attributes\Post;
use App\Helpers\MetaFormats\Attributes\Query;
use App\Helpers\MetaFormats\Attributes\Path;
use App\Helpers\MetaFormats\Type;
use App\Helpers\MetaFormats\Validators\VArray;
use App\Helpers\MetaFormats\Validators\VBool;
use App\Helpers\MetaFormats\Validators\VDouble;
use App\Helpers\MetaFormats\Validators\VEmail;
use App\Helpers\MetaFormats\Validators\VInt;
use App\Helpers\MetaFormats\Validators\VMixed;
use App\Helpers\MetaFormats\Validators\VString;
use App\Helpers\MetaFormats\Validators\VTimestamp;
use App\Helpers\MetaFormats\Validators\VUuid;
use App\Exceptions\ApiException;
use App\Exceptions\ExerciseCompilationException;
use App\Exceptions\ExerciseConfigException;
use App\Exceptions\ForbiddenRequestException;
use App\Exceptions\InvalidArgumentException;
use App\Exceptions\InvalidApiArgumentException;
use App\Exceptions\NotFoundException;
use App\Exceptions\ParseException;
use App\Helpers\ExerciseConfig\Helper;
Expand Down Expand Up @@ -197,7 +189,7 @@ public function checkUpdateEnvironmentConfigs(string $id)
* Configurations can be added or deleted here, based on what is provided in arguments.
* @POST
* @throws ForbiddenRequestException
* @throws InvalidArgumentException
* @throws InvalidApiArgumentException
* @throws ExerciseConfigException
* @throws NotFoundException
*/
Expand All @@ -214,7 +206,7 @@ public function actionUpdateEnvironmentConfigs(string $id)

// configurations cannot be empty
if (count($environmentConfigs) == 0) {
throw new InvalidArgumentException("No entry for runtime configurations given.");
throw new InvalidApiArgumentException('environmentConfigs', "No entry for runtime configurations given.");
}

$runtimeEnvironments = new ArrayCollection();
Expand All @@ -228,7 +220,10 @@ public function actionUpdateEnvironmentConfigs(string $id)

// check for duplicate environments
if (array_key_exists($environmentId, $configs)) {
throw new InvalidArgumentException("Duplicate entry for configuration '$environmentId''");
throw new InvalidApiArgumentException(
'environmentConfigs',
"Duplicate entry for configuration '$environmentId''"
);
}

// load variables table for this runtime configuration
Expand Down Expand Up @@ -593,8 +588,8 @@ public function actionGetLimits(string $id)

// fill existing limits into result structure
foreach ($exercise->getExerciseLimits() as $limit) {
$limits[$limit->getHardwareGroup()->getId()][$limit->getRuntimeEnvironment()->getId(
)] = $limit->getParsedLimits();
$limits[$limit->getHardwareGroup()->getId()][$limit->getRuntimeEnvironment()->getId()]
= $limit->getParsedLimits();
}
$this->sendSuccessResponse($limits);
}
Expand Down Expand Up @@ -766,7 +761,7 @@ public function checkSetTests(string $id)
* Set tests for exercise based on given identification.
* @POST
* @throws ForbiddenRequestException
* @throws InvalidArgumentException
* @throws InvalidApiArgumentException
* @throws ExerciseConfigException
*/
#[Post("tests", new VArray(), "An array of tests which will belong to exercise")]
Expand All @@ -792,18 +787,18 @@ public function actionSetTests(string $id)
foreach ($tests as $test) {
// Perform checks on the test name...
if (!array_key_exists("name", $test)) {
throw new InvalidArgumentException("tests", "name item not found in particular test");
throw new InvalidApiArgumentException('tests', "name item not found in particular test");
}

$name = trim($test["name"]);
if (!preg_match('/^[-a-zA-Z0-9_()\[\].! ]+$/', $name)) {
throw new InvalidArgumentException("tests", "test name contains illicit characters");
throw new InvalidApiArgumentException('tests', "test name contains illicit characters");
}
if (strlen($name) > 64) {
throw new InvalidArgumentException("tests", "test name too long (exceeds 64 characters)");
throw new InvalidApiArgumentException('tests', "test name too long (exceeds 64 characters)");
}
if (array_key_exists($name, $newTests)) {
throw new InvalidArgumentException("tests", "two tests with the same name '$name' were specified");
throw new InvalidApiArgumentException('tests', "two tests with the same name '$name' were specified");
}

$id = Arrays::get($test, "id", null);
Expand All @@ -816,7 +811,7 @@ public function actionSetTests(string $id)
$testsModified = true;

if ($exercise->getExerciseTestByName($name)) {
throw new InvalidArgumentException("tests", "given test name '$name' is already taken");
throw new InvalidApiArgumentException('tests', "given test name '$name' is already taken");
}

$testEntity = new ExerciseTest($name, $description, $this->getCurrentUser());
Expand All @@ -841,8 +836,8 @@ public function actionSetTests(string $id)

$testCountLimit = $this->exerciseRestrictionsConfig->getTestCountLimit();
if (count($newTests) > $testCountLimit) {
throw new InvalidArgumentException(
"tests",
throw new InvalidApiArgumentException(
'tests',
"The number of tests exceeds the configured limit ($testCountLimit)"
);
}
Expand Down
Loading