Skip to content

Commit

Permalink
Merge branch 'feature/cc-34041/dev-quick-sight-mvp' into feature/cc-3…
Browse files Browse the repository at this point in the history
…4041/cc-34137-extend-user-transfer
  • Loading branch information
ilyakubanov committed Aug 5, 2024
2 parents 148bafc + d1acbd9 commit ff38ada
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 3 deletions.
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"aws/aws-sdk-php": "^3.90.0",
"php": ">=8.1",
"spryker/kernel": "^3.30.0",
"spryker/symfony": "^3.0.0",
"spryker/user": "^3.0.0",
"spryker/user-extension": "^1.2.0"
"spryker/user-extension": "dev-master as 1.4.0",
"spryker/uuid-behavior": "^1.0.0"
},
"require-dev": {
"spryker/code-sniffer": "*",
"spryker/testify": "*"
"phpstan/phpstan": "*",
"spryker/code-sniffer": "*"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions data/translation/Zed/de_DE.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Author: A user who can create data sources, datasets, analyses, and dashboards. <br/>Reader: A user who has read-only access to dashboards.","Autor: Ein Benutzer, der Datenquellen, Datensätze, Analysen und Dashboards erstellen kann. <br/>Leser: Ein Benutzer, der nur Lesezugriff auf Dashboards hat."
"Select user role","Benutzerrolle auswählen"
Analytics,Analytics
3 changes: 3 additions & 0 deletions data/translation/Zed/en_US.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Author: A user who can create data sources, datasets, analyses, and dashboards. <br/>Reader: A user who has read-only access to dashboards.","Author: A user who can create data sources, datasets, analyses, and dashboards. <br/>Reader: A user who has read-only access to dashboards."
"Select user role","Select user role"
Analytics,Analytics
40 changes: 40 additions & 0 deletions src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
*/
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.
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
namespace SprykerEco\Zed\AmazonQuicksight\Communication;

use Spryker\Zed\Kernel\Communication\AbstractCommunicationFactory;
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 Symfony\Component\Form\DataTransformerInterface;

/**
* @method \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig getConfig()
Expand All @@ -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->createQuicksightUserFormDataProvider(),
$this->getConfig(),
);
}

/**
* @return \Symfony\Component\Form\DataTransformerInterface<array<string, mixed>, array<string, mixed>>
*/
public function createQuicksightUserRoleDataTransformer(): DataTransformerInterface
{
return new QuicksightUserRoleDataTransformer();
}

/**
* @return \SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProviderInterface
*/
public function createQuicksightUserFormDataProvider(): QuicksightUserFormDataProviderInterface
{
return new QuicksightUserFormDataProvider($this->getConfig());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* MIT License
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider;

use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig;

class QuicksightUserFormDataProvider implements QuicksightUserFormDataProviderInterface
{
/**
* @var \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig
*/
protected AmazonQuicksightConfig $amazonQuicksightConfig;

/**
* @param \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig $amazonQuicksightConfig
*/
public function __construct(AmazonQuicksightConfig $amazonQuicksightConfig)
{
$this->amazonQuicksightConfig = $amazonQuicksightConfig;
}

/**
* @return array<string, string>
*/
public function getQuicksightUserRoleChoices(): array
{
$quicksightUserRoles = $this->amazonQuicksightConfig->getQuicksightUserRoles();

return array_combine(
$this->formatQuicksightUserRoleChoiceLabels($quicksightUserRoles),
$quicksightUserRoles,
);
}

/**
* @param list<string> $quicksightUserRoles
*
* @return list<string>
*/
protected function formatQuicksightUserRoleChoiceLabels(array $quicksightUserRoles): array
{
return array_map(function ($quicksightUserRole) {
return ucfirst(strtolower($quicksightUserRole));
}, $quicksightUserRoles);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/**
* MIT License
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider;

interface QuicksightUserFormDataProviderInterface
{
/**
* @return array<string, string>
*/
public function getQuicksightUserRoleChoices(): array;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

/**
* MIT License
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Zed\AmazonQuicksight\Communication\Expander;

use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig;
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;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

class QuicksightUserFormExpander implements QuicksightUserFormExpanderInterface
{
/**
* @var string
*/
protected const FIELD_QUICKSIGHT_USER_ROLE = 'quicksight_user_role';

/**
* @var string
*/
protected const PLACEHOLDER_QUICKSIGHT_USER_ROLE = 'Select user role';

/**
* @var string
*/
protected const HELP_MESSAGE_QUICKSIGHT_USER_ROLE = 'Author: A user who can create data sources, datasets, analyses, and dashboards. <br/>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<array<string, mixed>, array<string, mixed>>
*/
protected DataTransformerInterface $quicksightUserRoleDataTransformer;

/**
* @var \SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProviderInterface
*/
protected QuicksightUserFormDataProviderInterface $quicksightUserFormDataProvider;

/**
* @var \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig
*/
protected AmazonQuicksightConfig $amazonQuicksightConfig;

/**
* @param \Symfony\Component\Form\DataTransformerInterface<array<string, mixed>, array<string, mixed>> $quicksightUserRoleDataTransformer
* @param \SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProviderInterface $quicksightUserFormDataProvider
* @param \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig $amazonQuicksightConfig
*/
public function __construct(
DataTransformerInterface $quicksightUserRoleDataTransformer,
QuicksightUserFormDataProviderInterface $quicksightUserFormDataProvider,
AmazonQuicksightConfig $amazonQuicksightConfig
) {
$this->quicksightUserRoleDataTransformer = $quicksightUserRoleDataTransformer;
$this->quicksightUserFormDataProvider = $quicksightUserFormDataProvider;
$this->amazonQuicksightConfig = $amazonQuicksightConfig;
}

/**
* @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, [
'required' => false,
'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' => static::HELP_MESSAGE_QUICKSIGHT_USER_ROLE,
]);
});

$builder->addModelTransformer($this->quicksightUserRoleDataTransformer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* MIT License
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Zed\AmazonQuicksight\Communication\Expander;

use Symfony\Component\Form\FormBuilderInterface;

interface QuicksightUserFormExpanderInterface
{
/**
* @param \Symfony\Component\Form\FormBuilderInterface<string, \Symfony\Component\Form\FormBuilderInterface> $builder
*
* @return void
*/
public function expandForm(FormBuilderInterface $builder): void;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* MIT License
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace SprykerEco\Zed\AmazonQuicksight\Communication\Plugin\User;

use Spryker\Zed\Kernel\Communication\AbstractPlugin;
use Spryker\Zed\UserExtension\Dependency\Plugin\UserFormExpanderPluginInterface;
use Symfony\Component\Form\FormBuilderInterface;

/**
* @method \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig getConfig()
* @method \SprykerEco\Zed\AmazonQuicksight\Business\AmazonQuicksightFacadeInterface getFacade()
* @method \SprykerEco\Zed\AmazonQuicksight\Communication\AmazonQuicksightCommunicationFactory getFactory()
*/
class QuicksightUserRoleUserFormExpanderPlugin extends AbstractPlugin implements UserFormExpanderPluginInterface
{
/**
* {@inheritDoc}
* - Expands user form with Quicksight user role field.
*
* @api
*
* @param \Symfony\Component\Form\FormBuilderInterface $builder
*
* @return void
*/
public function buildForm(FormBuilderInterface $builder): void
{
$this->getFactory()
->createQuicksightUserFormExpander()
->expandForm($builder);
}
}
Loading

0 comments on commit ff38ada

Please sign in to comment.