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-fixes-01 #487

Merged
merged 19 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions databox/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ FROM ${REGISTRY_NAMESPACE}php-fpm-base:${BASE_TAG} AS api-php
ENV IMAGICK_PHP83_FIX_COMMIT=28f27044e435a2b203e32675e942eb8de620ee58

RUN apk add --no-cache \
perl \
freetype \
imagemagick \
ffmpeg \
freetype \
ghostscript \
libheif \
libjpeg-turbo \
libpng \
libwebp \
libheif \
ffmpeg \
libreoffice \
libwebp \
perl \
&& apk add --no-cache --virtual build-essentials \
g++ \
make \
Expand Down
2 changes: 1 addition & 1 deletion databox/api/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Alchemy\WorkflowBundle\AlchemyWorkflowBundle::class => ['all' => true],
Alchemy\ESBundle\AlchemyESBundle::class => ['all' => true],
Alchemy\MessengerBundle\AlchemyMessengerBundle::class => ['all' => true],
Sentry\SentryBundle\SentryBundle::class => ['prod' => true],
Sentry\SentryBundle\SentryBundle::class => ['all' => true],
Arthem\ObjectReferenceBundle\ArthemObjectReferenceBundle::class => ['all' => true],
Alchemy\RenditionFactoryBundle\AlchemyRenditionFactoryBundle::class => ['all' => true],
];
1 change: 1 addition & 0 deletions databox/api/config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ framework:
Alchemy\Workflow\Message\JobConsumer: p1
Alchemy\WebhookBundle\Consumer\WebhookTriggerMessage: p2
Alchemy\WebhookBundle\Consumer\WebhookEvent: p2
Alchemy\CoreBundle\Message\Debug\SentryDebug: p1

when@dev:
framework:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
use Alchemy\AdminBundle\Field\CodeField;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Field\JsonField;
use Alchemy\AdminBundle\Filter\AssociationIdentifierFilter;
use Alchemy\AdminBundle\Filter\ChildPropertyEntityFilter;
use App\Entity\Core\AssetRendition;
use App\Entity\Core\Workspace;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Filter\BooleanFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\DateTimeFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\NullFilter;

class AssetRenditionCrudController extends AbstractAdminCrudController
Expand Down Expand Up @@ -45,9 +49,18 @@ public function configureCrud(Crud $crud): Crud
public function configureFilters(Filters $filters): Filters
{
return $filters
->add(ChildPropertyEntityFilter::new('definition', 'workspace', 'Workspace'))
->add(ChildPropertyEntityFilter::new(
'definition',
'workspace',
Workspace::class,
'Workspace'
))
->add(EntityFilter::new('definition'))
->add(AssociationIdentifierFilter::new('asset'))
->add(NullFilter::new('file', 'Is Ready')->setChoiceLabels('Not ready', 'Ready'))
->add(DateTimeFilter::new('createdAt'))
->add(BooleanFilter::new('locked'))
->add(BooleanFilter::new('substituted'))
;
}

Expand Down
14 changes: 12 additions & 2 deletions databox/api/src/Controller/Admin/AttributeCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
use Alchemy\AdminBundle\Controller\AbstractAdminCrudController;
use Alchemy\AdminBundle\Field\IdField;
use Alchemy\AdminBundle\Field\JsonField;
use Alchemy\AdminBundle\Filter\AssociationIdentifierFilter;
use Alchemy\AdminBundle\Filter\ChildPropertyEntityFilter;
use App\Entity\Core\Attribute;
use App\Entity\Core\Workspace;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
Expand All @@ -19,6 +21,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Filter\BooleanFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
use EasyCorp\Bundle\EasyAdminBundle\Filter\TextFilter;

class AttributeCrudController extends AbstractAdminCrudController
Expand All @@ -38,7 +41,14 @@ public function configureActions(Actions $actions): Actions
public function configureFilters(Filters $filters): Filters
{
return $filters
->add(ChildPropertyEntityFilter::new('definition', 'workspace', 'Workspace'))
->add(ChildPropertyEntityFilter::new(
'definition',
'workspace',
Workspace::class,
'Workspace'
))
->add(EntityFilter::new('definition'))
->add(AssociationIdentifierFilter::new('asset'))
->add(TextFilter::new('value'))
->add(TextFilter::new('locale'))
->add(BooleanFilter::new('locked'))
Expand All @@ -50,7 +60,7 @@ public function configureCrud(Crud $crud): Crud
return parent::configureCrud($crud)
->setEntityLabelInSingular('Attribute')
->setEntityLabelInPlural('Attribute')
->setSearchFields(['id', 'locale', 'position', 'translationId', 'translationOriginHash', 'value', 'origin', 'originVendor', 'originUserId', 'originVendorContext', 'coordinates', 'status', 'confidence'])
->setSearchFields(['id', 'locale', 'position', 'value', 'origin', 'originVendor', 'originUserId', 'originVendorContext', 'status', 'confidence'])
->setPaginatorPageSize(20);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function configureFields(string $pageName): iterable
yield Field::new('facetEnabled')
->hideOnIndex();
yield ArrayField::new('fallback')
->hideOnIndex();
->onlyOnDetail();
yield TextField::new('key')
->hideOnIndex();
yield IntegerField::new('position');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ public function configureFields(string $pageName): iterable
->onlyOnForms();
yield DateTimeField::new('createdAt')
->hideOnForm();
yield DateTimeField::new('updatedAt')
->hideOnForm();
}
}
36 changes: 27 additions & 9 deletions databox/api/src/Doctrine/Delete/CollectionDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
use App\Entity\Core\Asset;
use App\Entity\Core\Collection;
use App\Entity\Core\CollectionAsset;
use App\Entity\Template\AssetDataTemplate;
use Doctrine\ORM\EntityManagerInterface;

