Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Versions] Add events to versions and make them more consistent #65

Merged
merged 6 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions config/versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ services:
public: true
tags: [ 'controller.service_arguments' ]

Pimcore\Bundle\StudioBackendBundle\Version\RepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Version\Repository
Pimcore\Bundle\StudioBackendBundle\Version\Repository\VersionRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Version\Repository\VersionRepository

Pimcore\Bundle\StudioBackendBundle\Version\Hydrator\VersionHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Version\Hydrator\VersionHydrator
Expand All @@ -38,15 +38,15 @@ services:
class: Pimcore\Bundle\StudioBackendBundle\Version\Publisher\DocumentVersionPublisher

# Services
Pimcore\Bundle\StudioBackendBundle\Version\Hydrator\VersionHydratorServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Version\Hydrator\VersionHydratorService
Pimcore\Bundle\StudioBackendBundle\Version\Service\VersionServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Version\Service\VersionService
arguments:
$versionHydratorLocator: '@listing.version_hydrator.service_locator'
$versionPublisherLocator: '@version.element_publisher.service_locator'

Pimcore\Bundle\StudioBackendBundle\Version\Publisher\VersionPublisherServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Version\Publisher\VersionPublisherService
Pimcore\Bundle\StudioBackendBundle\Version\Service\VersionDetailServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Version\Service\VersionDetailService
arguments:
$versionPublisherLocator: '@version.element_publisher.service_locator'
$versionHydratorLocator: '@listing.version_hydrator.service_locator'

#Service Locator
listing.version_hydrator.service_locator:
Expand Down
2 changes: 1 addition & 1 deletion src/Response/Schemas.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Video;
use Pimcore\Bundle\StudioBackendBundle\Response\Schema\DevError;
use Pimcore\Bundle\StudioBackendBundle\Response\Schema\Error;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\AssetType\ImageVersion;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\AssetVersion;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\DataObjectVersion;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\DocumentVersion;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\ImageVersion;

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content;
namespace Pimcore\Bundle\StudioBackendBundle\Version\Attributes\Response\Content;

use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Property;
namespace Pimcore\Bundle\StudioBackendBundle\Version\Attributes\Response\Property;

use OpenApi\Attributes\Items;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\Version;

