From e9fff5fb9ed8336525c5f7f3e3b14283aee56fd5 Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Mon, 25 Nov 2024 08:50:46 +0100 Subject: [PATCH 1/6] Refactor AssetMediaType to MediaType in OpenAPI namespace --- src/Asset/Controller/Document/PreviewStreamController.php | 4 ++-- src/Asset/Controller/Download/DownloadCsvController.php | 4 ++-- src/Asset/Controller/Download/DownloadZipController.php | 4 ++-- src/Asset/Controller/DownloadController.php | 4 ++-- src/Asset/Controller/Image/CustomDownloadController.php | 4 ++-- src/Asset/Controller/Image/FormatDownloadController.php | 4 ++-- src/Asset/Controller/Image/PreviewStreamController.php | 4 ++-- src/Asset/Controller/Image/ThumbnailDownloadController.php | 4 ++-- .../Controller/Video/ImageThumbnailStreamController.php | 4 ++-- src/Asset/Controller/Video/ThumbnailDownloadController.php | 4 ++-- src/Asset/Controller/Video/ThumbnailStreamController.php | 4 ++-- .../Attribute/Response/Content/MediaType.php} | 6 +++--- src/Version/Controller/Asset/DownloadController.php | 4 ++-- src/Version/Controller/Asset/ImageStreamController.php | 4 ++-- src/Version/Controller/Asset/PdfStreamController.php | 4 ++-- 15 files changed, 31 insertions(+), 31 deletions(-) rename src/{Asset/Attribute/Response/Content/AssetMediaType.php => OpenApi/Attribute/Response/Content/MediaType.php} (81%) diff --git a/src/Asset/Controller/Document/PreviewStreamController.php b/src/Asset/Controller/Document/PreviewStreamController.php index 3c91ec50a..84dcec946 100644 --- a/src/Asset/Controller/Document/PreviewStreamController.php +++ b/src/Asset/Controller/Document/PreviewStreamController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Document; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\DocumentServiceInterface; @@ -29,6 +28,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidElementTypeException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UnprocessableContentException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -82,7 +82,7 @@ public function __construct( #[IdParameter(type: 'document')] #[SuccessResponse( description: 'asset_document_stream_preview_success_response', - content: new AssetMediaType('application/pdf'), + content: new MediaType('application/pdf'), headers: [new ContentDisposition('inline')] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Download/DownloadCsvController.php b/src/Asset/Controller/Download/DownloadCsvController.php index 43a3b01ad..6fab2ea15 100644 --- a/src/Asset/Controller/Download/DownloadCsvController.php +++ b/src/Asset/Controller/Download/DownloadCsvController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Download; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\DownloadServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\ExecutionEngine\CsvServiceInterface; @@ -27,6 +26,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\StreamResourceNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -65,7 +65,7 @@ public function __construct( #[IdParameter(type: 'JobRun', name: 'jobRunId')] #[SuccessResponse( description: 'asset_download_csv_success_response', - content: [new AssetMediaType('application/csv')], + content: [new MediaType('application/csv')], headers: [new ContentDisposition()] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Download/DownloadZipController.php b/src/Asset/Controller/Download/DownloadZipController.php index f2cccb8b4..2986f5f87 100644 --- a/src/Asset/Controller/Download/DownloadZipController.php +++ b/src/Asset/Controller/Download/DownloadZipController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Download; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\DownloadServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\ExecutionEngine\ZipServiceInterface; @@ -27,6 +26,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\StreamResourceNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -65,7 +65,7 @@ public function __construct( #[IdParameter(type: 'JobRun', name: 'jobRunId')] #[SuccessResponse( description: 'asset_download_zip_success_response', - content: [new AssetMediaType('application/zip')], + content: [new MediaType('application/zip')], headers: [new ContentDisposition()] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/DownloadController.php b/src/Asset/Controller/DownloadController.php index 0c340010e..95d75ade5 100644 --- a/src/Asset/Controller/DownloadController.php +++ b/src/Asset/Controller/DownloadController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\DownloadServiceInterface; @@ -28,6 +27,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -73,7 +73,7 @@ public function __construct( #[IdParameter(type: ElementTypes::TYPE_ASSET)] #[SuccessResponse( description: 'asset_download_by_id_success_response', - content: new AssetMediaType(), + content: new MediaType(), headers: [new ContentDisposition()] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Image/CustomDownloadController.php b/src/Asset/Controller/Image/CustomDownloadController.php index 81e71ab5a..537245338 100644 --- a/src/Asset/Controller/Image/CustomDownloadController.php +++ b/src/Asset/Controller/Image/CustomDownloadController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Image; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\MappedParameter\ImageDownloadConfigParameter; use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query\ImageConfigParameter; @@ -32,6 +31,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ThumbnailResizingFailedException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -87,7 +87,7 @@ public function __construct( #[ImageConfigParameter('dpi')] #[SuccessResponse( description: 'asset_image_download_custom_success_response', - content: [new AssetMediaType('image/jpeg'), new AssetMediaType('image/png')], + content: [new MediaType('image/jpeg'), new MediaType('image/png')], headers: [new ContentDisposition()] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Image/FormatDownloadController.php b/src/Asset/Controller/Image/FormatDownloadController.php index 892a24177..6dd986b90 100644 --- a/src/Asset/Controller/Image/FormatDownloadController.php +++ b/src/Asset/Controller/Image/FormatDownloadController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Image; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\FormatTypeParameter; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; @@ -30,6 +29,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ThumbnailResizingFailedException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -82,7 +82,7 @@ public function __construct( #[FormatTypeParameter] #[SuccessResponse( description: 'asset_image_download_by_format_success_response', - content: new AssetMediaType('image/jpeg'), + content: new MediaType('image/jpeg'), headers: [new ContentDisposition()] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Image/PreviewStreamController.php b/src/Asset/Controller/Image/PreviewStreamController.php index c705ffc9c..a5a2db381 100644 --- a/src/Asset/Controller/Image/PreviewStreamController.php +++ b/src/Asset/Controller/Image/PreviewStreamController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Image; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\BinaryServiceInterface; @@ -28,6 +27,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -77,7 +77,7 @@ public function __construct( #[IdParameter(type: 'image')] #[SuccessResponse( description: 'asset_image_stream_preview_success_response', - content: [new AssetMediaType('image/*')], + content: [new MediaType('image/*')], headers: [new ContentDisposition(HttpResponseHeaders::INLINE_TYPE->value)] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Image/ThumbnailDownloadController.php b/src/Asset/Controller/Image/ThumbnailDownloadController.php index 33fec52ad..e4017552c 100644 --- a/src/Asset/Controller/Image/ThumbnailDownloadController.php +++ b/src/Asset/Controller/Image/ThumbnailDownloadController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Image; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\ThumbnailNameParameter; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; @@ -29,6 +28,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -78,7 +78,7 @@ public function __construct( #[ThumbnailNameParameter] #[SuccessResponse( description: 'asset_image_download_by_thumbnail_success_response', - content: new AssetMediaType(), + content: new MediaType(), headers: [new ContentDisposition()] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Video/ImageThumbnailStreamController.php b/src/Asset/Controller/Video/ImageThumbnailStreamController.php index d66b52137..200af814a 100644 --- a/src/Asset/Controller/Video/ImageThumbnailStreamController.php +++ b/src/Asset/Controller/Video/ImageThumbnailStreamController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Video; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\MappedParameter\VideoImageStreamConfigParameter; use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Query\AspectRatioParameter; @@ -35,6 +34,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidThumbnailException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -91,7 +91,7 @@ public function __construct( #[AsyncGenerationParameter] #[SuccessResponse( description: 'asset_video_image_thumbnail_stream_success_response', - content: [new AssetMediaType('image/*')], + content: [new MediaType('image/*')], headers: [new ContentDisposition(HttpResponseHeaders::INLINE_TYPE->value)] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Video/ThumbnailDownloadController.php b/src/Asset/Controller/Video/ThumbnailDownloadController.php index d1c83b607..7dacb23fe 100644 --- a/src/Asset/Controller/Video/ThumbnailDownloadController.php +++ b/src/Asset/Controller/Video/ThumbnailDownloadController.php @@ -18,7 +18,6 @@ use League\Flysystem\FilesystemException; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\ThumbnailNameParameter; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; @@ -31,6 +30,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -82,7 +82,7 @@ public function __construct( #[ThumbnailNameParameter] #[SuccessResponse( description: 'asset_video_download_by_thumbnail_success_response', - content: new AssetMediaType('video/mp4'), + content: new MediaType('video/mp4'), headers: [new ContentDisposition()] )] #[DefaultResponses([ diff --git a/src/Asset/Controller/Video/ThumbnailStreamController.php b/src/Asset/Controller/Video/ThumbnailStreamController.php index 7174be7ff..4d63207d0 100644 --- a/src/Asset/Controller/Video/ThumbnailStreamController.php +++ b/src/Asset/Controller/Video/ThumbnailStreamController.php @@ -18,7 +18,6 @@ use League\Flysystem\FilesystemException; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attribute\Parameter\Path\ThumbnailNameParameter; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; @@ -31,6 +30,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -82,7 +82,7 @@ public function __construct( #[ThumbnailNameParameter] #[SuccessResponse( description: 'asset_video_stream_by_thumbnail_success_response', - content: new AssetMediaType('video/mp4'), + content: new MediaType('video/mp4'), headers: [new ContentDisposition('inline')] )] #[DefaultResponses([ diff --git a/src/Asset/Attribute/Response/Content/AssetMediaType.php b/src/OpenApi/Attribute/Response/Content/MediaType.php similarity index 81% rename from src/Asset/Attribute/Response/Content/AssetMediaType.php rename to src/OpenApi/Attribute/Response/Content/MediaType.php index 1107a108e..3a715a501 100644 --- a/src/Asset/Attribute/Response/Content/AssetMediaType.php +++ b/src/OpenApi/Attribute/Response/Content/MediaType.php @@ -14,15 +14,15 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content; +namespace Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content; -use OpenApi\Attributes\MediaType; +use OpenApi\Attributes\MediaType as OpenApiMediaType; use OpenApi\Attributes\Schema; /** * @internal */ -final class AssetMediaType extends MediaType +final class MediaType extends OpenApiMediaType { public function __construct(string $mimeType = 'application/*') { diff --git a/src/Version/Controller/Asset/DownloadController.php b/src/Version/Controller/Asset/DownloadController.php index 0229043b1..61ec671ce 100644 --- a/src/Version/Controller/Asset/DownloadController.php +++ b/src/Version/Controller/Asset/DownloadController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Version\Controller\Asset; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; @@ -25,6 +24,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -65,7 +65,7 @@ public function __construct( #[IdParameter(type: 'version')] #[SuccessResponse( description: 'version_asset_download_by_id_success_response', - content: new AssetMediaType('application/*'), + content: new MediaType('application/*'), headers: [new ContentDisposition()] )] #[DefaultResponses([ diff --git a/src/Version/Controller/Asset/ImageStreamController.php b/src/Version/Controller/Asset/ImageStreamController.php index 738b07de5..e1369e242 100644 --- a/src/Version/Controller/Asset/ImageStreamController.php +++ b/src/Version/Controller/Asset/ImageStreamController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Version\Controller\Asset; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; @@ -25,6 +24,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -66,7 +66,7 @@ public function __construct( #[IdParameter(type: 'version')] #[SuccessResponse( description: 'version_image_stream_by_id_success_response', - content: new AssetMediaType('image/*'), + content: new MediaType('image/*'), headers: [new ContentDisposition(HttpResponseHeaders::INLINE_TYPE->value)] )] #[DefaultResponses([ diff --git a/src/Version/Controller/Asset/PdfStreamController.php b/src/Version/Controller/Asset/PdfStreamController.php index 285f7330c..4ec0cbdaf 100644 --- a/src/Version/Controller/Asset/PdfStreamController.php +++ b/src/Version/Controller/Asset/PdfStreamController.php @@ -17,7 +17,6 @@ namespace Pimcore\Bundle\StudioBackendBundle\Version\Controller\Asset; use OpenApi\Attributes\Get; -use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Content\AssetMediaType; use Pimcore\Bundle\StudioBackendBundle\Asset\Attribute\Response\Header\ContentDisposition; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; @@ -28,6 +27,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UnprocessableContentException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; @@ -75,7 +75,7 @@ public function __construct( #[IdParameter(type: 'version')] #[SuccessResponse( description: 'version_pdf_stream_by_id_success_response', - content: new AssetMediaType('application/pdf'), + content: new MediaType('application/pdf'), headers: [new ContentDisposition(HttpResponseHeaders::INLINE_TYPE->value)] )] #[DefaultResponses([ From 118a2e26037f41faf1d8438cec776d5a920145c3 Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Mon, 25 Nov 2024 11:29:38 +0100 Subject: [PATCH 2/6] Add get user image --- config/users.yaml | 4 +- .../Controller/UploadUserImageController.php | 4 +- src/User/Controller/UserImageController.php | 79 +++++++++++++++++++ ...mageUploadService.php => ImageService.php} | 16 +++- ...nterface.php => ImageServiceInterface.php} | 5 +- ...adServiceTest.php => ImageServiceTest.php} | 32 ++++++-- 6 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 src/User/Controller/UserImageController.php rename src/User/Service/{ImageUploadService.php => ImageService.php} (79%) rename src/User/Service/{ImageUploadServiceInterface.php => ImageServiceInterface.php} (79%) rename tests/Unit/User/Service/{ImageUploadServiceTest.php => ImageServiceTest.php} (76%) diff --git a/config/users.yaml b/config/users.yaml index 605760de2..a42193468 100644 --- a/config/users.yaml +++ b/config/users.yaml @@ -47,8 +47,8 @@ services: Pimcore\Bundle\StudioBackendBundle\User\Service\KeyBindingServiceInterface: class: Pimcore\Bundle\StudioBackendBundle\User\Service\KeyBindingService - Pimcore\Bundle\StudioBackendBundle\User\Service\ImageUploadServiceInterface: - class: Pimcore\Bundle\StudioBackendBundle\User\Service\ImageUploadService + Pimcore\Bundle\StudioBackendBundle\User\Service\ImageServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\User\Service\ImageService diff --git a/src/User/Controller/UploadUserImageController.php b/src/User/Controller/UploadUserImageController.php index 78b942ed5..ca66406ec 100644 --- a/src/User/Controller/UploadUserImageController.php +++ b/src/User/Controller/UploadUserImageController.php @@ -29,7 +29,7 @@ use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; -use Pimcore\Bundle\StudioBackendBundle\User\Service\ImageUploadServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\User\Service\ImageServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait; @@ -49,7 +49,7 @@ final class UploadUserImageController extends AbstractApiController public function __construct( SerializerInterface $serializer, - private readonly ImageUploadServiceInterface $imageUploadService + private readonly ImageServiceInterface $imageUploadService ) { parent::__construct($serializer); } diff --git a/src/User/Controller/UserImageController.php b/src/User/Controller/UserImageController.php new file mode 100644 index 000000000..d145f7a50 --- /dev/null +++ b/src/User/Controller/UserImageController.php @@ -0,0 +1,79 @@ +value)] + #[Get( + path: self::PREFIX . '/user/image/{id}', + operationId: 'user_get_image', + summary: 'user_get_image_summary', + tags: [Tags::User->value] + )] + #[IdParameter(type: 'User')] + #[SuccessResponse( + description: 'user_get_image_success_response', + content: new MediaType('image/png'), + )] + #[DefaultResponses([ + HttpResponseCodes::NOT_FOUND, + HttpResponseCodes::FORBIDDEN, + ])] + public function getUserImage( + int $id, + ): StreamedResponse { + return $this->imageUploadService->getImageFromUserAsStreamedResponse($id); + } +} diff --git a/src/User/Service/ImageUploadService.php b/src/User/Service/ImageService.php similarity index 79% rename from src/User/Service/ImageUploadService.php rename to src/User/Service/ImageService.php index 6fd24b78a..befff61c1 100644 --- a/src/User/Service/ImageUploadService.php +++ b/src/User/Service/ImageService.php @@ -22,11 +22,12 @@ use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; use Pimcore\Bundle\StudioBackendBundle\User\Repository\UserRepositoryInterface; use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\HttpFoundation\StreamedResponse; /** * @internal */ -final readonly class ImageUploadService implements ImageUploadServiceInterface +final readonly class ImageService implements ImageServiceInterface { public function __construct( private UserRepositoryInterface $userRepository, @@ -55,4 +56,17 @@ public function uploadUserImage(UploadedFile $file, int $userId): void $user->setImage($file->getPathname()); } + + public function getImageFromUserAsStreamedResponse(int $userId): StreamedResponse + { + $user = $this->userRepository->getUserById($userId); + + $stream = $user->getImage(); + + return new StreamedResponse(function () use ($stream) { + fpassthru($stream); + }, 200, [ + 'Content-Type' => 'image/png', + ]); + } } diff --git a/src/User/Service/ImageUploadServiceInterface.php b/src/User/Service/ImageServiceInterface.php similarity index 79% rename from src/User/Service/ImageUploadServiceInterface.php rename to src/User/Service/ImageServiceInterface.php index 182f39bdb..f356cdd0b 100644 --- a/src/User/Service/ImageUploadServiceInterface.php +++ b/src/User/Service/ImageServiceInterface.php @@ -17,11 +17,14 @@ namespace Pimcore\Bundle\StudioBackendBundle\User\Service; use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\HttpFoundation\StreamedResponse; /** * @internal */ -interface ImageUploadServiceInterface +interface ImageServiceInterface { public function uploadUserImage(UploadedFile $file, int $userId): void; + + public function getImageFromUserAsStreamedResponse(int $userId): StreamedResponse; } diff --git a/tests/Unit/User/Service/ImageUploadServiceTest.php b/tests/Unit/User/Service/ImageServiceTest.php similarity index 76% rename from tests/Unit/User/Service/ImageUploadServiceTest.php rename to tests/Unit/User/Service/ImageServiceTest.php index 512fd94cf..eb36bd592 100644 --- a/tests/Unit/User/Service/ImageUploadServiceTest.php +++ b/tests/Unit/User/Service/ImageServiceTest.php @@ -22,14 +22,14 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ForbiddenException; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; use Pimcore\Bundle\StudioBackendBundle\User\Repository\UserRepositoryInterface; -use Pimcore\Bundle\StudioBackendBundle\User\Service\ImageUploadService; +use Pimcore\Bundle\StudioBackendBundle\User\Service\ImageService; use Pimcore\Model\UserInterface; use Symfony\Component\HttpFoundation\File\UploadedFile; /** * @internal */ -final class ImageUploadServiceTest extends Unit +final class ImageServiceTest extends Unit { public function testNonAdminCanNotEditAdminUser(): void { @@ -51,7 +51,7 @@ public function testNonAdminCanNotEditAdminUser(): void $assetResolver = $this->makeEmpty(AssetResolverInterface::class); - $imageUploadService = new ImageUploadService($userRepositoryMock, $securityServiceMock, $assetResolver); + $imageUploadService = new ImageService($userRepositoryMock, $securityServiceMock, $assetResolver); $this->expectException(ForbiddenException::class); $this->expectExceptionMessage('You are not allowed to upload an image for an admin user'); @@ -85,7 +85,7 @@ public function testWrongFileType(): void 'getFilename' => 'test.pdf', ]); - $imageUploadService = new ImageUploadService($userRepositoryMock, $securityServiceMock, $assetResolver); + $imageUploadService = new ImageService($userRepositoryMock, $securityServiceMock, $assetResolver); $this->expectException(ForbiddenException::class); $this->expectExceptionMessage('Only images are allowed'); @@ -123,8 +123,30 @@ public function testSetImageOfUserIsCalled(): void 'getPathname' => '/tmp/test.png', ]); - $imageUploadService = new ImageUploadService($userRepositoryMock, $securityServiceMock, $assetResolver); + $imageUploadService = new ImageService($userRepositoryMock, $securityServiceMock, $assetResolver); $imageUploadService->uploadUserImage($fileMock, 1); } + + public function testStreamResponseFromGetImage(): void + { + $userMock = $this->makeEmpty(UserInterface::class, [ + 'getImage' => fopen('php://memory', 'r'), + ]); + + $userRepositoryMock = $this->makeEmpty(UserRepositoryInterface::class, [ + 'getUserById' => $userMock, + ]); + + $securityServiceMock = $this->makeEmpty(SecurityServiceInterface::class); + + $assetResolver = $this->makeEmpty(AssetResolverInterface::class); + + $imageUploadService = new ImageService($userRepositoryMock, $securityServiceMock, $assetResolver); + + $response = $imageUploadService->getImageFromUserAsStreamedResponse(1); + + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('image/png', $response->headers->get('Content-Type')); + } } From 5b700ab8f777869b264194dbde10ee27f51ff05b Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Mon, 25 Nov 2024 11:31:10 +0100 Subject: [PATCH 3/6] Add Translation. --- translations/studio_api_docs.en.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/translations/studio_api_docs.en.yaml b/translations/studio_api_docs.en.yaml index 307e92b98..5cc6b1f7a 100644 --- a/translations/studio_api_docs.en.yaml +++ b/translations/studio_api_docs.en.yaml @@ -597,4 +597,6 @@ user_default_key_bindings_description: | Get default key bindings for user management user_default_key_bindings_summary: Get default key bindings user_default_key_bindings_response: List of default key bindings -user_upload_image_summary: Upload user image \ No newline at end of file +user_upload_image_summary: Upload user image +user_get_image_summary: Get user profile image +user_get_image_success_response: User profile image \ No newline at end of file From 23ffb08f72cee63ebc7f0cf51013f89dabb280e1 Mon Sep 17 00:00:00 2001 From: martineiber Date: Mon, 25 Nov 2024 10:32:24 +0000 Subject: [PATCH 4/6] Apply php-cs-fixer changes --- src/User/Controller/UserImageController.php | 1 - tests/Unit/User/Service/ImageServiceTest.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/User/Controller/UserImageController.php b/src/User/Controller/UserImageController.php index d145f7a50..dceec5b35 100644 --- a/src/User/Controller/UserImageController.php +++ b/src/User/Controller/UserImageController.php @@ -31,7 +31,6 @@ use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; diff --git a/tests/Unit/User/Service/ImageServiceTest.php b/tests/Unit/User/Service/ImageServiceTest.php index eb36bd592..085de234c 100644 --- a/tests/Unit/User/Service/ImageServiceTest.php +++ b/tests/Unit/User/Service/ImageServiceTest.php @@ -127,7 +127,7 @@ public function testSetImageOfUserIsCalled(): void $imageUploadService->uploadUserImage($fileMock, 1); } - + public function testStreamResponseFromGetImage(): void { $userMock = $this->makeEmpty(UserInterface::class, [ From 88e1cb24b7e6cb8df48e9a897a07d5e63b92e341 Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Mon, 25 Nov 2024 11:33:13 +0100 Subject: [PATCH 5/6] Update Exception --- src/User/Controller/UserImageController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/User/Controller/UserImageController.php b/src/User/Controller/UserImageController.php index dceec5b35..95639349d 100644 --- a/src/User/Controller/UserImageController.php +++ b/src/User/Controller/UserImageController.php @@ -51,7 +51,7 @@ public function __construct( } /** - * @throws NotFoundException|DatabaseException|ForbiddenException|ParseException + * @throws NotFoundException */ #[Route('/user/image/{id}', name: 'pimcore_studio_api_get_user_image', methods: ['GET'])] #[IsGranted(UserPermissions::USER_MANAGEMENT->value)] @@ -68,7 +68,6 @@ public function __construct( )] #[DefaultResponses([ HttpResponseCodes::NOT_FOUND, - HttpResponseCodes::FORBIDDEN, ])] public function getUserImage( int $id, From adee5550cb9e5a61b4ef68192ad8f1d465ac94b3 Mon Sep 17 00:00:00 2001 From: martineiber Date: Mon, 25 Nov 2024 10:33:45 +0000 Subject: [PATCH 6/6] Apply php-cs-fixer changes --- src/User/Controller/UserImageController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/User/Controller/UserImageController.php b/src/User/Controller/UserImageController.php index 95639349d..d039c4741 100644 --- a/src/User/Controller/UserImageController.php +++ b/src/User/Controller/UserImageController.php @@ -18,10 +18,7 @@ use OpenApi\Attributes\Get; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; -use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException; -use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ForbiddenException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; -use Pimcore\Bundle\StudioBackendBundle\Exception\Api\ParseException; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Path\IdParameter; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\MediaType; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;