-
Notifications
You must be signed in to change notification settings - Fork 5
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
19 changed files
with
1,233 additions
and
1,259 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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Api; | ||
|
||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\State\ProviderInterface; | ||
use App\Api\InputTransformer\InputTransformerInterface; | ||
use Symfony\Component\DependencyInjection\Attribute\AsDecorator; | ||
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; | ||
|
||
#[AsDecorator(decorates: 'api_platform.state_provider.deserialize', priority: 1)] | ||
final class InputTransformerProvider implements ProviderInterface | ||
{ | ||
/** | ||
* @var InputTransformerInterface[] | ||
*/ | ||
private readonly iterable $transformers; | ||
|
||
public function __construct( | ||
private readonly ProviderInterface $decorated, | ||
#[TaggedIterator('api.input_transformer')] | ||
iterable $transformers, | ||
) { | ||
$this->transformers = $transformers; | ||
} | ||
|
||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null | ||
{ | ||
$data = $this->decorated->provide($operation, $uriVariables, $context); | ||
if ($data instanceof Response) { | ||
return $data; | ||
} | ||
|
||
if (!is_object($data)) { | ||
return $data; | ||
} | ||
|
||
$resourceClass = $operation->getClass(); | ||
foreach ($this->transformers as $transformer) { | ||
if ($transformer->supports($resourceClass, $data)) { | ||
$request = $context['request']; | ||
if ($previousData = $request?->attributes->get('data')) { | ||
$context[AbstractNormalizer::OBJECT_TO_POPULATE] = $previousData; | ||
} | ||
|
||
return $transformer->transform($data, $resourceClass, $context); | ||
} | ||
} | ||
|
||
if (null === $operation->getProcessor()) { | ||
throw new \InvalidArgumentException(sprintf('No input transformer found for resource "%s"', $data::class)); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
databox/api/src/Api/Processor/AssetAttributeBatchUpdateProcessor.php
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,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Api\Processor; | ||
|
||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\State\ProcessorInterface; | ||
use App\Api\Model\Input\Attribute\AssetAttributeBatchUpdateInput; | ||
use App\Attribute\BatchAttributeManager; | ||
use App\Entity\Core\Asset; | ||
use App\Security\Voter\AssetVoter; | ||
use App\Util\DoctrineUtil; | ||
use App\Util\SecurityAwareTrait; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
final class AssetAttributeBatchUpdateProcessor implements ProcessorInterface | ||
{ | ||
use SecurityAwareTrait; | ||
|
||
public function __construct( | ||
private readonly BatchAttributeManager $batchAttributeManager, | ||
private readonly EntityManagerInterface $em, | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* @param AssetAttributeBatchUpdateInput $data | ||
*/ | ||
public function process($data, Operation $operation, array $uriVariables = [], array $context = []): Asset | ||
{ | ||
$asset = DoctrineUtil::findStrict($this->em, Asset::class, $uriVariables['id']); | ||
$this->denyAccessUnlessGranted(AssetVoter::EDIT_ATTRIBUTES, $asset); | ||
|
||
$this->batchAttributeManager->validate([$asset->getId()], $data); | ||
|
||
$this->batchAttributeManager->handleBatch( | ||
$asset->getWorkspaceId(), | ||
[$asset->getId()], | ||
$data, | ||
$this->getStrictUser(), | ||
true, | ||
); | ||
|
||
return $asset; | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
databox/api/src/Controller/Core/AssetAttributeBatchUpdateAction.php
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
databox/api/src/DependencyInjection/Compiler/FixApiPlatformPass.php
This file was deleted.
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
Oops, something went wrong.