/**
Expand All @@ -32,11 +31,7 @@ public function __construct()
'items',
title: 'items',
type: 'array',
items: new Items(
anyOf: [
new Schema(ref: Version::class),
]
)
items: new Items(ref: Version::class)
);
}
}
4 changes: 2 additions & 2 deletions src/Version/Controller/CleanupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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\Version\RepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Version\Repository\VersionRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Version\Request\VersionCleanupParameters;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
Expand All @@ -42,7 +42,7 @@
final class CleanupController extends AbstractApiController
{
public function __construct(
private readonly RepositoryInterface $repository,
private readonly VersionRepositoryInterface $repository,
SerializerInterface $serializer,
) {
parent::__construct($serializer);
Expand Down
12 changes: 6 additions & 6 deletions src/Version/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
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\Property\VersionCollection;
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\Traits\PaginatedResponseTrait;
use Pimcore\Bundle\StudioBackendBundle\Version\Hydrator\VersionHydratorServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Version\Attributes\Response\Property\VersionCollection;
use Pimcore\Bundle\StudioBackendBundle\Version\Request\VersionParameters;
use Pimcore\Bundle\StudioBackendBundle\Version\Service\VersionServiceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
Expand All @@ -50,7 +50,7 @@ final class CollectionController extends AbstractApiController
public function __construct(
SerializerInterface $serializer,
private readonly SecurityServiceInterface $securityService,
private readonly VersionHydratorServiceInterface $hydratorService,
private readonly VersionServiceInterface $hydratorService,
) {
parent::__construct($serializer);
}
Expand Down Expand Up @@ -80,15 +80,15 @@ public function __construct(
#[UnprocessableContentResponse]
public function getVersions(#[MapQueryString] VersionParameters $parameters): JsonResponse
{
$result = $this->hydratorService->getHydratedVersions(
$collection = $this->hydratorService->getVersions(
$parameters,
$this->securityService->getCurrentUser()
);

return $this->getPaginatedCollection(
$this->serializer,
$result->getItems(),
$result->getTotalItems(),
$collection->getItems(),
$collection->getTotalItems(),
);
}
}
7 changes: 5 additions & 2 deletions src/Version/Controller/DeleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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\Version\RepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Version\Repository\VersionRepositoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;
Expand All @@ -42,7 +42,7 @@ final class DeleteController extends AbstractApiController
public function __construct(
SerializerInterface $serializer,
private readonly SecurityServiceInterface $securityService,
private readonly RepositoryInterface $repository
private readonly VersionRepositoryInterface $repository
) {
parent::__construct($serializer);
}
Expand Down Expand Up @@ -70,12 +70,15 @@ public function __construct(
public function deleteVersion(int $id): JsonResponse
{
$user = $this->securityService->getCurrentUser();

$version = $this->repository->getVersionById($id);

$this->securityService->hasElementPermission(
$version->getData(),
$user,
ElementPermissions::VERSIONS_PERMISSION
);

$version->delete();

return $this->jsonResponse(['id' => $id]);
Expand Down
8 changes: 4 additions & 4 deletions src/Version/Controller/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\OneOfVersionJson;
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;
Expand All @@ -28,7 +27,8 @@
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\Version\Hydrator\VersionHydratorServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Version\Attributes\Response\Content\OneOfVersionJson;
use Pimcore\Bundle\StudioBackendBundle\Version\Service\VersionDetailServiceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;
Expand All @@ -41,7 +41,7 @@ final class GetController extends AbstractApiController
public function __construct(
SerializerInterface $serializer,
private readonly SecurityServiceInterface $securityService,
private readonly VersionHydratorServiceInterface $hydratorService,
private readonly VersionDetailServiceInterface $versionDetailService,
) {
parent::__construct($serializer);
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public function __construct(
public function getVersions(int $id): JsonResponse
{
return $this->jsonResponse(
$this->hydratorService->getHydratedVersionData(
$this->versionDetailService->getVersionData(
$id,
$this->securityService->getCurrentUser()
)
Expand Down
6 changes: 3 additions & 3 deletions src/Version/Controller/PublishController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
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\Version\Publisher\VersionPublisherServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Version\Service\VersionServiceInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;
Expand All @@ -41,7 +41,7 @@ final class PublishController extends AbstractApiController
public function __construct(
SerializerInterface $serializer,
private readonly SecurityServiceInterface $securityService,
private readonly VersionPublisherServiceInterface $publisher
private readonly VersionServiceInterface $versionService
) {
parent::__construct($serializer);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public function publishVersion(int $id): JsonResponse
$user = $this->securityService->getCurrentUser();

return $this->jsonResponse([
'id' => $this->publisher->publishVersion($id, $user),
'id' => $this->versionService->publishVersion($id, $user),
]);
}
}
40 changes: 40 additions & 0 deletions src/Version/Event/AssetVersionEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\Version\Event;

use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\AssetVersion;

final class AssetVersionEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.asset_version';

public function __construct(
private readonly AssetVersion $version
)
{
parent::__construct($version);
}

/**
* Use this to get additional infos out of the response object
*/
public function getVersion(): AssetVersion
{
return $this->version;
}
}
40 changes: 40 additions & 0 deletions src/Version/Event/DataObjectVersionEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\Version\Event;

use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\DataObjectVersion;

final class DataObjectVersionEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.data_object_version';

public function __construct(
private readonly DataObjectVersion $version
)
{
parent::__construct($version);
}

/**
* Use this to get additional infos out of the response object
*/
public function getVersion(): DataObjectVersion
{
return $this->version;
}
}
40 changes: 40 additions & 0 deletions src/Version/Event/DocumentVersionEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\Version\Event;

use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\Version\Schema\DocumentVersion;

final class DocumentVersionEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.document_version';

public function __construct(
private readonly DocumentVersion $version
)
{
parent::__construct($version);
}

/**
* Use this to get additional infos out of the response object
*/
public function getVersion(): DocumentVersion
{
return $this->version;
}
}
Loading
Loading