diff --git a/uploader/api/migrations/Version20241107091125.php b/uploader/api/migrations/Version20241107091125.php new file mode 100644 index 000000000..3a5ba2ae5 --- /dev/null +++ b/uploader/api/migrations/Version20241107091125.php @@ -0,0 +1,31 @@ +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'); + } +} diff --git a/uploader/api/src/Command/CreateTargetCommand.php b/uploader/api/src/Command/CreateTargetCommand.php index d75bc1062..ebfcf7314 100644 --- a/uploader/api/src/Command/CreateTargetCommand.php +++ b/uploader/api/src/Command/CreateTargetCommand.php @@ -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 @@ -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(<<%command.name% command creates a new upload target. @@ -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(); diff --git a/uploader/api/src/Controller/Admin/TargetCrudController.php b/uploader/api/src/Controller/Admin/TargetCrudController.php index 9c5464e17..8f811e6b0 100644 --- a/uploader/api/src/Controller/Admin/TargetCrudController.php +++ b/uploader/api/src/Controller/Admin/TargetCrudController.php @@ -46,9 +46,9 @@ 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') @@ -56,7 +56,7 @@ public function configureFields(string $pageName): iterable 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)') @@ -64,6 +64,8 @@ public function configureFields(string $pageName): iterable 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(); diff --git a/uploader/api/src/Doctrine/TargetExtension.php b/uploader/api/src/Doctrine/TargetExtension.php index 021480476..4fc71d1f8 100644 --- a/uploader/api/src/Doctrine/TargetExtension.php +++ b/uploader/api/src/Doctrine/TargetExtension.php @@ -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)) + ; } } diff --git a/uploader/api/src/Entity/Target.php b/uploader/api/src/Entity/Target.php index 674b72ec9..f784d7c03 100644 --- a/uploader/api/src/Entity/Target.php +++ b/uploader/api/src/Entity/Target.php @@ -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; @@ -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; + } }