From 00daab63e1bf84df9ccb05a2c6d561b2b4f2bce6 Mon Sep 17 00:00:00 2001 From: AntonKhabiuk Date: Fri, 2 Aug 2024 15:32:29 +0300 Subject: [PATCH 1/4] CC-34135 Expand user form --- composer.json | 10 +- phpstan.neon | 1 + .../Transfer/amazon_quicksight.transfer.xml | 4 + .../AmazonQuicksightConfig.php | 40 ++++++ .../AmazonQuicksightDependencyProvider.php | 31 +++++ .../AmazonQuicksightCommunicationFactory.php | 33 +++++ .../Expander/QuicksightUserFormExpander.php | 131 ++++++++++++++++++ .../QuicksightUserFormExpanderInterface.php | 20 +++ .../User/QuicksightUserFormExpanderPlugin.php | 37 +++++ .../QuicksightUserRoleDataTransformer.php | 68 +++++++++ ...azonQuicksightToTranslatorFacadeBridge.php | 37 +++++ ...nQuicksightToTranslatorFacadeInterface.php | 21 +++ .../user-form-quicksight-user-role-field.twig | 9 ++ src/SprykerEco/data/translation/Zed/de_DE.csv | 3 + src/SprykerEco/data/translation/Zed/en_US.csv | 3 + 15 files changed, 445 insertions(+), 3 deletions(-) create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpanderInterface.php create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserFormExpanderPlugin.php create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeBridge.php create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeInterface.php create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig create mode 100644 src/SprykerEco/data/translation/Zed/de_DE.csv create mode 100644 src/SprykerEco/data/translation/Zed/en_US.csv diff --git a/composer.json b/composer.json index cd38031..a30896f 100644 --- a/composer.json +++ b/composer.json @@ -7,11 +7,15 @@ "aws/aws-sdk-php": "^3.90.0", "php": ">=8.1", "spryker/kernel": "^3.30.0", - "spryker/user": "^3.0.0" + "spryker/symfony": "^3.0.0", + "spryker/translator": "^1.1.0", + "spryker/user": "^3.0.0", + "spryker/user-extension": "^1.4.0", + "spryker/uuid-behavior": "^1.0.0" }, "require-dev": { - "spryker/code-sniffer": "*", - "spryker/testify": "*" + "phpstan/phpstan": "*", + "spryker/code-sniffer": "*" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index 3260382..0afe047 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ parameters: level: 8 + checkGenericClassInNonGenericObjectType: false paths: - src/ excludePaths: diff --git a/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml b/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml index 499c4e6..dc33cc7 100644 --- a/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml +++ b/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml @@ -12,4 +12,8 @@ + + + + diff --git a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php index 1e94c97..1a6167c 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php @@ -18,6 +18,33 @@ class AmazonQuicksightConfig extends AbstractBundleConfig */ protected const QUICKSIGHT_USER_REGISTER_NAMESPACE = 'default'; + /** + * @var string + */ + protected const QUICKSIGHT_USER_ROLE_READER = 'READER'; + + /** + * @var string + */ + protected const QUICKSIGHT_USER_ROLE_AUTHOR = 'AUTHOR'; + + /** + * Specification: + * - Returns the list of available Quicksight user roles. + * - The list of available roles can be found here: {@link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_User.html#QS-Type-User-Role} + * + * @api + * + * @return list + */ + public function getQuicksightUserRoles(): array + { + return [ + static::QUICKSIGHT_USER_ROLE_READER, + static::QUICKSIGHT_USER_ROLE_AUTHOR, + ]; + } + /** * Specification: * - Returns the ID for the AWS account that contains your Amazon QuickSight account. @@ -74,4 +101,17 @@ public function getQuicksightClientConfiguration(): array return $quicksightClientConfiguration; } + + /** + * Specification: + * - Defines if updating quicksight user role via user form is enabled. + * + * @api + * + * @return bool + */ + public function isQuicksightUserRoleUpdateEnabled(): bool + { + return false; + } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php index 32ea401..6fa7bfd 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php @@ -10,6 +10,7 @@ use Spryker\Zed\Kernel\AbstractBundleDependencyProvider; use Spryker\Zed\Kernel\Container; use SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientAdapter; +use SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeBridge; /** * @method \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig getConfig() @@ -21,6 +22,11 @@ class AmazonQuicksightDependencyProvider extends AbstractBundleDependencyProvide */ public const AWS_QUICKSIGHT_CLIENT = 'AWS_QUICKSIGHT_CLIENT'; + /** + * @var string + */ + public const FACADE_TRANSLATOR = 'FACADE_TRANSLATOR'; + /** * @param \Spryker\Zed\Kernel\Container $container * @@ -34,6 +40,19 @@ public function provideBusinessLayerDependencies(Container $container): Containe return $container; } + /** + * @param \Spryker\Zed\Kernel\Container $container + * + * @return \Spryker\Zed\Kernel\Container + */ + public function provideCommunicationLayerDependencies(Container $container): Container + { + $container = parent::provideCommunicationLayerDependencies($container); + $container = $this->addTranslatorFacade($container); + + return $container; + } + /** * @param \Spryker\Zed\Kernel\Container $container * @@ -49,4 +68,16 @@ protected function addAwsQuicksightClient(Container $container): Container return $container; } + + /** + * @return \Spryker\Zed\Kernel\Container + */ + protected function addTranslatorFacade(Container $container): Container + { + $container->set(static::FACADE_TRANSLATOR, function (Container $container) { + return new AmazonQuicksightToTranslatorFacadeBridge($container->getLocator()->translator()->facade()); + }); + + return $container; + } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php index aeae640..d8cb1af 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php @@ -8,6 +8,12 @@ namespace SprykerEco\Zed\AmazonQuicksight\Communication; use Spryker\Zed\Kernel\Communication\AbstractCommunicationFactory; +use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightDependencyProvider; +use SprykerEco\Zed\AmazonQuicksight\Communication\Expander\QuicksightUserFormExpander; +use SprykerEco\Zed\AmazonQuicksight\Communication\Expander\QuicksightUserFormExpanderInterface; +use SprykerEco\Zed\AmazonQuicksight\Communication\Transformer\QuicksightUserRoleDataTransformer; +use SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeInterface; +use Symfony\Component\Form\DataTransformerInterface; /** * @method \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig getConfig() @@ -17,4 +23,31 @@ */ class AmazonQuicksightCommunicationFactory extends AbstractCommunicationFactory { + /** + * @return \SprykerEco\Zed\AmazonQuicksight\Communication\Expander\QuicksightUserFormExpanderInterface + */ + public function createQuicksightUserFormExpander(): QuicksightUserFormExpanderInterface + { + return new QuicksightUserFormExpander( + $this->createQuicksightUserRoleDataTransformer(), + $this->getConfig(), + $this->getTranslatorFacade(), + ); + } + + /** + * @return \Symfony\Component\Form\DataTransformerInterface + */ + public function createQuicksightUserRoleDataTransformer(): DataTransformerInterface + { + return new QuicksightUserRoleDataTransformer(); + } + + /** + * @return \SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeInterface + */ + public function getTranslatorFacade(): AmazonQuicksightToTranslatorFacadeInterface + { + return $this->getProvidedDependency(AmazonQuicksightDependencyProvider::FACADE_TRANSLATOR); + } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php new file mode 100644 index 0000000..3e9f187 --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php @@ -0,0 +1,131 @@ +Reader: A user who has read-only access to dashboards.'; + + /** + * @var string + */ + protected const TEMPLATE_PATH_QUICKSIGHT_USER_ROLE = '@AmazonQuicksight/_partials/user-form-quicksight-user-role-field.twig'; + + /** + * @var string + */ + protected const KEY_QUICKSIGHT_USER = 'quicksight_user'; + + /** + * @var string + */ + protected const KEY_ROLE = 'role'; + + /** + * @var \Symfony\Component\Form\DataTransformerInterface + */ + protected DataTransformerInterface $quicksightUserRoleDataTransformer; + + /** + * @var \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig + */ + protected AmazonQuicksightConfig $amazonQuicksightConfig; + + /** + * @var \SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeInterface + */ + protected AmazonQuicksightToTranslatorFacadeInterface $translatorFacade; + + /** + * @param \Symfony\Component\Form\DataTransformerInterface $quicksightUserRoleDataTransformer + * @param \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig $amazonQuicksightConfig + * @param \SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeInterface $translatorFacade + */ + public function __construct( + DataTransformerInterface $quicksightUserRoleDataTransformer, + AmazonQuicksightConfig $amazonQuicksightConfig, + AmazonQuicksightToTranslatorFacadeInterface $translatorFacade + ) { + $this->quicksightUserRoleDataTransformer = $quicksightUserRoleDataTransformer; + $this->amazonQuicksightConfig = $amazonQuicksightConfig; + $this->translatorFacade = $translatorFacade; + } + + /** + * @param \Symfony\Component\Form\FormBuilderInterface $builder + * + * @return void + */ + public function expandForm(FormBuilderInterface $builder): void + { + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { + $data = $event->getData(); + $quicksightUserRole = $data[static::KEY_QUICKSIGHT_USER][static::KEY_ROLE] ?? null; + + $event->getForm()->add(static::FIELD_QUICKSIGHT_USER_ROLE, ChoiceType::class, [ + 'label' => static::PLACEHOLDER_QUICKSIGHT_USER_ROLE, + 'required' => false, + 'choices' => $this->getQuicksightUserRoleChoices(), + 'placeholder' => static::PLACEHOLDER_QUICKSIGHT_USER_ROLE, + 'attr' => [ + 'template_path' => static::TEMPLATE_PATH_QUICKSIGHT_USER_ROLE, + 'disabled' => $quicksightUserRole && !$this->amazonQuicksightConfig->isQuicksightUserRoleUpdateEnabled(), + ], + 'help' => $this->translatorFacade->trans(static::FIELD_QUICKSIGHT_USER_ROLE_HELP_MESSAGE), + ]); + }); + + $builder->addModelTransformer($this->quicksightUserRoleDataTransformer); + } + + /** + * @return array + */ + protected function getQuicksightUserRoleChoices(): array + { + $quicksightUserRoles = $this->amazonQuicksightConfig->getQuicksightUserRoles(); + + return array_combine( + $this->formatQuicksightUserRoleChoiceLabels($quicksightUserRoles), + $quicksightUserRoles, + ); + } + + /** + * @param list $quicksightUserRoles + * + * @return list + */ + protected function formatQuicksightUserRoleChoiceLabels(array $quicksightUserRoles): array + { + return array_map(function ($quicksightUserRole) { + return ucfirst(strtolower($quicksightUserRole)); + }, $quicksightUserRoles); + } +} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpanderInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpanderInterface.php new file mode 100644 index 0000000..1a33f52 --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpanderInterface.php @@ -0,0 +1,20 @@ + $builder + * + * @return void + */ + public function expandForm(FormBuilderInterface $builder): void; +} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserFormExpanderPlugin.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserFormExpanderPlugin.php new file mode 100644 index 0000000..8a03dd0 --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserFormExpanderPlugin.php @@ -0,0 +1,37 @@ +getFactory() + ->createQuicksightUserFormExpander() + ->expandForm($builder); + } +} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php new file mode 100644 index 0000000..f611d42 --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php @@ -0,0 +1,68 @@ + + */ + public function transform(mixed $value) + { + if (!is_array($value)) { + return $value; + } + + $quicksightUserRole = $value[static::KEY_QUICKSIGHT_USER][static::KEY_ROLE] ?? null; + if ($quicksightUserRole !== null) { + $value[static::FIELD_QUICKSIGHT_USER_ROLE] = $quicksightUserRole; + } + + return $value; + } + + /** + * @param mixed $value + * + * @return mixed|array + */ + public function reverseTransform(mixed $value) + { + if (!is_array($value)) { + return $value; + } + + $quicksightUserRole = $value[static::FIELD_QUICKSIGHT_USER_ROLE] ?? null; + if ($quicksightUserRole !== null) { + $value[static::KEY_QUICKSIGHT_USER][static::KEY_ROLE] = $quicksightUserRole; + } + + return $value; + } +} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeBridge.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeBridge.php new file mode 100644 index 0000000..f6673fa --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeBridge.php @@ -0,0 +1,37 @@ +translatorFacade = $translatorFacade; + } + + /** + * @param string $id + * @param array $parameters + * @param string|null $domain + * @param string|null $locale + * + * @return string + */ + public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string + { + return $this->translatorFacade->trans($id, $parameters, $domain, $locale); + } +} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeInterface.php new file mode 100644 index 0000000..2ada2fe --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeInterface.php @@ -0,0 +1,21 @@ + $parameters + * @param string|null $domain + * @param string|null $locale + * + * @return string + */ + public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string; +} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig new file mode 100644 index 0000000..f9fe706 --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig @@ -0,0 +1,9 @@ +
+ +
+ {{ form_errors(userForm.quicksight_user_role) }} + {{ form_widget(userForm.quicksight_user_role) }} +
+ {{ userForm.quicksight_user_role.vars.help | raw }} +
+
diff --git a/src/SprykerEco/data/translation/Zed/de_DE.csv b/src/SprykerEco/data/translation/Zed/de_DE.csv new file mode 100644 index 0000000..1fb5d01 --- /dev/null +++ b/src/SprykerEco/data/translation/Zed/de_DE.csv @@ -0,0 +1,3 @@ +"Author: A user who can create data sources, datasets, analyses, and dashboards.
Reader: A user who has read-only access to dashboards.","Autor: Ein Benutzer, der Datenquellen, Datensätze, Analysen und Dashboards erstellen kann.
Leser: Ein Benutzer, der nur Lesezugriff auf Dashboards hat." +"Choose user role","Benutzerrolle auswählen" +Analytics,Analytics diff --git a/src/SprykerEco/data/translation/Zed/en_US.csv b/src/SprykerEco/data/translation/Zed/en_US.csv new file mode 100644 index 0000000..48339c4 --- /dev/null +++ b/src/SprykerEco/data/translation/Zed/en_US.csv @@ -0,0 +1,3 @@ +"Author: A user who can create data sources, datasets, analyses, and dashboards.
Reader: A user who has read-only access to dashboards.","Author: A user who can create data sources, datasets, analyses, and dashboards.
Reader: A user who has read-only access to dashboards." +"Choose user role","Choose user role" +Analytics,Analytics From 2951d657b79a2aed2aca50ce441cfcdf82f6bd2a Mon Sep 17 00:00:00 2001 From: AntonKhabiuk Date: Mon, 5 Aug 2024 11:35:49 +0300 Subject: [PATCH 2/4] CC-34135 Update selector placeholder --- .../Communication/Expander/QuicksightUserFormExpander.php | 3 +-- src/SprykerEco/data/translation/Zed/de_DE.csv | 2 +- src/SprykerEco/data/translation/Zed/en_US.csv | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php index 3e9f187..50b1d2e 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php @@ -25,7 +25,7 @@ class QuicksightUserFormExpander implements QuicksightUserFormExpanderInterface /** * @var string */ - protected const PLACEHOLDER_QUICKSIGHT_USER_ROLE = 'Choose user role'; + protected const PLACEHOLDER_QUICKSIGHT_USER_ROLE = 'Select user role'; /** * @var string @@ -89,7 +89,6 @@ public function expandForm(FormBuilderInterface $builder): void $quicksightUserRole = $data[static::KEY_QUICKSIGHT_USER][static::KEY_ROLE] ?? null; $event->getForm()->add(static::FIELD_QUICKSIGHT_USER_ROLE, ChoiceType::class, [ - 'label' => static::PLACEHOLDER_QUICKSIGHT_USER_ROLE, 'required' => false, 'choices' => $this->getQuicksightUserRoleChoices(), 'placeholder' => static::PLACEHOLDER_QUICKSIGHT_USER_ROLE, diff --git a/src/SprykerEco/data/translation/Zed/de_DE.csv b/src/SprykerEco/data/translation/Zed/de_DE.csv index 1fb5d01..68ed01b 100644 --- a/src/SprykerEco/data/translation/Zed/de_DE.csv +++ b/src/SprykerEco/data/translation/Zed/de_DE.csv @@ -1,3 +1,3 @@ "Author: A user who can create data sources, datasets, analyses, and dashboards.
Reader: A user who has read-only access to dashboards.","Autor: Ein Benutzer, der Datenquellen, Datensätze, Analysen und Dashboards erstellen kann.
Leser: Ein Benutzer, der nur Lesezugriff auf Dashboards hat." -"Choose user role","Benutzerrolle auswählen" +"Select user role","Benutzerrolle auswählen" Analytics,Analytics diff --git a/src/SprykerEco/data/translation/Zed/en_US.csv b/src/SprykerEco/data/translation/Zed/en_US.csv index 48339c4..95d708d 100644 --- a/src/SprykerEco/data/translation/Zed/en_US.csv +++ b/src/SprykerEco/data/translation/Zed/en_US.csv @@ -1,3 +1,3 @@ "Author: A user who can create data sources, datasets, analyses, and dashboards.
Reader: A user who has read-only access to dashboards.","Author: A user who can create data sources, datasets, analyses, and dashboards.
Reader: A user who has read-only access to dashboards." -"Choose user role","Choose user role" +"Select user role","Select user role" Analytics,Analytics From 60a77f5d1a2219da4af89d0ac14ede48472033e9 Mon Sep 17 00:00:00 2001 From: AntonKhabiuk Date: Mon, 5 Aug 2024 14:22:38 +0300 Subject: [PATCH 3/4] CC-34135 Fixes after CR --- composer.json | 1 - .../data => data}/translation/Zed/de_DE.csv | 0 .../data => data}/translation/Zed/en_US.csv | 0 phpstan.neon | 1 - .../AmazonQuicksightConfig.php | 2 +- .../AmazonQuicksightDependencyProvider.php | 31 ----------- .../AmazonQuicksightCommunicationFactory.php | 14 ++--- .../QuicksightUserFormDataProvider.php | 51 ++++++++++++++++++ ...uicksightUserFormDataProviderInterface.php | 16 ++++++ .../Expander/QuicksightUserFormExpander.php | 53 +++++-------------- ...cksightUserRoleUserFormExpanderPlugin.php} | 2 +- .../QuicksightUserRoleDataTransformer.php | 3 ++ ...azonQuicksightToTranslatorFacadeBridge.php | 37 ------------- ...nQuicksightToTranslatorFacadeInterface.php | 21 -------- .../user-form-quicksight-user-role-field.twig | 2 +- 15 files changed, 94 insertions(+), 140 deletions(-) rename {src/SprykerEco/data => data}/translation/Zed/de_DE.csv (100%) rename {src/SprykerEco/data => data}/translation/Zed/en_US.csv (100%) create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProvider.php create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProviderInterface.php rename src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/{QuicksightUserFormExpanderPlugin.php => QuicksightUserRoleUserFormExpanderPlugin.php} (90%) delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeBridge.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeInterface.php diff --git a/composer.json b/composer.json index a30896f..ab0ddf2 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,6 @@ "php": ">=8.1", "spryker/kernel": "^3.30.0", "spryker/symfony": "^3.0.0", - "spryker/translator": "^1.1.0", "spryker/user": "^3.0.0", "spryker/user-extension": "^1.4.0", "spryker/uuid-behavior": "^1.0.0" diff --git a/src/SprykerEco/data/translation/Zed/de_DE.csv b/data/translation/Zed/de_DE.csv similarity index 100% rename from src/SprykerEco/data/translation/Zed/de_DE.csv rename to data/translation/Zed/de_DE.csv diff --git a/src/SprykerEco/data/translation/Zed/en_US.csv b/data/translation/Zed/en_US.csv similarity index 100% rename from src/SprykerEco/data/translation/Zed/en_US.csv rename to data/translation/Zed/en_US.csv diff --git a/phpstan.neon b/phpstan.neon index 0afe047..3260382 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,5 @@ parameters: level: 8 - checkGenericClassInNonGenericObjectType: false paths: - src/ excludePaths: diff --git a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php index 1a6167c..bbf82d3 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php @@ -31,7 +31,7 @@ class AmazonQuicksightConfig extends AbstractBundleConfig /** * Specification: * - Returns the list of available Quicksight user roles. - * - The list of available roles can be found here: {@link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_User.html#QS-Type-User-Role} + * - The list of available roles can be found here: {@link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_User.html#QS-Type-User-Role}. * * @api * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php index 6fa7bfd..32ea401 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php @@ -10,7 +10,6 @@ use Spryker\Zed\Kernel\AbstractBundleDependencyProvider; use Spryker\Zed\Kernel\Container; use SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientAdapter; -use SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeBridge; /** * @method \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig getConfig() @@ -22,11 +21,6 @@ class AmazonQuicksightDependencyProvider extends AbstractBundleDependencyProvide */ public const AWS_QUICKSIGHT_CLIENT = 'AWS_QUICKSIGHT_CLIENT'; - /** - * @var string - */ - public const FACADE_TRANSLATOR = 'FACADE_TRANSLATOR'; - /** * @param \Spryker\Zed\Kernel\Container $container * @@ -40,19 +34,6 @@ public function provideBusinessLayerDependencies(Container $container): Containe return $container; } - /** - * @param \Spryker\Zed\Kernel\Container $container - * - * @return \Spryker\Zed\Kernel\Container - */ - public function provideCommunicationLayerDependencies(Container $container): Container - { - $container = parent::provideCommunicationLayerDependencies($container); - $container = $this->addTranslatorFacade($container); - - return $container; - } - /** * @param \Spryker\Zed\Kernel\Container $container * @@ -68,16 +49,4 @@ protected function addAwsQuicksightClient(Container $container): Container return $container; } - - /** - * @return \Spryker\Zed\Kernel\Container - */ - protected function addTranslatorFacade(Container $container): Container - { - $container->set(static::FACADE_TRANSLATOR, function (Container $container) { - return new AmazonQuicksightToTranslatorFacadeBridge($container->getLocator()->translator()->facade()); - }); - - return $container; - } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php index d8cb1af..3c5b3c2 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php @@ -8,11 +8,11 @@ namespace SprykerEco\Zed\AmazonQuicksight\Communication; use Spryker\Zed\Kernel\Communication\AbstractCommunicationFactory; -use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightDependencyProvider; +use SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProvider; +use SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProviderInterface; use SprykerEco\Zed\AmazonQuicksight\Communication\Expander\QuicksightUserFormExpander; use SprykerEco\Zed\AmazonQuicksight\Communication\Expander\QuicksightUserFormExpanderInterface; use SprykerEco\Zed\AmazonQuicksight\Communication\Transformer\QuicksightUserRoleDataTransformer; -use SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeInterface; use Symfony\Component\Form\DataTransformerInterface; /** @@ -30,13 +30,13 @@ public function createQuicksightUserFormExpander(): QuicksightUserFormExpanderIn { return new QuicksightUserFormExpander( $this->createQuicksightUserRoleDataTransformer(), + $this->createQuicksightUserFormDataProvider(), $this->getConfig(), - $this->getTranslatorFacade(), ); } /** - * @return \Symfony\Component\Form\DataTransformerInterface + * @return \Symfony\Component\Form\DataTransformerInterface, array> */ public function createQuicksightUserRoleDataTransformer(): DataTransformerInterface { @@ -44,10 +44,10 @@ public function createQuicksightUserRoleDataTransformer(): DataTransformerInterf } /** - * @return \SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeInterface + * @return \SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProviderInterface */ - public function getTranslatorFacade(): AmazonQuicksightToTranslatorFacadeInterface + public function createQuicksightUserFormDataProvider(): QuicksightUserFormDataProviderInterface { - return $this->getProvidedDependency(AmazonQuicksightDependencyProvider::FACADE_TRANSLATOR); + return new QuicksightUserFormDataProvider($this->getConfig()); } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProvider.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProvider.php new file mode 100644 index 0000000..557b816 --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProvider.php @@ -0,0 +1,51 @@ +amazonQuicksightConfig = $amazonQuicksightConfig; + } + + /** + * @return array + */ + public function getQuicksightUserRoleChoices(): array + { + $quicksightUserRoles = $this->amazonQuicksightConfig->getQuicksightUserRoles(); + + return array_combine( + $this->formatQuicksightUserRoleChoiceLabels($quicksightUserRoles), + $quicksightUserRoles, + ); + } + + /** + * @param list $quicksightUserRoles + * + * @return list + */ + protected function formatQuicksightUserRoleChoiceLabels(array $quicksightUserRoles): array + { + return array_map(function ($quicksightUserRole) { + return ucfirst(strtolower($quicksightUserRole)); + }, $quicksightUserRoles); + } +} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProviderInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProviderInterface.php new file mode 100644 index 0000000..ff120ee --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProviderInterface.php @@ -0,0 +1,16 @@ + + */ + public function getQuicksightUserRoleChoices(): array; +} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php index 50b1d2e..cfed15a 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php @@ -8,7 +8,7 @@ namespace SprykerEco\Zed\AmazonQuicksight\Communication\Expander; use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig; -use SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeInterface; +use SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProviderInterface; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -30,7 +30,7 @@ class QuicksightUserFormExpander implements QuicksightUserFormExpanderInterface /** * @var string */ - protected const FIELD_QUICKSIGHT_USER_ROLE_HELP_MESSAGE = 'Author: A user who can create data sources, datasets, analyses, and dashboards.
Reader: A user who has read-only access to dashboards.'; + protected const HELP_MESSAGE_QUICKSIGHT_USER_ROLE = 'Author: A user who can create data sources, datasets, analyses, and dashboards.
Reader: A user who has read-only access to dashboards.'; /** * @var string @@ -48,33 +48,33 @@ class QuicksightUserFormExpander implements QuicksightUserFormExpanderInterface protected const KEY_ROLE = 'role'; /** - * @var \Symfony\Component\Form\DataTransformerInterface + * @var \Symfony\Component\Form\DataTransformerInterface, array> */ protected DataTransformerInterface $quicksightUserRoleDataTransformer; /** - * @var \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig + * @var \SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProviderInterface */ - protected AmazonQuicksightConfig $amazonQuicksightConfig; + protected QuicksightUserFormDataProviderInterface $quicksightUserFormDataProvider; /** - * @var \SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeInterface + * @var \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig */ - protected AmazonQuicksightToTranslatorFacadeInterface $translatorFacade; + protected AmazonQuicksightConfig $amazonQuicksightConfig; /** - * @param \Symfony\Component\Form\DataTransformerInterface $quicksightUserRoleDataTransformer + * @param \Symfony\Component\Form\DataTransformerInterface, array> $quicksightUserRoleDataTransformer + * @param \SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProviderInterface $quicksightUserFormDataProvider * @param \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig $amazonQuicksightConfig - * @param \SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToTranslatorFacadeInterface $translatorFacade */ public function __construct( DataTransformerInterface $quicksightUserRoleDataTransformer, - AmazonQuicksightConfig $amazonQuicksightConfig, - AmazonQuicksightToTranslatorFacadeInterface $translatorFacade + QuicksightUserFormDataProviderInterface $quicksightUserFormDataProvider, + AmazonQuicksightConfig $amazonQuicksightConfig ) { $this->quicksightUserRoleDataTransformer = $quicksightUserRoleDataTransformer; + $this->quicksightUserFormDataProvider = $quicksightUserFormDataProvider; $this->amazonQuicksightConfig = $amazonQuicksightConfig; - $this->translatorFacade = $translatorFacade; } /** @@ -90,41 +90,16 @@ public function expandForm(FormBuilderInterface $builder): void $event->getForm()->add(static::FIELD_QUICKSIGHT_USER_ROLE, ChoiceType::class, [ 'required' => false, - 'choices' => $this->getQuicksightUserRoleChoices(), + 'choices' => $this->quicksightUserFormDataProvider->getQuicksightUserRoleChoices(), 'placeholder' => static::PLACEHOLDER_QUICKSIGHT_USER_ROLE, 'attr' => [ 'template_path' => static::TEMPLATE_PATH_QUICKSIGHT_USER_ROLE, 'disabled' => $quicksightUserRole && !$this->amazonQuicksightConfig->isQuicksightUserRoleUpdateEnabled(), ], - 'help' => $this->translatorFacade->trans(static::FIELD_QUICKSIGHT_USER_ROLE_HELP_MESSAGE), + 'help' => static::HELP_MESSAGE_QUICKSIGHT_USER_ROLE, ]); }); $builder->addModelTransformer($this->quicksightUserRoleDataTransformer); } - - /** - * @return array - */ - protected function getQuicksightUserRoleChoices(): array - { - $quicksightUserRoles = $this->amazonQuicksightConfig->getQuicksightUserRoles(); - - return array_combine( - $this->formatQuicksightUserRoleChoiceLabels($quicksightUserRoles), - $quicksightUserRoles, - ); - } - - /** - * @param list $quicksightUserRoles - * - * @return list - */ - protected function formatQuicksightUserRoleChoiceLabels(array $quicksightUserRoles): array - { - return array_map(function ($quicksightUserRole) { - return ucfirst(strtolower($quicksightUserRole)); - }, $quicksightUserRoles); - } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserFormExpanderPlugin.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserRoleUserFormExpanderPlugin.php similarity index 90% rename from src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserFormExpanderPlugin.php rename to src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserRoleUserFormExpanderPlugin.php index 8a03dd0..279133b 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserFormExpanderPlugin.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserRoleUserFormExpanderPlugin.php @@ -16,7 +16,7 @@ * @method \SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacadeInterface getFacade() * @method \SprykerEco\Zed\AmazonQuicksight\Communication\AmazonQuicksightCommunicationFactory getFactory() */ -class QuicksightUserFormExpanderPlugin extends AbstractPlugin implements UserFormExpanderPluginInterface +class QuicksightUserRoleUserFormExpanderPlugin extends AbstractPlugin implements UserFormExpanderPluginInterface { /** * {@inheritDoc} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php index f611d42..eb49a85 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php @@ -9,6 +9,9 @@ use Symfony\Component\Form\DataTransformerInterface; +/** + * @implements \Symfony\Component\Form\DataTransformerInterface, array> + */ class QuicksightUserRoleDataTransformer implements DataTransformerInterface { /** diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeBridge.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeBridge.php deleted file mode 100644 index f6673fa..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeBridge.php +++ /dev/null @@ -1,37 +0,0 @@ -translatorFacade = $translatorFacade; - } - - /** - * @param string $id - * @param array $parameters - * @param string|null $domain - * @param string|null $locale - * - * @return string - */ - public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string - { - return $this->translatorFacade->trans($id, $parameters, $domain, $locale); - } -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeInterface.php deleted file mode 100644 index 2ada2fe..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToTranslatorFacadeInterface.php +++ /dev/null @@ -1,21 +0,0 @@ - $parameters - * @param string|null $domain - * @param string|null $locale - * - * @return string - */ - public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null): string; -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig index f9fe706..f3fc39d 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig @@ -4,6 +4,6 @@ {{ form_errors(userForm.quicksight_user_role) }} {{ form_widget(userForm.quicksight_user_role) }}
- {{ userForm.quicksight_user_role.vars.help | raw }} + {{ userForm.quicksight_user_role.vars.help | trans | raw }}
From a1f5042b0bed22ed9b725bd80314dfb988e1bb66 Mon Sep 17 00:00:00 2001 From: AntonKhabiuk Date: Mon, 5 Aug 2024 14:25:01 +0300 Subject: [PATCH 4/4] CC-34135 Adjust composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ab0ddf2..33090a1 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "spryker/kernel": "^3.30.0", "spryker/symfony": "^3.0.0", "spryker/user": "^3.0.0", - "spryker/user-extension": "^1.4.0", + "spryker/user-extension": "dev-master as 1.4.0", "spryker/uuid-behavior": "^1.0.0" }, "require-dev": {