Skip to content

Commit 7938390

Browse files
author
Martin Krulis
committed
Adding version validation for shadow assignments.
1 parent 2597a73 commit 7938390

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

app/V1Module/presenters/ShadowAssignmentsPresenter.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ public function actionDetail(string $id) {
105105
$this->sendSuccessResponse($this->shadowAssignmentViewFactory->getAssignment($assignment));
106106
}
107107

108+
public function checkValidate(string $id) {
109+
$assignment = $this->shadowAssignments->findOrThrow($id);
110+
if (!$this->shadowAssignmentAcl->canUpdate($assignment)) {
111+
throw new ForbiddenRequestException("You cannot access this shadow assignment.");
112+
}
113+
}
114+
115+
/**
116+
* Check if the version of the shadow assignment is up-to-date.
117+
* @POST
118+
* @Param(type="post", name="version", validation="numericint", description="Version of the shadow assignment.")
119+
* @param string $id Identifier of the shadow assignment
120+
* @throws ForbiddenRequestException
121+
*/
122+
public function actionValidate($id) {
123+
$assignment = $this->shadowAssignments->findOrThrow($id);
124+
$version = intval($this->getHttpRequest()->getPost("version"));
125+
$this->sendSuccessResponse([
126+
"versionIsUpToDate" => $assignment->getVersion() === $version
127+
]);
128+
}
129+
108130
public function checkUpdateDetail(string $id) {
109131
$assignment = $this->shadowAssignments->findOrThrow($id);
110132
if (!$this->shadowAssignmentAcl->canUpdate($assignment)) {

app/V1Module/router/RouterFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ private static function createShadowAssignmentsRoutes(string $prefix): RouteList
455455
$router[] = new PostRoute("$prefix/<id>", "ShadowAssignments:updateDetail");
456456
$router[] = new PostRoute("$prefix", "ShadowAssignments:create");
457457
$router[] = new DeleteRoute("$prefix/<id>", "ShadowAssignments:remove");
458+
$router[] = new PostRoute("$prefix/<id>/validate", "ShadowAssignments:validate");
458459
$router[] = new GetRoute("$prefix/<id>/points", "ShadowAssignments:pointsList");
459460
$router[] = new PostRoute("$prefix/<id>/points", "ShadowAssignments:createPoints");
460461
$router[] = new GetRoute("$prefix/points/<pointsId>", "ShadowAssignments:points");

0 commit comments

Comments
 (0)