diff --git a/databox/api/migrations/Version20230920160828.php b/databox/api/migrations/Version20230920160828.php index 5405ed920..e104c5191 100644 --- a/databox/api/migrations/Version20230920160828.php +++ b/databox/api/migrations/Version20230920160828.php @@ -4,7 +4,6 @@ namespace DoctrineMigrations; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; @@ -31,8 +30,7 @@ public function up(Schema $schema): void foreach ([ ['attribute_definition', 'fallback'], ['file', 'alternate_urls'], - ] as $t) - { + ] as $t) { [$table, $column] = $t; $rows = $connection->fetchAllAssociative(sprintf('SELECT "id", "%s" FROM "%s"', $column, $table)); diff --git a/databox/api/src/Api/InputTransformer/MoveAssetInputTransformer.php b/databox/api/src/Api/InputTransformer/MoveAssetInputTransformer.php new file mode 100644 index 000000000..621ab9fbe --- /dev/null +++ b/databox/api/src/Api/InputTransformer/MoveAssetInputTransformer.php @@ -0,0 +1,23 @@ +denyAccessUnlessGranted(AbstractVoter::EDIT, $data); + $dest = $uriVariables['dest']; + $isRoot = 'root' === $dest; + + if ($isRoot) { + $destination = null; + } else { + $destination = $this->em->find(Collection::class, $dest); + if (!$destination instanceof Collection) { + throw new NotFoundHttpException(sprintf('Collection destination "%s" not found', $dest)); + } + $this->denyAccessUnlessGranted(AbstractVoter::EDIT, $destination); + } + + if ($destination === $data) { + throw new \InvalidArgumentException('Cannot reference parent to itself!'); + } + + $data->setParent($destination); + + $this->em->persist($data); + $this->em->flush(); + + return new Response('', 204); + } +} diff --git a/databox/api/src/Controller/Core/MoveCollectionAction.php b/databox/api/src/Controller/Core/MoveCollectionAction.php deleted file mode 100644 index d11236c52..000000000 --- a/databox/api/src/Controller/Core/MoveCollectionAction.php +++ /dev/null @@ -1,40 +0,0 @@ -denyAccessUnlessGranted(AbstractVoter::EDIT, $data); - - $isRoot = 'root' === $dest; - - if ($isRoot) { - $destination = null; - } else { - $destination = $this->em->find(Collection::class, $dest); - if (!$destination instanceof Collection) { - throw new NotFoundHttpException(sprintf('Collection destination "%s" not found', $dest)); - } - $this->denyAccessUnlessGranted(AbstractVoter::EDIT, $destination); - } - - $data->setParent($destination); - - return $data; - } -} diff --git a/databox/api/src/Elasticsearch/AssetDataTemplateSearch.php b/databox/api/src/Elasticsearch/AssetDataTemplateSearch.php index 03792d5b0..b9fa3664f 100644 --- a/databox/api/src/Elasticsearch/AssetDataTemplateSearch.php +++ b/databox/api/src/Elasticsearch/AssetDataTemplateSearch.php @@ -14,7 +14,6 @@ use FOS\ElasticaBundle\Paginator\FantaPaginatorAdapter; use Pagerfanta\Pagerfanta; use Symfony\Bundle\SecurityBundle\Security; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; final readonly class AssetDataTemplateSearch @@ -103,7 +102,7 @@ public function search( protected function createACLBoolQuery(array $filters, ?string $userId, array $groupIds, ?Collection $collection): ?Query\BoolQuery { - $workspaceId = $filters['workspace'] ?? ($collection?->getWorkspaceId()) ?? null; + $workspaceId = $filters['workspace'] ?? $collection?->getWorkspaceId() ?? null; if (empty($workspaceId)) { throw new BadRequestHttpException('"workspace" filter is mandatory'); diff --git a/databox/api/src/Elasticsearch/CollectionSearch.php b/databox/api/src/Elasticsearch/CollectionSearch.php index 485795eff..23eaa90a0 100644 --- a/databox/api/src/Elasticsearch/CollectionSearch.php +++ b/databox/api/src/Elasticsearch/CollectionSearch.php @@ -5,7 +5,6 @@ namespace App\Elasticsearch; use App\Entity\Core\Collection; -use App\Entity\Core\Workspace; use Elastica\Aggregation; use Elastica\Query; use FOS\ElasticaBundle\Finder\PaginatedFinderInterface; diff --git a/databox/api/src/Elasticsearch/Mapping/ElasticsearchClient.php b/databox/api/src/Elasticsearch/Mapping/ElasticsearchClient.php index e7dc4c13c..8df3d7935 100644 --- a/databox/api/src/Elasticsearch/Mapping/ElasticsearchClient.php +++ b/databox/api/src/Elasticsearch/Mapping/ElasticsearchClient.php @@ -12,8 +12,7 @@ public function __construct( private Client $client, private bool $useAlias, - ) - { + ) { } public function updateMapping(string $indexName, array $mapping): void diff --git a/databox/api/src/Entity/AbstractUuidEntity.php b/databox/api/src/Entity/AbstractUuidEntity.php index ace1bf17b..08a28bd6b 100644 --- a/databox/api/src/Entity/AbstractUuidEntity.php +++ b/databox/api/src/Entity/AbstractUuidEntity.php @@ -5,7 +5,6 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiProperty; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Ramsey\Uuid\Doctrine\UuidType; use Ramsey\Uuid\Uuid; diff --git a/databox/api/src/Entity/Basket/Basket.php b/databox/api/src/Entity/Basket/Basket.php index 1978f88ab..1071476fd 100644 --- a/databox/api/src/Entity/Basket/Basket.php +++ b/databox/api/src/Entity/Basket/Basket.php @@ -6,7 +6,6 @@ use App\Entity\AbstractUuidEntity; use App\Entity\Core\Collection; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] diff --git a/databox/api/src/Entity/Core/AssetRendition.php b/databox/api/src/Entity/Core/AssetRendition.php index 4cfe6ca9d..f48c17e3b 100644 --- a/databox/api/src/Entity/Core/AssetRendition.php +++ b/databox/api/src/Entity/Core/AssetRendition.php @@ -18,7 +18,6 @@ use App\Entity\Traits\CreatedAtTrait; use App\Entity\Traits\UpdatedAtTrait; use App\Repository\Core\AssetRenditionRepository; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation\Groups; diff --git a/databox/api/src/Entity/Core/Collection.php b/databox/api/src/Entity/Core/Collection.php index a955f82c0..6f31ceaff 100644 --- a/databox/api/src/Entity/Core/Collection.php +++ b/databox/api/src/Entity/Core/Collection.php @@ -9,13 +9,14 @@ use ApiPlatform\Metadata\Delete; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Patch; use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Put; use App\Api\Model\Input\CollectionInput; use App\Api\Model\Output\CollectionOutput; +use App\Api\Processor\MoveCollectionProcessor; use App\Api\Provider\CollectionProvider; -use App\Controller\Core\MoveCollectionAction; use App\Doctrine\Listener\SoftDeleteableInterface; use App\Entity\AbstractUuidEntity; use App\Entity\ESIndexableInterface; @@ -49,7 +50,10 @@ new Patch(security: 'is_granted("EDIT", object)'), new Put( uriTemplate: '/collections/{id}/move/{dest}', - controller: MoveCollectionAction::class, + uriVariables: [ + 'dest' => new Link(fromClass: Collection::class, identifiers: ['id'], expandedValue: '{dest}'), + 'id' => new Link(fromClass: Collection::class, identifiers: ['id']), + ], openapiContext: [ 'parameters' => [ [ @@ -62,7 +66,8 @@ ], security: 'is_granted("EDIT", object)', deserialize: false, - name: 'put_move' + name: 'put_move', + processor: MoveCollectionProcessor::class ), new GetCollection(), new Post(securityPostDenormalize: 'is_granted("CREATE", object)'), diff --git a/databox/api/src/Entity/Core/CollectionAsset.php b/databox/api/src/Entity/Core/CollectionAsset.php index f4d7df990..b8d275c8c 100644 --- a/databox/api/src/Entity/Core/CollectionAsset.php +++ b/databox/api/src/Entity/Core/CollectionAsset.php @@ -11,7 +11,6 @@ use App\Entity\SearchDependencyInterface; use App\Entity\Traits\CreatedAtTrait; use App\Repository\Core\CollectionAssetRepository; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ApiResource( diff --git a/databox/api/src/Entity/Media/MediaIndex.php b/databox/api/src/Entity/Media/MediaIndex.php index 0633d28e2..b82712ad7 100644 --- a/databox/api/src/Entity/Media/MediaIndex.php +++ b/databox/api/src/Entity/Media/MediaIndex.php @@ -7,7 +7,6 @@ use App\Entity\AbstractUuidEntity; use App\Entity\Core\Collection; use App\Entity\Traits\WorkspaceTrait; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] diff --git a/databox/api/src/Entity/Traits/WorkspaceTrait.php b/databox/api/src/Entity/Traits/WorkspaceTrait.php index fec453179..441218c6f 100644 --- a/databox/api/src/Entity/Traits/WorkspaceTrait.php +++ b/databox/api/src/Entity/Traits/WorkspaceTrait.php @@ -5,7 +5,6 @@ namespace App\Entity\Traits; use App\Entity\Core\Workspace; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; trait WorkspaceTrait diff --git a/databox/api/src/Entity/Workflow/WorkflowState.php b/databox/api/src/Entity/Workflow/WorkflowState.php index 3524ce70b..fd210265d 100644 --- a/databox/api/src/Entity/Workflow/WorkflowState.php +++ b/databox/api/src/Entity/Workflow/WorkflowState.php @@ -17,8 +17,8 @@ use App\Controller\Workflow\RerunJobAction; use App\Entity\Core\Asset; use App\Workflow\Event\IncomingUploaderFileWorkflowEvent; -use Doctrine\ORM\EntityManagerInterface; use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping as ORM; #[ApiResource( diff --git a/databox/api/src/Validator/ValidAttributeConstraintValidator.php b/databox/api/src/Validator/ValidAttributeConstraintValidator.php index f63847f56..ef5aff854 100644 --- a/databox/api/src/Validator/ValidAttributeConstraintValidator.php +++ b/databox/api/src/Validator/ValidAttributeConstraintValidator.php @@ -16,7 +16,7 @@ public function __construct(private readonly AttributeTypeRegistry $typeRegistry } /** - * @param AbstractBaseAttribute $value + * @param AbstractBaseAttribute $value * @param SameWorkspaceConstraint $constraint */ public function validate($value, Constraint $constraint): void diff --git a/databox/api/tests/Attribute/Type/DateAttributeTypeTest.php b/databox/api/tests/Attribute/Type/DateAttributeTypeTest.php index 6ffaf25ce..b260583a4 100644 --- a/databox/api/tests/Attribute/Type/DateAttributeTypeTest.php +++ b/databox/api/tests/Attribute/Type/DateAttributeTypeTest.php @@ -41,7 +41,7 @@ public function getDenormalizationCases(): array ['2009', null], ['foo', null], ['1', null], - ['2008-01-12T12:13:00Z', \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, '2008-01-12T12:13:00Z')], + ['2008-01-12T12:13:00Z', '2008-01-12'], ]; } }