diff --git a/composer.json b/composer.json index 48df1c69..b34d5ba1 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "~8.2.0 || ~8.3.0", "nesbot/carbon": "^2.65", "pimcore/static-resolver-bundle": "1.x-dev", - "pimcore/generic-data-index-bundle": "1.x-dev", + "pimcore/generic-data-index-bundle": "2.x-dev", "pimcore/pimcore": "^11.x-dev", "zircote/swagger-php": "^4.8", "ext-zip": "*", diff --git a/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvDataCollectionHandler.php b/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvDataCollectionHandler.php index bc0bf7f2..c910f441 100644 --- a/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvDataCollectionHandler.php +++ b/src/Asset/ExecutionEngine/AutomationAction/Messenger/Handler/CsvDataCollectionHandler.php @@ -19,6 +19,7 @@ use Exception; use Pimcore\Bundle\StaticResolverBundle\Models\User\UserResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Asset\ExecutionEngine\AutomationAction\Messenger\Messages\CsvCollectionMessage; +use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Asset; use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Asset\Util\Constant\Csv; use Pimcore\Bundle\StudioBackendBundle\Element\Service\ElementServiceInterface; @@ -28,8 +29,6 @@ use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Mercure\Service\PublishServiceInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Constant\ElementTypes; -use Pimcore\Model\Asset; -use Pimcore\Model\Element\ElementDescriptor; use Symfony\Component\Messenger\Attribute\AsMessageHandler; /** @@ -61,7 +60,9 @@ public function __invoke(CsvCollectionMessage $message): void if (!$this->shouldBeExecuted($jobRun)) { return; } + $user = $this->userResolver->getById($jobRun->getOwnerId()); + if ($user === null) { $this->abort($this->getAbortData( Config::USER_NOT_FOUND_MESSAGE->value, @@ -72,14 +73,10 @@ public function __invoke(CsvCollectionMessage $message): void } $jobAsset = $this->extractConfigFieldFromJobStepConfig($message, Csv::ASSET_TO_EXPORT->value); - // TODO: Replace getElementById with getAsset with permission check. - // We do not want to load the asset form the database. Permission check should be done in the index. - $asset = $this->getElementById( - new ElementDescriptor($jobAsset['type'], $jobAsset['id']), - $user, - $this->elementService - ); - if (!$asset instanceof Asset || $asset->getType() === ElementTypes::TYPE_FOLDER) { + + $asset = $this->assetService->getAsset($jobAsset['id'], $user); + + if ($asset->getType() === ElementTypes::TYPE_FOLDER) { $this->abort($this->getAbortData( Config::ELEMENT_FOLDER_COLLECTION_NOT_SUPPORTED->value, [ @@ -95,13 +92,11 @@ public function __invoke(CsvCollectionMessage $message): void true ); - $indexAsset = $this->assetService->getAsset($asset->getId()); - try { $assetData = [ $asset->getId() => $this->gridService->getGridValuesForElement( $columnCollection, - $indexAsset, + $asset, ElementTypes::TYPE_ASSET ), ]; diff --git a/src/Asset/Service/AssetService.php b/src/Asset/Service/AssetService.php index e64c2030..75502469 100644 --- a/src/Asset/Service/AssetService.php +++ b/src/Asset/Service/AssetService.php @@ -98,9 +98,9 @@ public function getAssets(ElementParameters $parameters): Collection /** * @throws SearchException|NotFoundException */ - public function getAsset(int $id): Asset|Archive|Audio|Document|AssetFolder|Image|Text|Unknown|Video + public function getAsset(int $id, ?UserInterface $user = null): Asset|Archive|Audio|Document|AssetFolder|Image|Text|Unknown|Video { - $asset = $this->assetSearchService->getAssetById($id); + $asset = $this->assetSearchService->getAssetById($id, $user); $this->eventDispatcher->dispatch( new AssetEvent($asset), diff --git a/src/Asset/Service/AssetServiceInterface.php b/src/Asset/Service/AssetServiceInterface.php index 4eddb19b..09d61817 100644 --- a/src/Asset/Service/AssetServiceInterface.php +++ b/src/Asset/Service/AssetServiceInterface.php @@ -49,7 +49,7 @@ public function getAssets(ElementParameters $parameters): Collection; /** * @throws SearchException|NotFoundException */ - public function getAsset(int $id): Asset|Archive|Audio|Document|AssetFolder|Image|Text|Unknown|Video; + public function getAsset(int $id, ?UserInterface $user = null): Asset|Archive|Audio|Document|AssetFolder|Image|Text|Unknown|Video; /** * @throws SearchException|NotFoundException diff --git a/src/DataIndex/Adapter/AssetSearchAdapter.php b/src/DataIndex/Adapter/AssetSearchAdapter.php index f1bbb00e..0b68f684 100644 --- a/src/DataIndex/Adapter/AssetSearchAdapter.php +++ b/src/DataIndex/Adapter/AssetSearchAdapter.php @@ -30,6 +30,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; +use Pimcore\Model\UserInterface; use function sprintf; final readonly class AssetSearchAdapter implements AssetSearchAdapterInterface @@ -71,10 +72,10 @@ public function searchAssets(QueryInterface $assetQuery): AssetSearchResult /** * @throws SearchException|NotFoundException */ - public function getAssetById(int $id): Asset + public function getAssetById(int $id, ?UserInterface $user = null): Asset { try { - $asset = $this->searchService->byId($id); + $asset = $this->searchService->byId($id, $user); } catch (AssetSearchException) { throw new SearchException(sprintf('Asset with id %s', $id)); } diff --git a/src/DataIndex/Adapter/AssetSearchAdapterInterface.php b/src/DataIndex/Adapter/AssetSearchAdapterInterface.php index 2c42cfe1..309c80aa 100644 --- a/src/DataIndex/Adapter/AssetSearchAdapterInterface.php +++ b/src/DataIndex/Adapter/AssetSearchAdapterInterface.php @@ -23,6 +23,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; +use Pimcore\Model\UserInterface; interface AssetSearchAdapterInterface { @@ -34,7 +35,7 @@ public function searchAssets(QueryInterface $assetQuery): AssetSearchResult; /** * @throws SearchException|NotFoundException */ - public function getAssetById(int $id): Asset; + public function getAssetById(int $id, ?UserInterface $user = null): Asset; /** * @throws SearchException diff --git a/src/DataIndex/AssetSearchService.php b/src/DataIndex/AssetSearchService.php index 7f19d1d3..c5fe06e1 100644 --- a/src/DataIndex/AssetSearchService.php +++ b/src/DataIndex/AssetSearchService.php @@ -32,6 +32,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; +use Pimcore\Model\UserInterface; use function count; final readonly class AssetSearchService implements AssetSearchServiceInterface @@ -53,9 +54,12 @@ public function searchAssets(QueryInterface $assetQuery): AssetSearchResult /** * @throws SearchException|NotFoundException */ - public function getAssetById(int $id): Asset|Archive|Audio|Document|AssetFolder|Image|Text|Unknown|Video + public function getAssetById( + int $id, + ?UserInterface $user = null + ): Asset|Archive|Audio|Document|AssetFolder|Image|Text|Unknown|Video { - return $this->assetSearchAdapter->getAssetById($id); + return $this->assetSearchAdapter->getAssetById($id, $user); } /** diff --git a/src/DataIndex/AssetSearchServiceInterface.php b/src/DataIndex/AssetSearchServiceInterface.php index e26244cb..45704741 100644 --- a/src/DataIndex/AssetSearchServiceInterface.php +++ b/src/DataIndex/AssetSearchServiceInterface.php @@ -30,6 +30,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; +use Pimcore\Model\UserInterface; interface AssetSearchServiceInterface { @@ -41,7 +42,10 @@ public function searchAssets(QueryInterface $assetQuery): AssetSearchResult; /** * @throws SearchException|NotFoundException */ - public function getAssetById(int $id): Asset|Archive|Audio|Document|AssetFolder|Image|Text|Unknown|Video; + public function getAssetById( + int $id, + ?UserInterface $user = null + ): Asset|Archive|Audio|Document|AssetFolder|Image|Text|Unknown|Video; /** * @throws SearchException