Skip to content

Commit

Permalink
PS-710 uploader - add hidden option on target
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Nov 7, 2024
1 parent 48b901f commit 88d4651
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
31 changes: 31 additions & 0 deletions uploader/api/migrations/Version20241107091125.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241107091125 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE target ADD hidden BOOLEAN NOT NULL DEFAULT FALSE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE target DROP hidden');
}
}
3 changes: 3 additions & 0 deletions uploader/api/src/Command/CreateTargetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class CreateTargetCommand extends Command
Expand All @@ -28,6 +29,7 @@ protected function configure(): void
->addArgument('slug', InputArgument::REQUIRED, 'The target unique slug')
->addArgument('name', InputArgument::REQUIRED, 'The target name')
->addArgument('target-url', InputArgument::REQUIRED)
->addOption('hidden', null, InputOption::VALUE_NONE, 'Whether the target is hidden')
->setHelp(<<<EOT
The <info>%command.name%</info> command creates a new upload target.
Expand All @@ -52,6 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$target->setTargetUrl($input->getArgument('target-url'));
$target->setHidden((bool) $input->getOption('hidden'));
$target->setName($input->getArgument('name'));
$this->em->persist($target);
$this->em->flush();
Expand Down
8 changes: 5 additions & 3 deletions uploader/api/src/Controller/Admin/TargetCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,26 @@ public function configureFields(string $pageName): iterable
yield IdField::new()
->hideOnForm();
yield TextField::new('slug');
yield TextField::new('name');
yield TextField::new('name');
yield TextareaField::new('description')
->hideOnIndex();
->hideOnIndex();
yield CodeField::new('pullModeUrl', 'Pull mode URL')
->onlyOnIndex();
yield TextField::new('targetUrl')
->setHelp('Leave empty for pull mode. i.e: "https://phraseanet.phrasea.local/api/v1/upload/enqueue/" for Phraseanet, "http://databox-api/incoming-uploads" for Databox upload');
yield TextField::new('targetTokenType')
->setHelp('Use "OAuth" for Phraseanet')
->setFormTypeOptions(['attr' => ['placeholder' => 'Defaults to "Bearer"']])
->onlyOnForms();
->onlyOnForms();
yield TextField::new('targetAccessToken');
yield TextField::new('defaultDestination')
->setHelp('i.e: "42" (for Phraseanet collection), "cdc3679f-3f37-4260-8de7-b649ecc8c1cc" (for Databox collection)')
->hideOnIndex();
yield GroupChoiceField::new('allowedGroups')
->hideOnIndex();
yield BooleanField::new('enabled');
yield BooleanField::new('hidden')
->setHelp('Hide this target from the list of available targets');
yield DateTimeField::new('createdAt')
->hideOnForm();

Expand Down
4 changes: 3 additions & 1 deletion uploader/api/src/Doctrine/TargetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ private function apply(

$rootAlias = $queryBuilder->getRootAliases()[0];
$queryBuilder
->andWhere(sprintf('%s.enabled = true', $rootAlias));
->andWhere(sprintf('%s.enabled = true', $rootAlias))
->andWhere(sprintf('%s.hidden = false', $rootAlias))
;
}
}
13 changes: 13 additions & 0 deletions uploader/api/src/Entity/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class Target extends AbstractUuidEntity implements \Stringable
#[Groups(['target:read'])]
private bool $enabled = true;

#[ORM\Column(type: Types::BOOLEAN, nullable: false)]
private bool $hidden = false;

#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['target:index'])]
private ?string $description = null;
Expand Down Expand Up @@ -216,4 +219,14 @@ public function setEnabled(bool $enabled): void
{
$this->enabled = $enabled;
}

public function isHidden(): bool
{
return $this->hidden;
}

public function setHidden(bool $hidden): void
{
$this->hidden = $hidden;
}
}

0 comments on commit 88d4651

Please sign in to comment.