final readonly class CollectionDelete
{
public function __construct(private EntityManagerInterface $em, private IndexCleaner $indexCleaner, private SoftDeleteToggler $softDeleteToggler)
{
public function __construct(
private EntityManagerInterface $em,
private IndexCleaner $indexCleaner,
private SoftDeleteToggler $softDeleteToggler,
) {
}

public function deleteCollection(string $collectionId, bool $isChildProcess = false): void
Expand Down Expand Up @@ -79,13 +83,6 @@ private function doDelete(string $collectionId): void
->getQuery()
->toIterable();

foreach ($assets as $a) {
$asset = $this->em->find(Asset::class, $a['id']);
$this->em->remove($asset);
$this->em->flush();
$this->em->clear();
}

$this->em->getRepository(CollectionAsset::class)
->createQueryBuilder('t')
->delete()
Expand All @@ -94,10 +91,31 @@ private function doDelete(string $collectionId): void
->getQuery()
->execute();

foreach ($assets as $a) {
$asset = $this->em->find(Asset::class, $a['id']);
$this->em->remove($asset);
$this->em->flush();
$this->em->clear();
}

$this->deleteDependencies(AssetDataTemplate::class, $collectionId);

$collection = $this->em->find(Collection::class, $collectionId);
if ($collection instanceof Collection) {
$this->em->remove($collection);
$this->em->flush();
}
}

private function deleteDependencies(string $entityClass, string $collectionId): void
{
$items = $this->em->getRepository($entityClass)->findBy([
'collection' => $collectionId,
]);
foreach ($items as $item) {
$this->em->remove($item);
}
$this->em->flush();
$this->em->clear();
}
}
12 changes: 9 additions & 3 deletions databox/api/src/Doctrine/Delete/WorkspaceDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
use App\Entity\Core\RenditionDefinition;
use App\Entity\Core\Tag;
use App\Entity\Core\Workspace;
use App\Entity\Template\AssetDataTemplate;
use Doctrine\ORM\EntityManagerInterface;

