Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.x' into 156-dependencies
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
#	qodana.sarif.json
  • Loading branch information
mcop1 committed May 14, 2024
2 parents d49098c + ce66ae4 commit b489967
Show file tree
Hide file tree
Showing 28 changed files with 2,951 additions and 751 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"minimum-stability": "dev",
"require": {
"php": "~8.2",
"pimcore/static-resolver-bundle": "^1.5",
"pimcore/static-resolver-bundle": "1.x-dev",
"pimcore/generic-data-index-bundle": "1.x-dev",
"pimcore/pimcore": "^11.0",
"zircote/swagger-php": "^4.8"
Expand Down
6 changes: 5 additions & 1 deletion config/assets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ services:
Pimcore\Bundle\StudioBackendBundle\Asset\Controller\:
resource: '../src/Asset/Controller'
public: true
tags: [ 'controller.service_arguments' ]
tags: [ 'controller.service_arguments' ]

# Hydrators
Pimcore\Bundle\StudioBackendBundle\Asset\Hydrator\CustomSettingsHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Asset\Hydrator\CustomSettingsHydrator
4 changes: 4 additions & 0 deletions config/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ services:
tags:
- { name: security.voter }

Pimcore\Bundle\StudioBackendBundle\Security\Voter\UserPermissionVoter:
tags:
- { name: security.voter }

Pimcore\Bundle\StudioBackendBundle\Security\Voter\PublicAuthorizationVoter:
arguments: [ '@request_stack' ]
tags:
Expand Down
3,104 changes: 2,377 additions & 727 deletions qodana.sarif.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Asset/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public function __construct(
*/
#[Route('/assets', name: 'pimcore_studio_api_assets', methods: ['GET'])]
//#[IsGranted('STUDIO_API')]
#[GET(
//#[IsGranted(UserPermissions::ASSETS->value)]
#[Get(
path: self::API_PATH . '/assets',
operationId: 'getAssets',
description: 'Get paginated assets',
Expand Down
91 changes: 91 additions & 0 deletions src/Asset/Controller/CustomSettingsController.php
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())
);
}
}
3 changes: 2 additions & 1 deletion src/Asset/Controller/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public function __construct(

#[Route('/assets/{id}', name: 'pimcore_studio_api_get_asset', methods: ['GET'])]
//#[IsGranted('STUDIO_API')]
#[GET(
//#[IsGranted(UserPermissions::ASSETS->value)]
#[Get(
path: self::API_PATH . '/assets/{id}',
operationId: 'getAssetById',
description: 'Get assets by id by path parameter',
Expand Down
70 changes: 70 additions & 0 deletions src/Asset/Hydrator/CustomSettingsHydrator.php
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)
);
}
}
27 changes: 27 additions & 0 deletions src/Asset/Hydrator/CustomSettingsHydratorInterface.php
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;
}
60 changes: 60 additions & 0 deletions src/Asset/Schema/CustomSettings.php
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;
}
}
58 changes: 58 additions & 0 deletions src/Asset/Schema/CustomSettings/FixedCustomSettings.php
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;
}
}
2 changes: 1 addition & 1 deletion src/Asset/Schema/Type/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
private readonly ?int $pageCount,
#[Property(
description: 'Path to image thumbnail',
type: 'integer',
type: 'string',
example: '/path/to/document/imagethumbnail.jpg'
)]
private readonly ?string $imageThumbnailPath,
Expand Down
6 changes: 3 additions & 3 deletions src/Asset/Schema/Type/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
#[Property(description: 'is animated', type: 'boolean', example: false)]
private readonly bool $isAnimated,
#[Property(description: 'path to thumbnail', type: 'string', example: '/path/to/element/hulk-smash.jpg')]
private readonly string $thumbnailPath,
private readonly string $imageThumbnailPath,
string $iconName,
bool $hasChildren,
string $type,
Expand Down Expand Up @@ -80,9 +80,9 @@ public function __construct(
);
}

public function getThumbnailPath(): string
public function getImageThumbnailPath(): string
{
return $this->thumbnailPath;
return $this->imageThumbnailPath;
}

public function getFormat(): string
Expand Down
Loading

0 comments on commit b489967

Please sign in to comment.