Everyone who may comment on a task sends images to it, e.g. photos taken with a phone. The server stores an upright, at most 2560 px JPEG without EXIF data (no location) and a 400 px thumbnail on the private disk, served only to those who see the job. Uploaders change captions (also the alt text) and remove their own images; admin and management may remove anyone's (jobs.remove-any-task-image). Removing a task also removes its image files. Livewire's temporary upload limit is raised to PHP's 40 MB so that the page's own 12 MB limit gives a translated message. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Jobs\Application\UseCases;
|
|
|
|
use App\Modules\Jobs\Application\Contracts\TaskImageFiles;
|
|
use App\Modules\Jobs\Application\Services\TaskImageFinder;
|
|
use App\Modules\Jobs\Domain\Contracts\TaskImageRepository;
|
|
use App\Modules\Jobs\Domain\Exceptions\NotTaskImageUploader;
|
|
use App\Modules\Jobs\Domain\Exceptions\TaskImageNotFound;
|
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
|
|
|
/**
|
|
* Removes the user's own image, or anyone's when the user may remove
|
|
* others' images (admin and management), and then its files.
|
|
*/
|
|
final class RemoveTaskImage
|
|
{
|
|
public function __construct(
|
|
private TaskImageFinder $finder,
|
|
private TaskImageRepository $images,
|
|
private TaskImageFiles $files,
|
|
private TransactionManager $transactions,
|
|
) {}
|
|
|
|
/**
|
|
* @throws TaskNotFound
|
|
* @throws TaskImageNotFound
|
|
* @throws NotTaskImageUploader
|
|
*/
|
|
public function execute(int $jobId, int $taskId, int $imageId, int $userId, bool $mayRemoveOthers): void
|
|
{
|
|
$paths = $this->transactions->run(function () use ($jobId, $taskId, $imageId, $userId, $mayRemoveOthers): array {
|
|
$image = $this->finder->find($jobId, $taskId, $imageId);
|
|
$image->ensureRemovableBy($userId, $mayRemoveOthers);
|
|
|
|
$this->images->delete($image);
|
|
|
|
return $image->file()->paths();
|
|
});
|
|
|
|
$this->files->delete($paths);
|
|
}
|
|
}
|