Skip to content

Commit 175e2e2

Browse files
committed
Removing previous modification of uploaded file (external links need a separate entity). Marking deprecated entry points.
1 parent bd9be31 commit 175e2e2

File tree

7 files changed

+29
-76
lines changed

7 files changed

+29
-76
lines changed

app/V1Module/presenters/ExerciseFilesPresenter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ public function checkUploadAttachmentFiles(string $id)
263263
/**
264264
* Associate attachment exercise files with an exercise
265265
* @POST
266+
* @DEPRECATED attachment files were unified with exercise files
266267
* @throws ForbiddenRequestException
267268
*/
268269
#[Post("files", new VMixed(), "Identifiers of attachment files", nullable: true)]
@@ -319,6 +320,7 @@ public function checkGetAttachmentFiles(string $id)
319320
/**
320321
* Get a list of all attachment files for an exercise
321322
* @GET
323+
* @DEPRECATED attachment files were unified with exercise files
322324
* @throws ForbiddenRequestException
323325
*/
324326
#[Path("id", new VUuid(), "identification of exercise", required: true)]
@@ -345,6 +347,7 @@ public function checkDeleteAttachmentFile(string $id, string $fileId)
345347
/**
346348
* Delete attachment exercise file with given id
347349
* @DELETE
350+
* @DEPRECATED attachment files were unified with exercise files
348351
* @throws ForbiddenRequestException
349352
* @throws NotFoundException
350353
*/
@@ -408,6 +411,7 @@ public function checkDownloadAttachmentFilesArchive(string $id)
408411
/**
409412
* Download archive containing all attachment files for exercise.
410413
* @GET
414+
* @DEPRECATED attachment files were unified with exercise files
411415
* @throws NotFoundException
412416
* @throws \Nette\Application\BadRequestException
413417
* @throws \Nette\Application\AbortException

app/V1Module/presenters/UploadedFilesPresenter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public function actionUpload()
353353
);
354354
}
355355

356-
// In theory, this may create race condition (DB record is commited before file is moved).
356+
// In theory, this may create race condition (DB record is committed before file is moved).
357357
// But we need the ID from the database so we can save the file.
358358
$uploadedFile = new UploadedFile($file->getName(), new DateTime(), $file->getSize(), $user);
359359
$this->uploadedFiles->persist($uploadedFile);
@@ -528,8 +528,8 @@ public function checkCompletePartial(string $id)
528528
}
529529

530530
/**
531-
* Finalize partial upload and convert the partial file into UploadFile.
532-
* All data chunks are extracted from the store, assembled into one file, and is moved back into the store.
531+
* Finalize partial upload and convert the partial file into UploadedFile entity.
532+
* All data chunks are extracted from the store, assembled into one file, and that is moved back into the store.
533533
* @POST
534534
*/
535535
#[Path("id", new VUuid(), "Identifier of the partial file", required: true)]
@@ -594,6 +594,7 @@ public function checkDownloadExerciseFile(string $id)
594594
/**
595595
* Download exercise file
596596
* @GET
597+
* @DEPRECATED use generic uploaded-file download endpoint instead
597598
* @throws ForbiddenRequestException
598599
* @throws NotFoundException
599600
* @throws \Nette\Application\AbortException

app/V1Module/router/RouterFactory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private static function createExercisesRoutes(string $prefix): RouteList
173173
"ExerciseFiles:downloadExerciseFilesArchive"
174174
);
175175

176-
// deprecated routes for supplementary files
176+
// deprecated routes for supplementary files (replaced with exercise-files)
177177
$router[] = new GetRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:getExerciseFiles");
178178
$router[] = new PostRoute("$prefix/<id>/supplementary-files", "ExerciseFiles:uploadExerciseFiles");
179179
$router[] = new DeleteRoute(
@@ -185,6 +185,7 @@ private static function createExercisesRoutes(string $prefix): RouteList
185185
"ExerciseFiles:downloadExerciseFilesArchive"
186186
);
187187

188+
// deprecated (will be removed with AttachmentFile entity, unified with exercise-files)
188189
$router[] = new GetRoute("$prefix/<id>/attachment-files", "ExerciseFiles:getAttachmentFiles");
189190
$router[] = new PostRoute("$prefix/<id>/attachment-files", "ExerciseFiles:uploadAttachmentFiles");
190191
$router[] = new DeleteRoute("$prefix/<id>/attachment-files/<fileId>", "ExerciseFiles:deleteAttachmentFile");
@@ -470,11 +471,13 @@ private static function createUploadedFilesRoutes(string $prefix): RouteList
470471
$router[] = new PostRoute("$prefix/partial/<id>", "UploadedFiles:completePartial");
471472

472473
$router[] = new PostRoute("$prefix", "UploadedFiles:upload");
473-
$router[] = new GetRoute("$prefix/supplementary-file/<id>/download", "UploadedFiles:downloadExerciseFile");
474474
$router[] = new GetRoute("$prefix/<id>", "UploadedFiles:detail");
475475
$router[] = new GetRoute("$prefix/<id>/download", "UploadedFiles:download");
476476
$router[] = new GetRoute("$prefix/<id>/content", "UploadedFiles:content");
477477
$router[] = new GetRoute("$prefix/<id>/digest", "UploadedFiles:digest");
478+
479+
// deprecated (should be handled by generic download)
480+
$router[] = new GetRoute("$prefix/supplementary-file/<id>/download", "UploadedFiles:downloadExerciseFile");
478481
return $router;
479482
}
480483

app/V1Module/security/Policies/UploadedFilePermissionPolicy.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace App\Security\Policies;
44

5-
use App\Model\Entity\Assignment;
65
use App\Model\Entity\AttachmentFile;
76
use App\Model\Entity\Exercise;
87
use App\Model\Entity\ExerciseFile;
8+
use App\Model\Entity\Group;
99
use App\Model\Entity\UploadedFile;
1010
use App\Model\Repository\Assignments;
1111
use App\Model\Repository\UploadedFiles;
@@ -61,6 +61,7 @@ public function isAuthorOfFileExercises(Identity $identity, UploadedFile $file)
6161
}
6262

6363
foreach ($file->getExercises() as $exercise) {
64+
/** @var Exercise $exercise */
6465
if ($exercise->isAuthor($user)) {
6566
return true;
6667
}
@@ -82,7 +83,9 @@ public function isExerciseFileInGroupUserSupervises(Identity $identity, Uploaded
8283
}
8384

