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
4 changes: 2 additions & 2 deletions app/Application/Media/TemporaryImageStorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

interface TemporaryImageStorageInterface
{
public const string PROFILE_PICTURE_DIRECTORY = 'tmp/reports/profile';
public const string PROFILE_PICTURE_DIRECTORY = 'tmp/reports/profiles';

public const string PROOF_DIRECTORY = 'tmp/reports/proofs';

Expand All @@ -21,7 +21,7 @@ public function uploadProof(UploadedFile $file): string;
/**
* Copy a published temporary file into a permanent public directory.
*
* $location is a public-disk path such as `/storage/tmp/reports/profile/file.jpg`,
* $location is a public-disk path such as `/storage/tmp/reports/profiles/file.jpg`,
* or the absolute public URL of that file. The file must exist directly inside
* $sourceDirectory. Returns the relative permanent path.
*/
Expand Down
16 changes: 9 additions & 7 deletions app/Application/Report/Usecases/ReportUsecase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@

class ReportUsecase implements ReportUsecaseInterface
{
public const string AVATAR_DIRECTORY = 'reports/organizations/avatars';
public const string ORGANIZATION_PROFILE_DIRECTORY = 'reports/organizations/profiles';

public const string SCAMMER_AVATAR_DIRECTORY = 'reports/scammers/avatars';
public const string SCAMMER_PROFILE_DIRECTORY = 'reports/scammers/profiles';

public const string PROOF_DIRECTORY = 'reports/proofs';
public const string ORGANIZATION_PROOF_DIRECTORY = 'reports/organizations/proofs';

public const string SCAMMER_PROOF_DIRECTORY = 'reports/scammers/proofs';

public function __construct(
private SearchRepositoryInterface $search,
Expand Down Expand Up @@ -81,7 +83,7 @@ public function storeOrganization(StoreOrganizationReportCommand $command): arra
$avatarPath = $this->copyTemporary(
$command->profilePicture,
TemporaryImageStorageInterface::PROFILE_PICTURE_DIRECTORY,
self::AVATAR_DIRECTORY,
self::ORGANIZATION_PROFILE_DIRECTORY,
'profile_picture',
);
$copied[] = $avatarPath;
Expand All @@ -93,7 +95,7 @@ public function storeOrganization(StoreOrganizationReportCommand $command): arra
$path = $this->copyTemporary(
$url,
TemporaryImageStorageInterface::PROOF_DIRECTORY,
self::PROOF_DIRECTORY,
self::ORGANIZATION_PROOF_DIRECTORY,
'proofs.'.$index,
);
$copied[] = $path;
Expand Down Expand Up @@ -176,7 +178,7 @@ public function storeScammer(StoreScammerReportCommand $command): array
$avatarPath = $this->copyTemporary(
$command->profilePicture,
TemporaryImageStorageInterface::PROFILE_PICTURE_DIRECTORY,
self::SCAMMER_AVATAR_DIRECTORY,
self::SCAMMER_PROFILE_DIRECTORY,
'profile_picture',
);
$copied[] = $avatarPath;
Expand All @@ -188,7 +190,7 @@ public function storeScammer(StoreScammerReportCommand $command): array
$path = $this->copyTemporary(
$url,
TemporaryImageStorageInterface::PROOF_DIRECTORY,
self::PROOF_DIRECTORY,
self::SCAMMER_PROOF_DIRECTORY,
'proofs.'.$index,
);
$copied[] = $path;
Expand Down
22 changes: 11 additions & 11 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ paths:
description: |
Accepts a JPG or PNG image up to 5 MB. The original is stored on the raw
disk and must pass image moderation before a 640×640 cover is published on
the public disk under `tmp/reports/profile`. The response path is
the public disk under `tmp/reports/profiles`. The response path is
the public URL of that file. Uploading the same image again returns the
existing URL while the file is still present. A rejected image is moved
to quarantine and the response does not include its path; it responds
Expand All @@ -405,7 +405,7 @@ paths:
schema:
$ref: "#/components/schemas/StoredImagePath"
example:
path: http://localhost:9000/storage/tmp/reports/profile/8f3c1a.jpg
path: http://localhost:9000/storage/tmp/reports/profiles/8f3c1a.jpg
"422":
$ref: "#/components/responses/ValidationFailed"
"429":
Expand Down Expand Up @@ -464,7 +464,7 @@ paths:
platform and reference is reused, and a payment method that already exists
for the same type and reference is reused. A trashed match is restored.
`profile_picture` and `proofs` are public-disk paths previously returned by
the temporary media endpoints, such as `/storage/tmp/reports/profile/file.jpg`,
the temporary media endpoints, such as `/storage/tmp/reports/profiles/file.jpg`,
and the files must still be present.
The report is stored without a user and is active.
requestBody:
Expand All @@ -476,7 +476,7 @@ paths:
example:
title: Fake store took my money
description: They never shipped the order.
profile_picture: /storage/tmp/reports/profile/8f3c1a.jpg
profile_picture: /storage/tmp/reports/profiles/8f3c1a.jpg
proofs:
- /storage/tmp/reports/proofs/8f3c1a.jpg
- /storage/tmp/reports/proofs/9a4d2b.png
Expand Down Expand Up @@ -516,7 +516,7 @@ paths:
platform and reference is reused, and a payment method that already exists
for the same type and reference is reused. A trashed match is restored.
`profile_picture` and `proofs` are public-disk paths previously returned by
the temporary media endpoints, such as `/storage/tmp/reports/profile/file.jpg`,
the temporary media endpoints, such as `/storage/tmp/reports/profiles/file.jpg`,
and the files must still be present.
The report is stored without a user and is active.
requestBody:
Expand All @@ -528,7 +528,7 @@ paths:
example:
title: Called me about a prize
description: They asked for a transfer to release the prize.
profile_picture: /storage/tmp/reports/profile/8f3c1a.jpg
profile_picture: /storage/tmp/reports/profiles/8f3c1a.jpg
proofs:
- /storage/tmp/reports/proofs/8f3c1a.jpg
- /storage/tmp/reports/proofs/9a4d2b.png
Expand Down Expand Up @@ -737,7 +737,7 @@ components:
type: string
format: uri
description: Public URL of the stored image.
example: http://localhost:9000/storage/tmp/reports/profile/8f3c1a.jpg
example: http://localhost:9000/storage/tmp/reports/profiles/8f3c1a.jpg
StoredImagePaths:
type: object
required: [paths]
Expand Down Expand Up @@ -768,8 +768,8 @@ components:
type:
- string
- "null"
description: Public-disk path of a file under `tmp/reports/profile`.
example: /storage/tmp/reports/profile/8f3c1a.jpg
description: Public-disk path of a file under `tmp/reports/profiles`.
example: /storage/tmp/reports/profiles/8f3c1a.jpg
proofs:
type: array
items:
Expand Down Expand Up @@ -870,8 +870,8 @@ components:
type:
- string
- "null"
description: Public-disk path of a file under `tmp/reports/profile`.
example: /storage/tmp/reports/profile/8f3c1a.jpg
description: Public-disk path of a file under `tmp/reports/profiles`.
example: /storage/tmp/reports/profiles/8f3c1a.jpg
proofs:
type: array
items:
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/PublicReportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function test_stores_jpg_and_png_profile_pictures_for_scammers_and_organi

$extension = pathinfo($filename, PATHINFO_EXTENSION);
$url = $response->json('path');
$prefix = config('filesystems.disks.public.url').'/tmp/reports/profile/';
$prefix = config('filesystems.disks.public.url').'/tmp/reports/profiles/';

$this->assertStringStartsWith($prefix, $url);
$this->assertStringEndsWith('.'.$extension, $url);
Expand Down Expand Up @@ -94,7 +94,7 @@ public function passes(string $contents): bool
$quarantined = Storage::disk('quarantine')->allFiles();

$this->assertCount(1, $quarantined);
$this->assertStringStartsWith('tmp/reports/profile/', $quarantined[0]);
$this->assertStringStartsWith('tmp/reports/profiles/', $quarantined[0]);
$this->assertSame($contents, Storage::disk('quarantine')->get($quarantined[0]));
$this->assertSame([], Storage::disk('public')->allFiles());
$this->assertSame([], Storage::disk('raw')->allFiles());
Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/StoreOrganizationReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function test_creates_an_organization_report_with_contacts_payment_method
$this->assertSame('Tienda Falsa', $organization->name);
$this->assertTrue($organization->reports()->whereKey($report->id)->exists());

$this->assertStringStartsWith('reports/organizations/avatars/', $organization->profile_picture_path);
$this->assertStringStartsWith('reports/organizations/profiles/', $organization->profile_picture_path);
$this->assertSame('avatar', Storage::disk('public')->get($organization->profile_picture_path));
$this->assertTrue(Storage::disk('public')->exists(TemporaryImageStorageInterface::PROFILE_PICTURE_DIRECTORY.'/avatar.jpg'));

Expand All @@ -76,6 +76,8 @@ public function test_creates_an_organization_report_with_contacts_payment_method
Storage::disk('public')->get($storedProofs[0]->path),
Storage::disk('public')->get($storedProofs[1]->path),
]);
$this->assertStringStartsWith('reports/organizations/proofs/', $storedProofs[0]->path);
$this->assertStringStartsWith('reports/organizations/proofs/', $storedProofs[1]->path);
$this->assertTrue(Storage::disk('public')->exists(TemporaryImageStorageInterface::PROOF_DIRECTORY.'/one.jpg'));
$this->assertTrue(Storage::disk('public')->exists(TemporaryImageStorageInterface::PROOF_DIRECTORY.'/two.png'));

Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/StoreScammerReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function test_creates_a_scammer_report_with_contacts_payment_methods_and_
$this->assertSame('Juan Perez', $scammer->name);
$this->assertTrue($scammer->reports()->whereKey($report->id)->exists());

$this->assertStringStartsWith('reports/scammers/avatars/', $scammer->profile_picture_path);
$this->assertStringStartsWith('reports/scammers/profiles/', $scammer->profile_picture_path);
$this->assertSame('avatar', Storage::disk('public')->get($scammer->profile_picture_path));
$this->assertTrue(Storage::disk('public')->exists(TemporaryImageStorageInterface::PROFILE_PICTURE_DIRECTORY.'/avatar.jpg'));

Expand All @@ -76,6 +76,8 @@ public function test_creates_a_scammer_report_with_contacts_payment_methods_and_
Storage::disk('public')->get($storedProofs[0]->path),
Storage::disk('public')->get($storedProofs[1]->path),
]);
$this->assertStringStartsWith('reports/scammers/proofs/', $storedProofs[0]->path);
$this->assertStringStartsWith('reports/scammers/proofs/', $storedProofs[1]->path);
$this->assertTrue(Storage::disk('public')->exists(TemporaryImageStorageInterface::PROOF_DIRECTORY.'/one.jpg'));
$this->assertTrue(Storage::disk('public')->exists(TemporaryImageStorageInterface::PROOF_DIRECTORY.'/two.png'));

Expand Down
Loading