-
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.
Merge remote-tracking branch 'origin/1.x' into 156-dependencies
# Conflicts: # composer.json # qodana.sarif.json
- Loading branch information
Showing
28 changed files
with
2,951 additions
and
751 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
Large diffs are not rendered by default.
Oops, something went wrong.
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; | ||
|
||
use OpenApi\Attributes\Get; | ||
use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Hydrator\CustomSettingsHydratorInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\CustomSettingsJson; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\MethodNotAllowedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\NotFoundResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnauthorizedResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnsupportedMediaTypeResponse; | ||
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\ElementPermissions; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\ElementTypes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; | ||
use Pimcore\Model\Asset; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CustomSettingsController extends AbstractApiController | ||
{ | ||
use ElementProviderTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly CustomSettingsHydratorInterface $hydrator, | ||
private readonly SecurityServiceInterface $securityService, | ||
private readonly ServiceResolverInterface $serviceResolver, | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
#[Route('/assets/{id}/custom-settings', name: 'pimcore_studio_api_get_asset_custom_settings', methods: ['GET'])] | ||
//#[IsGranted('STUDIO_API')] | ||
#[GET( | ||
path: self::API_PATH . '/assets/{id}/custom-settings', | ||
operationId: 'getAssetCustomSettingsById', | ||
description: 'Get custom settings of an asset by its id by path parameter', | ||
summary: 'Get custom settings of an asset by id', | ||
security: self::SECURITY_SCHEME, | ||
tags: [Tags::Assets->name] | ||
)] | ||
#[IdParameter(type: 'asset')] | ||
#[SuccessResponse( | ||
description: 'Array of custom settings', | ||
content: new CustomSettingsJson() | ||
)] | ||
#[UnauthorizedResponse] | ||
#[NotFoundResponse] | ||
#[MethodNotAllowedResponse] | ||
#[UnsupportedMediaTypeResponse] | ||
#[UnprocessableContentResponse] | ||
public function getAssetCustomSettingsById(int $id): JsonResponse | ||
{ | ||
/** @var Asset $asset */ | ||
$asset = $this->getElement($this->serviceResolver, ElementTypes::TYPE_ASSET, $id); | ||
$this->securityService->hasElementPermission( | ||
$asset, | ||
$this->securityService->getCurrentUser(), | ||
ElementPermissions::VIEW_PERMISSION | ||
); | ||
|
||
return $this->jsonResponse( | ||
$this->hydrator->hydrate($asset->getCustomSettings()) | ||
); | ||
} | ||
} |
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,70 @@ | ||
<?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\Hydrator; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomSettings; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomSettings\FixedCustomSettings; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class CustomSettingsHydrator implements CustomSettingsHydratorInterface | ||
{ | ||
private const METADATA_KEY = 'embeddedMetaData'; | ||
|
||
private const METADATA_EXTRACTED_KEY = 'embeddedMetaDataExtracted'; | ||
|
||
private const FIXED_CUSTOM_SETTINGS_KEYS = [ | ||
self::METADATA_KEY, | ||
self::METADATA_EXTRACTED_KEY, | ||
]; | ||
|
||
public function hydrate(array $customSettings): CustomSettings | ||
{ | ||
if (empty($customSettings)) { | ||
return new CustomSettings(new FixedCustomSettings()); | ||
} | ||
|
||
$fixedCustomSettings = $this->getFixedCustomSettings($customSettings); | ||
$dynamicCustomSettings = $this->getDynamicCustomSettings($customSettings); | ||
|
||
return new CustomSettings( | ||
fixedCustomSettings: $fixedCustomSettings, | ||
dynamicCustomSettings: $dynamicCustomSettings | ||
); | ||
} | ||
|
||
private function getFixedCustomSettings( | ||
array $customSettings | ||
): FixedCustomSettings { | ||
$embeddedMetadata = $customSettings[self::METADATA_KEY] ?? []; | ||
$extracted = $customSettings[self::METADATA_EXTRACTED_KEY] ?? false; | ||
|
||
return new FixedCustomSettings( | ||
embeddedMetaData: $embeddedMetadata, | ||
embeddedMetaDataExtracted: $extracted | ||
); | ||
} | ||
|
||
private function getDynamicCustomSettings(array $customSettings): array | ||
{ | ||
return array_diff_key( | ||
$customSettings, | ||
array_flip(self::FIXED_CUSTOM_SETTINGS_KEYS) | ||
); | ||
} | ||
} |
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,27 @@ | ||
<?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\Hydrator; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomSettings; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface CustomSettingsHydratorInterface | ||
{ | ||
public function hydrate(array $customSettings): CustomSettings; | ||
} |
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,60 @@ | ||
<?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\Schema; | ||
|
||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\Property; | ||
use OpenApi\Attributes\Schema; | ||
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\CustomSettings\FixedCustomSettings; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Schema( | ||
title: 'CustomSettings', | ||
type: 'object' | ||
)] | ||
final readonly class CustomSettings | ||
{ | ||
public function __construct( | ||
#[Property( | ||
description: 'fixed custom settings', | ||
type: FixedCustomSettings::class, | ||
example: '{ embeddedMetadata: { FileSize: 360 KiB }, checksum: b3685e8348e7ac4d30d0268f7e58902a }') | ||
] | ||
private ?FixedCustomSettings $fixedCustomSettings = null, | ||
#[Property( | ||
description: 'dynamic custom settings - can be any key-value pair', | ||
type: 'array', | ||
items: new Items(), | ||
example: '{ imageWidth: 1280, imageHeight: 720 }') | ||
] | ||
private array $dynamicCustomSettings = [], | ||
) { | ||
|
||
} | ||
|
||
public function getFixedCustomSettings(): ?FixedCustomSettings | ||
{ | ||
return $this->fixedCustomSettings; | ||
} | ||
|
||
public function getDynamicCustomSettings(): array | ||
{ | ||
return $this->dynamicCustomSettings; | ||
} | ||
} |
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,58 @@ | ||
<?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\Schema\CustomSettings; | ||
|
||
use OpenApi\Attributes\Items; | ||
use OpenApi\Attributes\Property; | ||
use OpenApi\Attributes\Schema; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Schema( | ||
title: 'FixedCustomSettings', | ||
type: 'object' | ||
)] | ||
final readonly class FixedCustomSettings | ||
{ | ||
public function __construct( | ||
#[Property( | ||
description: 'embedded meta data of the asset - array of any key-value pairs', | ||
type: 'array', | ||
items: new Items(), | ||
example: '{ FileSize: "265 KiB", MIMEType: "image/jpeg" }' | ||
)] | ||
private array $embeddedMetaData = [], | ||
#[Property( | ||
description: 'flag to indicate if the embedded meta data has been extracted from the asset', | ||
type: 'bool', | ||
example: true | ||
)] | ||
private bool $embeddedMetaDataExtracted = false, | ||
) { | ||
} | ||
|
||
public function getEmbeddedMetaData(): array | ||
{ | ||
return $this->embeddedMetaData; | ||
} | ||
|
||
public function isEmbeddedMetaDataExtracted(): bool | ||
{ | ||
return $this->embeddedMetaDataExtracted; | ||
} | ||
} |
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
Oops, something went wrong.