8485
foreach ($file->getExercises() as $exercise) {
86+
/** @var Exercise $exercise */
8587
foreach ($exercise->getGroups() as $group) {
88+
/** @var Group $group */
8689
if ($group->isAdminOrSupervisorOfSubgroup($user)) {
8790
return true; // The user can assign one of the corresponding exercises in hir group.
8891
}
@@ -103,7 +106,7 @@ public function isOwner(Identity $identity, UploadedFile $file)
103106
return $file->getUser() && $file->getUser()->getId() === $user->getId();
104107
}
105108

106-
public function isReferenceSolutionInSupervisedOrObserverdSubGroup(Identity $identity, UploadedFile $file)
109+
public function isReferenceSolutionInSupervisedOrObservedSubGroup(Identity $identity, UploadedFile $file)
107110
{
108111
$user = $identity->getUserData();
109112
if ($user === null) {
@@ -140,6 +143,7 @@ public function isRelatedToAssignment(Identity $identity, UploadedFile $file)
140143

141144
if ($file instanceof AttachmentFile) {
142145
foreach ($file->getExercises() as $exercise) {
146+
/** @var Exercise $exercise */
143147
foreach ($user->getGroups() as $group) {
144148
if ($this->assignments->isAssignedToGroup($exercise, $group)) {
145149
return true;

app/config/permissions.neon

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ permissions:
4343
actions:
4444
- takeOver
4545

46-
- allow: false # A safety mechanism that prevents us from accidentaly allowing account takeover to non-admins (e.g. by wildcard rules)
46+
- allow: false # A safety mechanism that prevents us from accidentally allowing account takeover to non-admins (e.g. by wildcard rules)
4747
actions:
4848
- takeOver
4949

@@ -743,7 +743,7 @@ permissions:
743743
actions:
744744
- viewThread
745745
- addComment
746-
conditions: # TODO - make sure only apropriate group members/authors can do this
746+
conditions: # TODO - make sure only appropriate group members/authors can do this
747747
- userIsNotGroupLocked
748748

749749
- allow: true
@@ -1030,15 +1030,15 @@ permissions:
10301030
actions:
10311031
- download
10321032
- viewDetail
1033-
- downloadExerciseFile
1033+
- downloadExerciseFile # deprecated (replaced with generic download)
10341034

10351035
- allow: true
10361036
role: scope-ref-solutions
10371037
resource: uploadedFile
10381038
actions:
10391039
- download
10401040
- viewDetail
1041-
- downloadExerciseFile
1041+
- downloadExerciseFile # deprecated (replaced with generic download)
10421042
- upload
10431043

10441044
- allow: true
@@ -1075,11 +1075,14 @@ permissions:
10751075
conditions:
10761076
or:
10771077
- file.isSolutionInSupervisedOrObservedGroup
1078-
- file.isReferenceSolutionInSupervisedOrObserverdSubGroup
1078+
- file.isReferenceSolutionInSupervisedOrObservedSubGroup
10791079
- file.isPublic
10801080
- file.isOwner
1081-
- file.isRelatedToAssignment
1081+
- file.isRelatedToAssignment # deprecated (will be removed with Attachment files)
1082+
- file.isAuthorOfFileExercises
1083+
- file.isExerciseFileInGroupUserSupervises
10821084

1085+
# deprecated (will be removed with Attachment files)
10831086
- allow: true
10841087
role: supervisor-student
10851088
resource: uploadedFile
@@ -1094,8 +1097,7 @@ permissions:
10941097
role: supervisor-student
10951098
resource: uploadedFile
10961099
actions:
1097-
- viewDetail
1098-
- downloadExerciseFile
1100+
- downloadExerciseFile # deprecated (replaced with generic download)
10991101
conditions:
11001102
or:
11011103
- file.isAuthorOfFileExercises

app/model/entity/UploadedFile.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ public function getFileExtension(): string
5252
*/
5353
protected $isPublic;
5454

55-
/**
56-
* External identification (used in URL) that allows for accessing the file without authentication.
57-
* If empty, the file is not accessible this way.
58-
* The identifier should be a generated random string.
59-
* @ORM\Column(type="string", length=16, nullable=true, unique=true)
60-
*/
61-
protected $external = null;
62-
6355
/**
6456
* @ORM\Column(type="integer")
6557
*/
@@ -128,26 +120,6 @@ public function setPublic(bool $isPublic): void
128120
$this->isPublic = $isPublic;
129121
}
130122

131-
public function getExternal(): ?string
132-
{
133-
return $this->external;
134-
}
135-
136-
public function setExternal(?string $external): void
137-
{
138-
$this->external = $external;
139-
}
140-
141-
/**
142-
* Generate a random external ID for this file which uses only URL-safe characters.
143-
*/
144-
public function generateRandomExternalId(): void
145-
{
146-
// the + and / characters are replaced to make the string URL-safe without the need for encoding
147-
// (base64 encoding uses A-Z, a-z, 0-9, +, /)
148-
$this->external = str_replace(['+', '/'], ['-', '$'], base64_encode(random_bytes(12)));
149-
}
150-
151123
/**
152124
* Retrieve a corresponding file object from file storage.
153125
* @param FileStorageManager $manager the storage that retrieves the file

migrations/Version20251113182809.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)