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

PS-721 fix un/translatable behaviour on attrs #490

Merged
merged 36 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8880aed
add configurator database
4rthem Oct 30, 2024
587a250
WIP
4rthem Nov 5, 2024
a0d9894
WIP
4rthem Nov 5, 2024
80653b1
WIP
4rthem Nov 5, 2024
0671b82
fix default doctrine connection
4rthem Nov 5, 2024
bc5f458
fix
4rthem Nov 5, 2024
e52bb8f
fix
4rthem Nov 5, 2024
8c41e32
fix
4rthem Nov 5, 2024
dc9c345
fix
4rthem Nov 6, 2024
a53081a
WIP
4rthem Nov 6, 2024
55dd5cf
WIP
4rthem Nov 6, 2024
d98d071
WIP
4rthem Nov 6, 2024
fd97f8f
WIP
4rthem Nov 6, 2024
6857fd9
WIP
4rthem Nov 6, 2024
56bffc7
composer update
4rthem Nov 14, 2024
487028b
fix rebase
4rthem Nov 14, 2024
97fa815
configurator bundle
4rthem Nov 14, 2024
1c67e1d
composer update
4rthem Nov 20, 2024
a16738a
add migrate to configurator
4rthem Nov 20, 2024
c5640cb
fix builds
4rthem Nov 20, 2024
5790005
fix namings
4rthem Nov 21, 2024
b08434a
fix api platform doc auth
4rthem Nov 21, 2024
41de30a
better names for admin
4rthem Nov 21, 2024
d7145df
add es document
4rthem Nov 21, 2024
5f995ae
WIP
4rthem Nov 22, 2024
140a931
WIP
4rthem Nov 22, 2024
2e6b26c
ts fixes
4rthem Nov 22, 2024
5fbe1bd
fixes
4rthem Nov 25, 2024
64efc69
PS-721 databox - fix un/translatable behaviour on attrs
4rthem Nov 25, 2024
285abc5
fix test
4rthem Nov 25, 2024
e4d6e47
WIP
4rthem Nov 25, 2024
891ae57
PS-732 databox - add feat delete AssetFileVersion
4rthem Nov 25, 2024
ddcbec9
Merge branch 'master' into PS-721-es
4rthem Nov 26, 2024
146da2b
remove composer lock in libs
4rthem Nov 26, 2024
9b2c416
remove S3 ACL
4rthem Nov 26, 2024
4a78360
fix test
4rthem Nov 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@ public function configure(OutputInterface $output, array $presets): void
$appScopes = $this->getAppScopes();
foreach ($this->symfonyApplications as $app) {
$clientId = getenv(sprintf('%s_ADMIN_CLIENT_ID', strtoupper($app)));
$baseUri = getenv(sprintf('%s_API_URL', strtoupper($app)));

$clientData = $this->configureClient(
$clientId,
getenv(sprintf('%s_ADMIN_CLIENT_SECRET', strtoupper($app))),
getenv(sprintf('%s_API_URL', strtoupper($app))).'/admin',
$baseUri,
[
'serviceAccountsEnabled' => true,
],
redirectUris: [
$baseUri.'/admin/*',
$baseUri.'/bundles/apiplatform/swagger-ui/oauth2-redirect.html',
]
);

Expand Down Expand Up @@ -198,12 +204,14 @@ private function configureClient(
?string $clientSecret,
string $baseUri,
array $data = [],
?array $redirectUris = null,
): array {
$clientData = $this->keycloakManager->createClient(
$clientId,
$clientSecret,
$baseUri,
$data,
$redirectUris,
);

foreach ([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ public function addServiceAccountRole(
public function createClient(
string $clientId,
?string $clientSecret,
?string $baseUri,
?string $rootUrl,
array $data = [],
?array $redirectUris = null,
): array {
$client = $this->getClientByClientId($clientId);

Expand All @@ -284,10 +285,10 @@ public function createClient(
'secret' => $clientSecret,
'publicClient' => null === $clientSecret,
'frontchannelLogout' => false,
'rootUrl' => $baseUri,
'redirectUris' => $baseUri ? [
$baseUri.'/*',
] : null,
'rootUrl' => $rootUrl,
'redirectUris' => $redirectUris ?? ($rootUrl ? [
$rootUrl.'/*',
] : null),
], $data);

if (null !== $client) {
Expand Down
4 changes: 2 additions & 2 deletions databox/api/config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ api_platform:
oauth:
clientId: '%env(ADMIN_CLIENT_ID)%'
clientSecret: '%env(ADMIN_CLIENT_SECRET)%'
tokenUrl: '%env(KEYCLOAK_URL)%/oauth/v2/token'
tokenUrl: '%env(KEYCLOAK_URL)%/realms/%env(KEYCLOAK_REALM_NAME)%/protocol/openid-connect/token'
authorizationUrl: '%env(KEYCLOAK_URL)%/realms/%env(KEYCLOAK_REALM_NAME)%/protocol/openid-connect/auth'
flow: authorizationCode
authorizationUrl: '%env(KEYCLOAK_URL)%/oauth/v2/auth'
event_listeners_backward_compatibility_layer: false
1 change: 1 addition & 0 deletions databox/api/src/Api/Model/Input/AssetInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AssetInput extends AbstractOwnerIdInput
/**
* @var Workspace
*/
#[Assert\NotNull]
public $workspace;

public ?Collection $collection = null;
Expand Down
29 changes: 29 additions & 0 deletions databox/api/src/Api/Model/Output/ESDocumentStateOutput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Api\Model\Output;

use Symfony\Component\Serializer\Annotation\Groups;

final readonly class ESDocumentStateOutput
{
public function __construct(
#[Groups(['_'])]
private array $data,
#[Groups(['_'])]
private bool $synced,
)
{
}

public function getData(): array
{
return $this->data;
}

public function getSynced(): bool
{
return $this->synced;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function process($data, Operation $operation, array $uriVariables = [], a
true,
);

$this->em->clear();

return $asset;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace App\Api\Processor;

use Alchemy\AuthBundle\Security\JwtUser;
use Alchemy\AuthBundle\Security\Traits\SecurityAwareTrait;
use Alchemy\ESBundle\Listener\DeferredIndexListener;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use Symfony\Component\HttpFoundation\Response;

class ItemElasticsearchDocumentSyncProcessor implements ProcessorInterface
{
use SecurityAwareTrait;

public function __construct(
private readonly DeferredIndexListener $deferredIndexListener,
) {
}

public function process($data, Operation $operation, array $uriVariables = [], array $context = []): Response
{
$this->denyAccessUnlessGranted(JwtUser::ROLE_TECH);
$this->deferredIndexListener->scheduleForUpdate($data);

return new Response('', 201);
}
}
10 changes: 3 additions & 7 deletions databox/api/src/Api/Provider/AttributeCollectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ protected function provideCollection(Operation $operation, array $uriVariables =
{
$asset = $this->getAsset($context);

$criteria = [
'asset' => $asset->getId(),
];

return $this->em->getRepository(Attribute::class)->findBy($criteria, [
'position' => 'ASC',
]);
return $this->em->getRepository(Attribute::class)
->getAssetAttributes($asset->getId())
;
}
}
2 changes: 1 addition & 1 deletion databox/api/src/Api/Provider/FieldTypeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function provideCollection(
$t->setName($name);

return $t;
}, $this->attributeTypeRegistry->getTypes());
}, array_filter($this->attributeTypeRegistry->getTypes(), fn (AttributeTypeInterface $type): bool => $type->isListed()));

usort($results, fn (FieldType $a, FieldType $b): int => $a->getTitle() <=> $b->getTitle());

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

declare(strict_types=1);

namespace App\Api\Provider;

use Alchemy\AuthBundle\Security\JwtUser;
use Alchemy\AuthBundle\Security\Traits\SecurityAwareTrait;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\Api\Traits\ItemProviderAwareTrait;
use App\Elasticsearch\ESDocumentStateManager;
use App\Security\Voter\AbstractVoter;
use Doctrine\ORM\EntityManagerInterface;

final class ItemElasticsearchDocumentProvider implements ProviderInterface
{
use SecurityAwareTrait;
use ItemProviderAwareTrait;

public function __construct(
private readonly EntityManagerInterface $em,
private readonly ESDocumentStateManager $esDocumentStateManager,
) {
}

public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
$item = $this->itemProvider->provide($operation, $uriVariables, $context);
$this->denyAccessUnlessGranted(AbstractVoter::READ, $item);
$this->denyAccessUnlessGranted(JwtUser::ROLE_TECH);

if ($item) {
return $this->esDocumentStateManager->getObjectState($item);
}

return null;
}
}
5 changes: 5 additions & 0 deletions databox/api/src/Attribute/Type/AbstractAttributeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,9 @@ public function supportsElasticSearchFuzziness(): bool
{
return false;
}

public function isListed(): bool
{
return true;
}
}
2 changes: 2 additions & 0 deletions databox/api/src/Attribute/Type/AttributeTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ public function validate($value, ExecutionContextInterface $context): void;
public function getAggregationField(): ?string;

public function normalizeBucket(array $bucket): ?array;

public function isListed(): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public function supportsAggregation(): bool
{
return true;
}

public function isListed(): bool
{
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p2')]
final readonly class FileDelete
final readonly class DeleteFileFromStorage
{
public function __construct(
private array $paths,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
readonly class FileDeleteHandler
readonly class DeleteFileFromStorageHandler
{
public function __construct(
private FileStorageManager $storageManager,
) {
}

public function __invoke(FileDelete $message): void
public function __invoke(DeleteFileFromStorage $message): void
{
foreach ($message->getPaths() as $path) {
$this->storageManager->delete($path);
Expand Down
19 changes: 19 additions & 0 deletions databox/api/src/Consumer/Handler/File/DeleteFilesIfOrphan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Consumer\Handler\File;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p2')]
final readonly class DeleteFilesIfOrphan
{
public function __construct(
private array $ids,
) {
}

public function getIds(): array
{
return $this->ids;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace App\Consumer\Handler\File;

use App\Entity\Core\File;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\MessageBusInterface;

#[AsMessageHandler]
readonly class DeleteFilesIfOrphanHandler
{
public function __construct(
private EntityManagerInterface $em,
private MessageBusInterface $bus,
) {
}

public function __invoke(DeleteFilesIfOrphan $message): void
{
$repo = $this->em->getRepository(File::class);
foreach ($message->getIds() as $id) {
$this->em->wrapInTransaction(function () use ($id, $repo): void {
$file = $repo->find($id);
if ($file instanceof File) {
$path = null;
if (File::STORAGE_S3_MAIN === $file->getStorage()) {
$path = $file->getPath();
}

$this->em->remove($file);
$this->em->flush();

if (null !== $path) {
$this->bus->dispatch(new DeleteFileFromStorage([$path]));
}
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static function getEntityFqcn(): string
public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
->setEntityLabelInSingular('AlternateUrl')
->setEntityLabelInPlural('AlternateUrl')
->setEntityLabelInSingular('Alternate URL')
->setEntityLabelInPlural('Alternate URLs')
->setSearchFields(['id', 'type', 'label']);
}

Expand Down
5 changes: 2 additions & 3 deletions databox/api/src/Controller/Admin/AssetCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
->setEntityLabelInSingular('Asset')
->setEntityLabelInPlural('Asset')
->setSearchFields(['id', 'title', 'ownerId', 'key', 'locale', 'privacy'])
->setPaginatorPageSize(30);
->setEntityLabelInPlural('Assets')
->setSearchFields(['id', 'title', 'ownerId', 'key', 'locale', 'privacy']);
}

public function configureFilters(Filters $filters): Filters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function configureActions(Actions $actions): Actions
public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
->setEntityLabelInSingular('AssetRendition')
->setEntityLabelInPlural('AssetRendition')
->setEntityLabelInSingular('Asset Rendition')
->setEntityLabelInPlural('Asset Renditions')
->setSearchFields(['id', 'definition.name'])
->setPaginatorPageSize(100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static function getEntityFqcn(): string
public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
->setEntityLabelInSingular('AssetTitleAttribute')
->setEntityLabelInPlural('AssetTitleAttribute')
->setEntityLabelInSingular('Asset Title Attribute')
->setEntityLabelInPlural('Asset Title Attributes')
->setSearchFields(['id', 'priority'])
->setPaginatorPageSize(200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public static function getEntityFqcn(): string
public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
->setEntityLabelInSingular('AttributeClass')
->setEntityLabelInPlural('AttributeClass')
->setEntityLabelInSingular('Attribute Class')
->setEntityLabelInPlural('Attribute Classes')
->setSearchFields(['id', 'name', 'key'])
->setPaginatorPageSize(100);
}
Expand Down
4 changes: 2 additions & 2 deletions databox/api/src/Controller/Admin/AttributeCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public function configureCrud(Crud $crud): Crud
{
return parent::configureCrud($crud)
->setEntityLabelInSingular('Attribute')
->setEntityLabelInPlural('Attribute')
->setEntityLabelInPlural('Attributes')
->setSearchFields(['id', 'locale', 'position', 'value', 'origin', 'originVendor', 'originUserId', 'originVendorContext', 'status', 'confidence'])
->setPaginatorPageSize(20);
;
}

public function configureFields(string $pageName): iterable
Expand Down
Loading
Loading