Skip to content

Commit

Permalink
Final refactoring and polishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Krulis committed May 11, 2020
1 parent d20e29c commit c553f8d
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 110 deletions.
56 changes: 28 additions & 28 deletions app/V1Module/presenters/AssignmentSolutionsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,20 @@ public function actionDeleteSolution(string $id)
$this->sendSuccessResponse("OK");
}

public function checkEvaluations(string $id)
public function checkSubmissions(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
if (!$this->assignmentSolutionAcl->canViewDetail($solution)) {
throw new ForbiddenRequestException("You cannot access this solution evaluations");
throw new ForbiddenRequestException("You cannot access submissions of this solution");
}
}

/**
* Get information about the evaluations of a solution
* Get list of all submissions of a solution
* @GET
* @param string $id Identifier of the solution
*/
public function actionEvaluations(string $id)
public function actionSubmissions(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);

Expand All @@ -205,9 +205,9 @@ function (AssignmentSolutionSubmission $submission) {
$this->sendSuccessResponse($submissions);
}

public function checkEvaluation(string $evaluationId)
public function checkSubmission(string $submissionId)
{
$submission = $this->assignmentSolutionSubmissions->findOrThrow($evaluationId);
$submission = $this->assignmentSolutionSubmissions->findOrThrow($submissionId);
$solution = $submission->getAssignmentSolution();
if (!$this->assignmentSolutionAcl->canViewEvaluation($solution)) {
throw new ForbiddenRequestException("You cannot access this evaluation");
Expand All @@ -217,13 +217,13 @@ public function checkEvaluation(string $evaluationId)
/**
* Get information about the evaluation of a submission
* @GET
* @param string $evaluationId Identifier of the submission
* @param string $submissionId Identifier of the submission
* @throws NotFoundException
* @throws InternalServerException
*/
public function actionEvaluation(string $evaluationId)
public function actionSubmission(string $submissionId)
{
$submission = $this->assignmentSolutionSubmissions->findOrThrow($evaluationId);
$submission = $this->assignmentSolutionSubmissions->findOrThrow($submissionId);

// try to load evaluation if not present
$this->evaluationLoadingHelper->loadEvaluation($submission);
Expand All @@ -232,9 +232,9 @@ public function actionEvaluation(string $evaluationId)
$this->sendSuccessResponse($submissionData);
}

public function checkDeleteEvaluation(string $evaluationId)
public function checkDeleteSubmission(string $submissionId)
{
$submission = $this->assignmentSolutionSubmissions->findOrThrow($evaluationId);
$submission = $this->assignmentSolutionSubmissions->findOrThrow($submissionId);
$solution = $submission->getAssignmentSolution();
if (!$this->assignmentSolutionAcl->canDeleteEvaluation($solution)) {
throw new ForbiddenRequestException("You cannot delete this evaluation");
Expand All @@ -245,13 +245,13 @@ public function checkDeleteEvaluation(string $evaluationId)
}

/**
* Remove evaluation (submission) permanently.
* Remove the submission permanently
* @DELETE
* @param string $evaluationId Identifier of the submission
* @param string $submissionId Identifier of the submission
*/
public function actionDeleteEvaluation(string $evaluationId)
public function actionDeleteSubmission(string $submissionId)
{
$submission = $this->assignmentSolutionSubmissions->findOrThrow($evaluationId);
$submission = $this->assignmentSolutionSubmissions->findOrThrow($submissionId);
$solution = $submission->getAssignmentSolution();
$solution->setLastSubmission($this->assignmentSolutionSubmissions->getLastSubmission($solution, $submission));
$this->assignmentSolutionSubmissions->remove($submission);
Expand Down Expand Up @@ -506,9 +506,9 @@ public function actionDownloadSolutionArchive(string $id)
$this->sendResponse(new ZipFilesResponse($files, "solution-{$id}.zip"));
}

public function checkDownloadResultArchive(string $evaluationId)
public function checkDownloadResultArchive(string $submissionId)
{
$submission = $this->assignmentSolutionSubmissions->findOrThrow($evaluationId);
$submission = $this->assignmentSolutionSubmissions->findOrThrow($submissionId);
if (!$this->assignmentSolutionAcl->canDownloadResultArchive($submission->getAssignmentSolution())) {
throw new ForbiddenRequestException("You cannot access the result archive for this submission");
}
Expand All @@ -517,14 +517,14 @@ public function checkDownloadResultArchive(string $evaluationId)
/**
* Download result archive from backend for particular submission.
* @GET
* @param string $evaluationId
* @param string $submissionId
* @throws NotFoundException
* @throws InternalServerException
* @throws \Nette\Application\AbortException
*/
public function actionDownloadResultArchive(string $evaluationId)
public function actionDownloadResultArchive(string $submissionId)
{
$submission = $this->assignmentSolutionSubmissions->findOrThrow($evaluationId);
$submission = $this->assignmentSolutionSubmissions->findOrThrow($submissionId);
$this->evaluationLoadingHelper->loadEvaluation($submission);

if (!$submission->hasEvaluation()) {
Expand All @@ -533,31 +533,31 @@ public function actionDownloadResultArchive(string $evaluationId)

$stream = $this->fileServerProxy->getFileserverFileStream($submission->getResultsUrl());
if ($stream === null) {
throw new NotFoundException("Archive for submission '$evaluationId' not found on remote fileserver");
throw new NotFoundException("Archive for submission '$submissionId' not found on remote fileserver");
}

$this->sendResponse(new GuzzleResponse($stream, "results-{$evaluationId}.zip", "application/zip"));
$this->sendResponse(new GuzzleResponse($stream, "results-{$submissionId}.zip", "application/zip"));
}

public function checkEvaluationScoreConfig(string $evaluationId)
public function checkEvaluationScoreConfig(string $submissionId)
{
$submission = $this->assignmentSolutionSubmissions->findOrThrow($evaluationId);
$submission = $this->assignmentSolutionSubmissions->findOrThrow($submissionId);
$solution = $submission->getAssignmentSolution();
if (!$this->assignmentSolutionAcl->canViewEvaluation($solution)) {
throw new ForbiddenRequestException("You cannot access this evaluation");
}
}

/**
* Get score configuration associated with given evaluation
* Get score configuration associated with given submission evaluation
* @GET
* @param string $evaluationId Identifier of the submission
* @param string $submissionId Identifier of the submission
* @throws NotFoundException
* @throws InternalServerException
*/
public function actionEvaluationScoreConfig(string $evaluationId)
public function actionEvaluationScoreConfig(string $submissionId)
{
$submission = $this->assignmentSolutionSubmissions->findOrThrow($evaluationId);
$submission = $this->assignmentSolutionSubmissions->findOrThrow($submissionId);
$this->evaluationLoadingHelper->loadEvaluation($submission);

$evaluation = $submission->getEvaluation();
Expand Down
4 changes: 1 addition & 3 deletions app/V1Module/presenters/ExercisesConfigPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,7 @@ public function actionSetScoreConfig(string $id)

// validate score configuration
$calculator = $this->calculators->getCalculator($calculatorName);
$normalizedConfig = $config !== null
? $calculator->validateAndNormalizeScore($config) // throws if validation fails
: null;
$normalizedConfig = $calculator->validateAndNormalizeScore($config); // throws if validation fails

if ($calculatorName !== $oldConfig->getCalculator() || $config !== $oldConfig->getConfig()) {
$newConfig = new ExerciseScoreConfig($calculatorName, $config, $oldConfig);
Expand Down
60 changes: 30 additions & 30 deletions app/V1Module/presenters/ReferenceExerciseSolutionsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,22 +219,22 @@ public function actionDeleteReferenceSolution(string $solutionId)
$this->sendSuccessResponse("OK");
}

public function checkEvaluations(string $solutionId)
public function checkSubmissions(string $solutionId)
{
$solution = $this->referenceSolutions->findOrThrow($solutionId);
$exercise = $solution->getExercise();
if (!$this->exerciseAcl->canViewDetail($exercise)) {
throw new ForbiddenRequestException("You cannot access this exercise evaluations");
throw new ForbiddenRequestException("You cannot access this reference solution submissions");
}
}

/**
* Get reference solution evaluations for an exercise solution.
* Get a list of submissions for given reference solution.
* @GET
* @param string $solutionId identifier of the reference exercise solution
* @throws InternalServerException
*/
public function actionEvaluations(string $solutionId)
public function actionSubmissions(string $solutionId)
{
$solution = $this->referenceSolutions->findOrThrow($solutionId);

Expand All @@ -246,49 +246,49 @@ public function actionEvaluations(string $solutionId)
$this->sendSuccessResponse($solution->getSubmissions()->getValues());
}

public function checkEvaluation(string $evaluationId)
public function checkSubmission(string $submissionId)
{
$submission = $this->referenceSubmissions->findOrThrow($evaluationId);
$submission = $this->referenceSubmissions->findOrThrow($submissionId);
$exercise = $submission->getReferenceSolution()->getExercise();
if (!$this->exerciseAcl->canViewDetail($exercise)) {
throw new ForbiddenRequestException("You cannot access this exercise evaluations");
}
}

/**
* Get reference solution evaluation for an exercise solution.
* Get reference solution evaluation (i.e., submission) for an exercise solution.
* @GET
* @param string $evaluationId identifier of the reference exercise evaluation
* @param string $submissionId identifier of the reference exercise submission
* @throws NotFoundException
* @throws InternalServerException
*/
public function actionEvaluation(string $evaluationId)
public function actionSubmission(string $submissionId)
{
$submission = $this->referenceSubmissions->findOrThrow($evaluationId);
$submission = $this->referenceSubmissions->findOrThrow($submissionId);
$this->evaluationLoadingHelper->loadEvaluation($submission);
$this->sendSuccessResponse($submission);
}

public function checkDeleteEvaluation(string $evaluationId)
public function checkDeleteSubmission(string $submissionId)
{
$submission = $this->referenceSubmissions->findOrThrow($evaluationId);
$submission = $this->referenceSubmissions->findOrThrow($submissionId);
$solution = $submission->getReferenceSolution();
if (!$this->referenceSolutionAcl->canDeleteEvaluation($solution)) {
throw new ForbiddenRequestException("You cannot delete this evaluation");
throw new ForbiddenRequestException("You cannot delete this submission");
}
if ($solution->getSubmissions()->count() < 2) {
throw new BadRequestException("You cannot delete last evaluation of a solution");
throw new BadRequestException("You cannot delete last submission of a solution");
}
}

/**
* Remove reference solution evaluation (submission) permanently.
* @DELETE
* @param string $evaluationId Identifier of the reference solution submission
* @param string $submissionId Identifier of the reference solution submission
*/
public function actionDeleteEvaluation(string $evaluationId)
public function actionDeleteSubmission(string $submissionId)
{
$submission = $this->referenceSubmissions->findOrThrow($evaluationId);
$submission = $this->referenceSubmissions->findOrThrow($submissionId);
$this->referenceSubmissions->remove($submission);
$this->referenceSubmissions->flush();
$this->sendSuccessResponse("OK");
Expand Down Expand Up @@ -626,10 +626,10 @@ public function actionDownloadSolutionArchive(string $solutionId)
$this->sendResponse(new ZipFilesResponse($files, "reference-solution-{$solutionId}.zip"));
}

public function checkDownloadResultArchive(string $evaluationId)
public function checkDownloadResultArchive(string $submissionId)
{
/** @var ReferenceSolutionSubmission $submission */
$submission = $this->referenceSubmissions->findOrThrow($evaluationId);
$submission = $this->referenceSubmissions->findOrThrow($submissionId);
$refSolution = $submission->getReferenceSolution();

if (!$this->referenceSolutionAcl->canEvaluate($refSolution)) {
Expand All @@ -640,16 +640,16 @@ public function checkDownloadResultArchive(string $evaluationId)
/**
* Download result archive from backend for a reference solution evaluation
* @GET
* @param string $evaluationId
* @param string $submissionId
* @throws ForbiddenRequestException
* @throws NotFoundException
* @throws NotReadyException
* @throws InternalServerException
* @throws \Nette\Application\AbortException
*/
public function actionDownloadResultArchive(string $evaluationId)
public function actionDownloadResultArchive(string $submissionId)
{
$submission = $this->referenceSubmissions->findOrThrow($evaluationId);
$submission = $this->referenceSubmissions->findOrThrow($submissionId);
$this->evaluationLoadingHelper->loadEvaluation($submission);

if (!$submission->hasEvaluation()) {
Expand All @@ -659,32 +659,32 @@ public function actionDownloadResultArchive(string $evaluationId)
$stream = $this->fileServerProxy->getFileserverFileStream($submission->getResultsUrl());
if ($stream === null) {
throw new NotFoundException(
"Archive for solution evaluation '$evaluationId' not found on remote fileserver"
"Evaluation archive for solution submission '$submissionId' not found on remote fileserver"
);
}

$this->sendResponse(new GuzzleResponse($stream, "results-{$evaluationId}.zip", "application/zip"));
$this->sendResponse(new GuzzleResponse($stream, "results-{$submissionId}.zip", "application/zip"));
}

public function checkEvaluationScoreConfig(string $evaluationId)
public function checkEvaluationScoreConfig(string $submissionId)
{
$submission = $this->referenceSubmissions->findOrThrow($evaluationId);
$submission = $this->referenceSubmissions->findOrThrow($submissionId);
$exercise = $submission->getReferenceSolution()->getExercise();
if (!$this->exerciseAcl->canViewDetail($exercise)) {
throw new ForbiddenRequestException("You cannot access this exercise evaluations");
}
}

/**
* Get score configuration associated with given evaluation
* Get score configuration associated with given submission evaluation
* @GET
* @param string $evaluationId identifier of the reference exercise evaluation
* @param string $submissionId identifier of the reference exercise submission
* @throws NotFoundException
* @throws InternalServerException
*/
public function actionEvaluationScoreConfig(string $evaluationId)
public function actionEvaluationScoreConfig(string $submissionId)
{
$submission = $this->referenceSubmissions->findOrThrow($evaluationId);
$submission = $this->referenceSubmissions->findOrThrow($submissionId);
$this->evaluationLoadingHelper->loadEvaluation($submission);

$evaluation = $submission->getEvaluation();
Expand Down
Loading

0 comments on commit c553f8d

Please sign in to comment.