-
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.
- Loading branch information
Showing
6 changed files
with
239 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?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\StudioApiBundle\Attributes\Parameters\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] | ||
final class ElementTypeParameter extends QueryParameter | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
name: 'type', | ||
description: 'Element type.', | ||
in: 'query', | ||
required: true, | ||
schema: new Schema(type: 'string', enum: [ | ||
FilterServiceInterface::TYPE_ASSET, | ||
FilterServiceInterface::TYPE_DATA_OBJECT, | ||
FilterServiceInterface::TYPE_DOCUMENT, | ||
], example: 'asset'), | ||
); | ||
} | ||
} |
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,36 @@ | ||
<?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\StudioApiBundle\Attributes\Parameters\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] | ||
final class IdParameter extends QueryParameter | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct( | ||
name: 'id', | ||
description: 'Element id.', | ||
in: 'query', | ||
required: true, | ||
schema: new Schema(type: 'integer', example: 1), | ||
); | ||
} | ||
} |
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,110 @@ | ||
<?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\StudioApiBundle\Controller\Api\Versions; | ||
|
||
use Exception; | ||
use OpenApi\Attributes\Get; | ||
use OpenApi\Attributes\JsonContent; | ||
use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Query\ElementTypeParameter; | ||
use Pimcore\Bundle\StudioApiBundle\Attributes\Parameters\Query\IdParameter; | ||
use Pimcore\Bundle\StudioApiBundle\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioApiBundle\Attributes\Response\UnauthorizedResponse; | ||
use Pimcore\Bundle\StudioApiBundle\Config\Tags; | ||
use Pimcore\Bundle\StudioApiBundle\Controller\Api\AbstractApiController; | ||
use Pimcore\Bundle\StudioApiBundle\Controller\Trait\PaginatedResponseTrait; | ||
use Pimcore\Bundle\StudioApiBundle\Request\Query\Version as VersionQuery; | ||
use Pimcore\Bundle\StudioApiBundle\Service\Filter\FilterServiceInterface; | ||
use Pimcore\Model\Element\Service; | ||
use Pimcore\Model\Exception\NotFoundException; | ||
use Pimcore\Model\Version\Listing; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpKernel\Attribute\MapQueryString; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
final class CollectionController extends AbstractApiController | ||
{ | ||
use PaginatedResponseTrait; | ||
|
||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly FilterServiceInterface $filterService | ||
Check failure on line 45 in src/Controller/Api/Versions/CollectionController.php GitHub Actions / Static Analysis with PHPStan (8.2, highest, false)
Check failure on line 45 in src/Controller/Api/Versions/CollectionController.php GitHub Actions / Static Analysis with PHPStan (8.2, highest, 11.x-dev as 11.99.9, true)
|
||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
#[Route('/versions', name: 'pimcore_studio_api_element_versions', methods: ['GET'])] | ||
//#[IsGranted('STUDIO_API')] | ||
#[GET(path: self::API_PATH | ||
.'/versions', description: 'Get versions of an element', summary: 'Get all versions of an specific element (Asset, DataObject, Document) by its ID.', security: self::SECURITY_SCHEME, tags: [Tags::Versions->name],)] | ||
#[IdParameter] | ||
#[ElementTypeParameter] | ||
#[SuccessResponse(description: 'Paginated versions with total count as header param', content: new JsonContent( | ||
ref: Version::class | ||
Check failure on line 60 in src/Controller/Api/Versions/CollectionController.php GitHub Actions / Static Analysis with PHPStan (8.2, highest, false)
|
||
))] | ||
#[UnauthorizedResponse] | ||
public function getVersions( | ||
#[MapQueryString] VersionQuery $versionQuery | ||
): JsonResponse { | ||
$type = $versionQuery->getType(); | ||
$id = $versionQuery->getId(); | ||
$element = Service::getElementById($type, $id); | ||
|
||
if (!$element) { | ||
throw new NotFoundException('Element not found'); | ||
} | ||
|
||
if (!$element->isAllowed('versions')) { | ||
throw $this->createAccessDeniedException('You are not allowed to view versions of this element'); | ||
} | ||
|
||
$schedule = $element->getScheduledTasks(); | ||
$schedules = []; | ||
foreach ($schedule as $task) { | ||
if ($task->getActive()) { | ||
$schedules[$task->getVersion()] = $task->getDate(); | ||
} | ||
} | ||
|
||
//only load auto-save versions from current user | ||
$list = new Listing(); | ||
$list->setLoadAutoSave(true); | ||
|
||
// TODO: Implement the filter of the user as it was on admin-ui-classic-bundle | ||
$list->setCondition('cid = ? AND ctype = ? AND (autoSave=0 OR (autoSave=1)) ', [ | ||
$element->getId(), | ||
Service::getElementType($element), | ||
])->setOrderKey('date')->setOrder('ASC'); | ||
|
||
$versions = $list->load(); | ||
|
||
$versions = Service::getSafeVersionInfo($versions); | ||
$versions = array_reverse($versions); //reverse array to sort by ID DESC | ||
foreach ($versions as &$version) { | ||
$version['scheduled'] = null; | ||
if (array_key_exists($version['id'], $schedules)) { | ||
$version['scheduled'] = $schedules[$version['id']]; | ||
} | ||
} | ||
|
||
// TODO: This was just copied from other endpoint without customizing it for this endpoint. | ||
return $this->getPaginatedCollection($this->serializer, ['versions' => $versions]); | ||
} | ||
} |
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,49 @@ | ||
<?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\StudioApiBundle\Request\Query; | ||
|
||
use OpenApi\Attributes\Property; | ||
use OpenApi\Attributes\Schema; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Schema( | ||
title: 'Version', | ||
description: 'Version request for specific element (dataObject, asset, document).', | ||
type: 'object' | ||
)] | ||
final readonly class Version | ||
{ | ||
public function __construct( | ||
#[Property(description: 'Id', type: 'integer', example: 'Element ID.')] | ||
private int $id, | ||
#[Property(description: 'Type', type: 'string', example: 'Element type (asset, dataObject, document).')] | ||
private string $type | ||
) { | ||
} | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
} |