-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add endpoint to check if asset already exists * Apply php-cs-fixer changes * fix: STAN * fix response codes --------- Co-authored-by: lukmzig <[email protected]>
- Loading branch information
Showing
12 changed files
with
215 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Asset\Controller\Upload; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attributes\Parameters\Query\NameParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Service\UploadServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\AccessDeniedException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\BoolJson; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Core\Exception\UserNotFoundException; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InfoController extends AbstractApiController | ||
{ | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly UploadServiceInterface $uploadService, | ||
private readonly SecurityServiceInterface $securityService | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws AccessDeniedException | ||
* @throws NotFoundException | ||
* @throws UserNotFoundException | ||
*/ | ||
#[Route('/assets/exists/{parentId}', name: 'pimcore_studio_api_get_asset', methods: ['GET'])] | ||
#[IsGranted(UserPermissions::ASSETS->value)] | ||
#[Get( | ||
path: self::API_PATH . '/assets/exists/{parentId}', | ||
operationId: 'getAssetExists', | ||
description: 'Get information if asset already exists by parentId path parameter and fileName query string', | ||
summary: 'Get asset info by parentId and fileName', | ||
tags: [Tags::Assets->name] | ||
)] | ||
#[IdParameter(type: ElementTypes::TYPE_ASSET, name: 'parentId')] | ||
#[NameParameter(name: 'fileName', description: 'Name of the file to upload', example: 'file.jpg')] | ||
#[SuccessResponse( | ||
description: 'Returns true if asset with the same name and in the same path already exists, false otherwise', | ||
content: new BoolJson(name: 'exists', description: 'True if asset exists, false otherwise') | ||
)] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::UNAUTHORIZED, | ||
HttpResponseCodes::NOT_FOUND, | ||
])] | ||
public function getAssetExists(int $parentId, #[MapQueryParameter] string $fileName): JsonResponse | ||
{ | ||
|
||
return $this->jsonResponse( | ||
[ | ||
'exists' => $this->uploadService->fileExists( | ||
$parentId, | ||
$fileName, | ||
$this->securityService->getCurrentUser() | ||
), | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Asset/OpenApi/Attributes/Parameters/Query/NameParameter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Asset\OpenApi\Attributes\Parameters\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\Thumbnails; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class NameParameter extends QueryParameter | ||
{ | ||
public function __construct( | ||
string $name = 'thumbnailName', | ||
string $description = 'Find asset by matching thumbnail name.', | ||
string $example = Thumbnails::DEFAULT_THUMBNAIL_ID->value, | ||
) { | ||
parent::__construct( | ||
name: $name, | ||
description: $description, | ||
in: 'query', | ||
required: true, | ||
schema: new Schema( | ||
type: 'string', | ||
example: $example | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content; | ||
|
||
use OpenApi\Attributes\JsonContent; | ||
use OpenApi\Attributes\Property; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class BoolJson extends JsonContent | ||
{ | ||
public function __construct(string $name = '', string $description = '') | ||
{ | ||
parent::__construct( | ||
required: [$name], | ||
properties: [ | ||
new Property( | ||
$name, | ||
title: $name, | ||
description: $description, | ||
type: 'boolean', | ||
example: true | ||
), | ||
], | ||
type: 'object', | ||
); | ||
} | ||
} |