Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Oct 2, 2023
1 parent 0ead7eb commit 63ea290
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 60 deletions.
4 changes: 1 addition & 3 deletions databox/api/migrations/Version20230920160828.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace DoctrineMigrations;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

Expand All @@ -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));

Expand Down
23 changes: 23 additions & 0 deletions databox/api/src/Api/InputTransformer/MoveAssetInputTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Api\InputTransformer;

use App\Api\Model\Input\MoveAssetInput;

class MoveAssetInputTransformer extends AbstractFileInputTransformer
{
public function supports(string $resourceClass, object $data): bool
{
return $data instanceof MoveAssetInput;
}

/**
* @param MoveAssetInput $data
*/
public function transform(object $data, string $resourceClass, array $context = []): object|iterable
{
return $data;
}
}
59 changes: 59 additions & 0 deletions databox/api/src/Api/Processor/MoveCollectionProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace App\Api\Processor;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\Entity\Core\Collection;
use App\Security\Voter\AbstractVoter;
use App\Util\SecurityAwareTrait;
use Arthem\Bundle\RabbitBundle\Producer\EventProducer;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class MoveCollectionProcessor implements ProcessorInterface
{
use SecurityAwareTrait;

public function __construct(
private readonly EventProducer $eventProducer,
private readonly EntityManagerInterface $em,
private readonly IriConverterInterface $iriConverter
) {
}

/**
* @param Collection $data
*/
public function process($data, Operation $operation, array $uriVariables = [], array $context = []): Response
{
$this->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);
}
}
40 changes: 0 additions & 40 deletions databox/api/src/Controller/Core/MoveCollectionAction.php

This file was deleted.

3 changes: 1 addition & 2 deletions databox/api/src/Elasticsearch/AssetDataTemplateSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down
1 change: 0 additions & 1 deletion databox/api/src/Elasticsearch/CollectionSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
public function __construct(
private Client $client,
private bool $useAlias,
)
{
) {
}

public function updateMapping(string $indexName, array $mapping): void
Expand Down
1 change: 0 additions & 1 deletion databox/api/src/Entity/AbstractUuidEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion databox/api/src/Entity/Basket/Basket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion databox/api/src/Entity/Core/AssetRendition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 8 additions & 3 deletions databox/api/src/Entity/Core/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' => [
[
Expand All @@ -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)'),
Expand Down
1 change: 0 additions & 1 deletion databox/api/src/Entity/Core/CollectionAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion databox/api/src/Entity/Media/MediaIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion databox/api/src/Entity/Traits/WorkspaceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion databox/api/src/Entity/Workflow/WorkflowState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion databox/api/tests/Attribute/Type/DateAttributeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
}

0 comments on commit 63ea290

Please sign in to comment.