class WorkspaceDelete
final readonly class WorkspaceDelete
{
public function __construct(private readonly EntityManagerInterface $em, private readonly CollectionDelete $collectionDelete, private readonly IndexCleaner $indexCleaner, private readonly SoftDeleteToggler $softDeleteToggler)
{
public function __construct(
private EntityManagerInterface $em,
private CollectionDelete $collectionDelete,
private IndexCleaner $indexCleaner,
private SoftDeleteToggler $softDeleteToggler,
) {
}

public function deleteWorkspace(string $workspaceId): void
Expand Down Expand Up @@ -62,6 +67,7 @@ public function deleteWorkspace(string $workspaceId): void
$this->deleteDependencies(RenditionClass::class, $workspaceId);
$this->deleteDependencies(AttributeDefinition::class, $workspaceId);
$this->deleteDependencies(AttributeClass::class, $workspaceId);
$this->deleteDependencies(AssetDataTemplate::class, $workspaceId);

$files = $this->em->getRepository(File::class)
->createQueryBuilder('t')
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Entity/Integration/WorkspaceSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,8 @@ public function getPlainValue(): ?string
public function setPlainValue(?string $plainValue): void
{
$this->plainValue = $plainValue;
if (null !== $plainValue) {
$this->setValue(null); // Make a change to this mapped field trigger Doctrine preUpdate event
}
}
}
4 changes: 4 additions & 0 deletions databox/api/src/Integration/ApiBudgetLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function createLimiter(int $limit, string $policy, string $interval, stri
*/
public function acceptIntegrationApiCall(IntegrationConfig $config, int $tokens = 1): void
{
if (!$config['budgetLimit']['enabled']) {
return;
}

$limiter = $this->createLimiter(
$config['budgetLimit']['limit'],
$config['budgetLimit']['policy'],
Expand Down
20 changes: 14 additions & 6 deletions databox/api/src/Integration/RemoveBg/RemoveBgClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public function getBgRemoved(File $file, string $apiKey): string
}

$path = $this->fileFetcher->getFile($file);

$md5 = md5_file($path);
$md5 = md5_file($path).'-v2';

$cacheFile = sprintf('%s/%s', $this->cacheDir, $md5);
if (file_exists($cacheFile)) {
Expand All @@ -42,11 +41,20 @@ public function getBgRemoved(File $file, string $apiKey): string
],
]);

$fileHandler = fopen($cacheFile, 'w');
foreach ($this->removeBgClient->stream($res) as $chunk) {
fwrite($fileHandler, $chunk->getContent());
try {
$fileHandler = fopen($cacheFile, 'w');
foreach ($this->removeBgClient->stream($res) as $chunk) {
fwrite($fileHandler, $chunk->getContent());
}
fclose($fileHandler);
} catch (\Throwable $e) {
if (isset($fileHandler)) {
fclose($fileHandler);
@unlink($cacheFile);
}

throw $e;
}
fclose($fileHandler);

return $cacheFile;
}
Expand Down
3 changes: 2 additions & 1 deletion databox/api/src/Integration/RemoveBg/RemoveBgIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Integration\Action\FileUserActionsTrait;
use App\Integration\IntegrationConfig;
use App\Integration\IntegrationContext;
use App\Integration\IntegrationDataTransformerInterface;
use App\Integration\PusherTrait;
use App\Integration\RemoveBg\Message\RemoveBgCall;
use App\Integration\UserActionsIntegrationInterface;
Expand All @@ -19,7 +20,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;

class RemoveBgIntegration extends AbstractIntegration implements WorkflowIntegrationInterface, UserActionsIntegrationInterface
class RemoveBgIntegration extends AbstractIntegration implements IntegrationDataTransformerInterface, WorkflowIntegrationInterface, UserActionsIntegrationInterface
{
use PusherTrait;
use FileUserActionsTrait;
Expand Down
30 changes: 30 additions & 0 deletions databox/api/src/Listener/AssetIngestWorkflowListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Listener;

use Alchemy\CoreBundle\Pusher\PusherManager;
use Alchemy\Workflow\Listener\WorkflowUpdateEvent;
use Alchemy\Workflow\State\WorkflowState;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener(event: WorkflowUpdateEvent::class, method: 'onWorkflowUpdate')]
final readonly class AssetIngestWorkflowListener
{
public function __construct(
private PusherManager $pusherManager,
)
{
}

public function onWorkflowUpdate(WorkflowUpdateEvent $event): void
{
$state = $event->getState();
if (str_starts_with($state->getWorkflowName(), 'asset-ingest:') && in_array($state->getStatus(), [
WorkflowState::STATUS_SUCCESS,
WorkflowState::STATUS_FAILURE,
])) {
$assetId = $state->getEvent()->getInputs()['assetId'];
$this->pusherManager->trigger('asset-'.$assetId, 'asset_ingested', [], direct: true);
}
}
}
5 changes: 1 addition & 4 deletions databox/api/src/Security/Voter/AssetVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $
return $isOwner()
|| $this->security->isGranted(self::SCOPE_PREFIX.'DELETE')
|| $this->hasAcl(PermissionInterface::DELETE, $subject, $token)
|| (
null !== $subject->getReferenceCollection()
&& $this->hasAcl(PermissionInterface::DELETE, $subject->getReferenceCollection(), $token)
);
|| $this->voteOnContainer($subject, AbstractVoter::DELETE);
case self::EDIT_PERMISSIONS:
return $isOwner()
|| $this->security->isGranted(self::SCOPE_PREFIX.'OWNER')
Expand Down
2 changes: 1 addition & 1 deletion databox/client/src/components/Dialog/Workspace/Acl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Acl({data, onClose, minHeight}: Props) {
objectType={PermissionObject.Workspace}
displayedPermissions={Object.keys(aclPermissions).filter(
p => p !== AclPermission.SHARE
)}
).concat([AclPermission.ALL])}
/>
</ContentTab>
);
Expand Down
15 changes: 14 additions & 1 deletion databox/client/src/components/Media/Asset/AssetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import AssetViewActions from './Actions/AssetViewActions.tsx';
import {Trans} from 'react-i18next';
import {getMediaBackgroundColor} from '../../../themes/base.ts';
import {useModalFetch} from '../../../hooks/useModalFetch.ts';
import {useChannelRegistration} from "../../../lib/pusher.ts";
import {queryClient} from "../../../lib/query.ts";

export type IntegrationOverlayCommonProps = {
dimensions: Dimensions;
Expand Down Expand Up @@ -50,8 +52,19 @@ export default function AssetView({modalIndex, open}: Props) {
AssetAnnotation[] | undefined
>();

const queryKey = ['assets', assetId];

useChannelRegistration(
`asset-${assetId}`,
`asset_ingested`,
() => {
queryClient.invalidateQueries({queryKey});
}
);

const {data, isSuccess} = useModalFetch({
queryKey: ['assets', assetId],
queryKey,
staleTime: 2000,
queryFn: () =>
Promise.all([
getAsset(assetId!),
Expand Down
2 changes: 1 addition & 1 deletion expose/api/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle::class => ['all' => true],
Alchemy\NotifyBundle\AlchemyNotifyBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Sentry\SentryBundle\SentryBundle::class => ['prod' => true],
Sentry\SentryBundle\SentryBundle::class => ['all' => true],
Alchemy\MessengerBundle\AlchemyMessengerBundle::class => ['all' => true],
];
Loading
Loading