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
71 changes: 43 additions & 28 deletions app/V1Module/router/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class RouterFactory
{
use Nette\StaticClass;

private static $strictMode = false;

public static function setStrictMode(bool $strict = true): void
{
self::$strictMode = $strict;
}

/**
* Create router with all routes for V1 module.
* @return Router
Expand Down Expand Up @@ -177,26 +184,28 @@ private static function createExercisesRoutes(string $prefix): RouteList
// special download route for file link by its key
$router[] = new GetRoute("$prefix/<id>/file-download/<linkKey>", "UploadedFiles:downloadExerciseFileLinkByKey");

// deprecated routes for supplementary-files (replaced with `files`)
$router[] = new GetRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:getExerciseFiles");
$router[] = new PostRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:uploadExerciseFiles");
$router[] = new DeleteRoute(
"$prefix/<id>/supplementary-files/<fileId>",
"ExerciseFiles:deleteExerciseFile"
);
$router[] = new GetRoute(
"$prefix/<id>/supplementary-files/download-archive",
"ExerciseFiles:downloadExerciseFilesArchive"
);

// deprecated (will be removed with AttachmentFile entity, unified with exercise-files)
$router[] = new GetRoute("$prefix/<id>/attachment-files", "ExerciseFiles:getAttachmentFiles");
$router[] = new PostRoute("$prefix/<id>/attachment-files", "ExerciseFiles:uploadAttachmentFiles");
$router[] = new DeleteRoute("$prefix/<id>/attachment-files/<fileId>", "ExerciseFiles:deleteAttachmentFile");
$router[] = new GetRoute(
"$prefix/<id>/attachment-files/download-archive",
"ExerciseFiles:downloadAttachmentFilesArchive"
);
if (!self::$strictMode) {
// deprecated routes for supplementary-files (replaced with `files`)
$router[] = new GetRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:getExerciseFiles");
$router[] = new PostRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:uploadExerciseFiles");
$router[] = new DeleteRoute(
"$prefix/<id>/supplementary-files/<fileId>",
"ExerciseFiles:deleteExerciseFile"
);
$router[] = new GetRoute(
"$prefix/<id>/supplementary-files/download-archive",
"ExerciseFiles:downloadExerciseFilesArchive"
);

// deprecated (will be removed with AttachmentFile entity, unified with exercise-files)
$router[] = new GetRoute("$prefix/<id>/attachment-files", "ExerciseFiles:getAttachmentFiles");
$router[] = new PostRoute("$prefix/<id>/attachment-files", "ExerciseFiles:uploadAttachmentFiles");
$router[] = new DeleteRoute("$prefix/<id>/attachment-files/<fileId>", "ExerciseFiles:deleteAttachmentFile");
$router[] = new GetRoute(
"$prefix/<id>/attachment-files/download-archive",
"ExerciseFiles:downloadAttachmentFilesArchive"
);
}

$router[] = new GetRoute("$prefix/<id>/tests", "ExercisesConfig:getTests");
$router[] = new PostRoute("$prefix/<id>/tests", "ExercisesConfig:setTests");
Expand Down Expand Up @@ -483,8 +492,10 @@ private static function createUploadedFilesRoutes(string $prefix): RouteList
$router[] = new GetRoute("$prefix/<id>/content", "UploadedFiles:content");
$router[] = new GetRoute("$prefix/<id>/digest", "UploadedFiles:digest");

// deprecated (should be handled by generic download)
$router[] = new GetRoute("$prefix/supplementary-file/<id>/download", "UploadedFiles:downloadExerciseFile");
if (!self::$strictMode) {
// deprecated (should be handled by generic download)
$router[] = new GetRoute("$prefix/supplementary-file/<id>/download", "UploadedFiles:downloadExerciseFile");
}
return $router;
}

Expand Down Expand Up @@ -600,10 +611,12 @@ private static function createPipelinesRoutes(string $prefix): RouteList
$router[] = new DeleteRoute("$prefix/<id>/exercise-files/<fileId>", "Pipelines:deleteExerciseFile");
$router[] = new GetRoute("$prefix/<id>/exercises", "Pipelines:getPipelineExercises");

// deprecated routes for supplementary files
$router[] = new GetRoute("$prefix/<id>/supplementary-files", "Pipelines:getExerciseFiles");
$router[] = new PostRoute("$prefix/<id>/supplementary-files", "Pipelines:uploadExerciseFiles");
$router[] = new DeleteRoute("$prefix/<id>/supplementary-files/<fileId>", "Pipelines:deleteExerciseFile");
if (!self::$strictMode) {
// deprecated routes for supplementary files
$router[] = new GetRoute("$prefix/<id>/supplementary-files", "Pipelines:getExerciseFiles");
$router[] = new PostRoute("$prefix/<id>/supplementary-files", "Pipelines:uploadExerciseFiles");
$router[] = new DeleteRoute("$prefix/<id>/supplementary-files/<fileId>", "Pipelines:deleteExerciseFile");
}
return $router;
}

Expand Down Expand Up @@ -674,8 +687,10 @@ private static function createWorkerFilesRoutes(string $prefix): RouteList
$router[] = new GetRoute("$prefix/exercise-file/<hash>", "WorkerFiles:downloadExerciseFile");
$router[] = new PutRoute("$prefix/result/<type>/<id>", "WorkerFiles:uploadResultsFile");

// deprecated route for supplementary files
$router[] = new GetRoute("$prefix/supplementary-file/<hash>", "WorkerFiles:downloadExerciseFile");
if (!self::$strictMode) {
// deprecated route for supplementary files
$router[] = new GetRoute("$prefix/supplementary-file/<hash>", "WorkerFiles:downloadExerciseFile");
}
return $router;
}

Expand Down
1 change: 1 addition & 0 deletions app/helpers/Swagger/AnnotationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ public static function filterAnnotations(array $annotations, string $type)
*/
public static function getRoutesMetadata(): array
{
RouterFactory::setStrictMode(); // no deprecated (duplicate) routes
$router = RouterFactory::createRouter();

// find all route object using a queue
Expand Down
Loading
Loading