diff --git a/README.md b/README.md index 41adad7..540a5fc 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ AmazonQuicksight module allows the Spryker project to connect to the Amazon QuickSight service. -**DEPRECATED - Invalid Release. Please skip this version. Use the latest version instead.** - ## Installation ``` diff --git a/assets/Zed/js/modules/quicksight-analytics.js b/assets/Zed/js/modules/quicksight-analytics.js index cff0aa7..817e1e8 100644 --- a/assets/Zed/js/modules/quicksight-analytics.js +++ b/assets/Zed/js/modules/quicksight-analytics.js @@ -22,7 +22,6 @@ $(document).ready(function () { const frameOptions = { url: embedUrl, container: embedElement, - height: '700px', width: '100%', onChange: (changeEvent, metadata) => { switch (changeEvent.eventName) { diff --git a/data/translation/Zed/de_DE.csv b/data/translation/Zed/de_DE.csv index 82c77bd..5b38d75 100644 --- a/data/translation/Zed/de_DE.csv +++ b/data/translation/Zed/de_DE.csv @@ -1,14 +1,20 @@ "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." "Select user role","Benutzerrolle auswählen" Analytics,Analytics -"The user role for Analytics could not be set. Please try again later.","Die Benutzerrolle für Analytics konnte nicht eingerichtet werden. Bitte versuchen Sie es später noch einmal." "The user role for Analytics could not be reset. Please contact your Spryker Success Manager.","Die Benutzerrolle für Analytics konnte nicht zurückgesetzt werden. Bitte kontaktieren Sie Ihren Spryker Success Manager." "Please be aware that you will be the owner of all default assets (dashboards, analyses, datasets and data sources).","Bitte beachten Sie, dass Sie als Eigentümer aller Standard-Assets (Dashboards, Analysen, Datensätzen und Datenquellen) eingetragen werden." -"Please be aware that all Analytics dashboards and configurations, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon reset process. Owner of default assets will be replaced with the user who initiated the reset process by clicking this button.","Bitte beachten Sie, dass alle Dashboards und Konfigurationen, einschließlich Ihrer Änderungen, zurückgesetzt und durch die Analytics-Standarddaten ersetzt werden. Also, all users will be detached from assets upon reset process. Owner of default assets will be replaced with the user who initiated the reset process by clicking this button." +"If you want to start fresh with a new setup in Analytics, keep these critical points in mind:","Wenn Sie Analytics neu einrichten möchten, sollten Sie die folgenden Punkte beachten:" +"Resetting Analytics restores all default assets (dashboards, analyses, datasets) to their original state, erasing any modifications you've made.","Beim Zurücksetzen von Analytics werden alle Standard-Assets (Dashboards, Analysen, Datensätze) auf ihren ursprünglichen Zustand zurückgesetzt. Dabei gehen sämtliche von Ihnen vorgenommenen Änderungen verloren." +"The user performing the reset becomes the owner of the default assets, and all other users lose access to them.","Der Benutzer, der das Zurücksetzen durchführt, wird automatisch zum Eigentümer der Standard-Assets, während alle anderen Benutzer den Zugriff darauf verlieren." +"Custom assets created by other users remain under their ownership.","Von anderen Benutzern erstellte benutzerdefinierte Assets bleiben in deren Besitz und sind nicht betroffen." +"IMPORTANT: If you or other authors use default datasets in custom analyses, such analyses won't be able to access data for all visuals. To avoid this, duplicate the relevant default datasets and associate them with the custom analyses before proceeding.","WICHTIG: Wenn Sie oder andere Autoren Standard-Datensätze in benutzerdefinierten Analysen verwenden, können diese Analysen nach dem Zurücksetzen nicht mehr auf alle benötigten Daten für alle Visualisierungen zugreifen. Um dies zu verhindern, sollten Sie die relevanten Standard-Datensätze vorab duplizieren und mit den benutzerdefinierten Analysen verknüpfen." "An error occurred during the Analytics activation. Please try again by clicking the ""Enable Analytics"" button.","Bei der Aktivierung von Analytics ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut, indem Sie auf die Taste ""Analytics aktivieren"" klicken." "An error occurred during the Analytics reset. Please try again by clicking the ""Reset Analytics"" button.","Beim Zurücksetzen von Analytics ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut, indem Sie auf die Taste ""Analytics zurücksetzen"" klicken." -"Spryker Analytics is not enabled yet","Spryker Analytics ist noch nicht eingeschaltet" -"You can enable Spryker Analytics to view and modify default dashboards with the ability to share them with other users.","Schalten Sie Spryker Analytics ein, um Standard-Dashboards anzuzeigen, zu bearbeiten und mit anderen Benutzern zu teilen." +"Analytics is not enabled yet","Analytics ist noch nicht eingeschaltet" +"You can enable Analytics to view and modify dashboards with the ability to share them with other users.","Schalten Sie Analytics ein, um Dashboards anzuzeigen, zu bearbeiten und mit anderen Benutzern zu teilen." "Enable Analytics","Analytics einschalten" "Reset Analytics","Analytics zurücksetzen" -"Spryker Analytics is being activated. Please wait 4-5 minutes and reload the page.","Spryker Analytics wird aktiviert. Bitte warten Sie 4-5 Minuten und laden Sie die Seite neu." +"Analytics is being activated. Please wait 3-5 minutes and reload the page.","Analytics wird aktiviert. Bitte warten Sie 3-5 Minuten und laden Sie die Seite neu." +"Analytics users have been successfully synchronized.","Analytics-Benutzer wurden erfolgreich synchronisiert." +"Synchronize Users","Benutzer synchronisieren" +"CSRF token is not valid.","CSRF-Token ist ungültig." diff --git a/data/translation/Zed/en_US.csv b/data/translation/Zed/en_US.csv index 465fc56..5f5725f 100644 --- a/data/translation/Zed/en_US.csv +++ b/data/translation/Zed/en_US.csv @@ -1,14 +1,20 @@ "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." "Select user role","Select user role" Analytics,Analytics -"The user role for Analytics could not be set. Please try again later.","The user role for Analytics could not be set. Please try again later." "The user role for Analytics could not be reset. Please contact your Spryker Success Manager.","The user role for Analytics could not be reset. Please contact your Spryker Success Manager." "Please be aware that you will be the owner of all default assets (dashboards, analyses, datasets and data sources).","Please be aware that you will be the owner of all default assets (dashboards, analyses, datasets and data sources)." -"Please be aware that all Analytics dashboards and configurations, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon reset process. Owner of default assets will be replaced with the user who initiated the reset process by clicking this button.","Please be aware that all Analytics dashboards and configurations, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon reset process. Owner of default assets will be replaced with the user who initiated the reset process by clicking this button." +"If you want to start fresh with a new setup in Analytics, keep these critical points in mind:","If you want to start fresh with a new setup in Analytics, keep these critical points in mind:" +"Resetting Analytics restores all default assets (dashboards, analyses, datasets) to their original state, erasing any modifications you\'ve made.","Resetting Analytics restores all default assets (dashboards, analyses, datasets) to their original state, erasing any modifications you\'ve made." +"The user performing the reset becomes the owner of the default assets, and all other users lose access to them.","The user performing the reset becomes the owner of the default assets, and all other users lose access to them." +"Custom assets created by other users remain under their ownership.","Custom assets created by other users remain under their ownership." +"IMPORTANT: If you or other authors use default datasets in custom analyses, such analyses won\'t be able to access data for all visuals. To avoid this, duplicate the relevant default datasets and associate them with the custom analyses before proceeding.","IMPORTANT: If you or other authors use default datasets in custom analyses, such analyses won\'t be able to access data for all visuals. To avoid this, duplicate the relevant default datasets and associate them with the custom analyses before proceeding." "An error occurred during the Analytics activation. Please try again by clicking the ""Enable Analytics"" button.","An error occurred during the Analytics activation. Please try again by clicking the ""Enable Analytics"" button." "An error occurred during the Analytics reset. Please try again by clicking the ""Reset Analytics"" button.","An error occurred during the Analytics reset. Please try again by clicking the ""Reset Analytics"" button." -"Spryker Analytics is not enabled yet","Spryker Analytics is not enabled yet" -"You can enable Spryker Analytics to view and modify default dashboards with the ability to share them with other users.","You can enable Spryker Analytics to view and modify default dashboards with the ability to share them with other users." +"Analytics is not enabled yet","Analytics is not enabled yet" +"You can enable Analytics to view and modify dashboards with the ability to share them with other users.","You can enable Analytics to view and modify dashboards with the ability to share them with other users." "Enable Analytics","Enable Analytics" "Reset Analytics","Reset Analytics" -"Spryker Analytics is being activated. Please wait 4-5 minutes and reload the page.","Spryker Analytics is being activated. Please wait 4-5 minutes and reload the page." +"Analytics is being activated. Please wait 3-5 minutes and reload the page.","Analytics is being activated. Please wait 3-5 minutes and reload the page." +"Analytics users have been successfully synchronized.","Analytics users have been successfully synchronized." +"Synchronize Users","Synchronize Users" +"CSRF token is not valid.","CSRF token is not valid." diff --git a/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml b/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml index 2c0405c..00b60d5 100644 --- a/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml +++ b/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml @@ -43,25 +43,11 @@ - - - - - - - - - - - - - - @@ -266,19 +252,6 @@ - - - - - - - - - - - - - diff --git a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php index 9134716..423e2b5 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightConfig.php @@ -281,19 +281,6 @@ public function findAwsCredentialsToken(): ?string : null; } - /** - * Specification: - * - Defines if updating quicksight user role via user form is enabled. - * - * @api - * - * @return bool - */ - public function isQuicksightUserRoleUpdateEnabled(): bool - { - return false; - } - /** * Specification: * - Provides the starting path for the QuickSight console. diff --git a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php index ebc7c54..8fdf655 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/AmazonQuicksightDependencyProvider.php @@ -46,6 +46,13 @@ class AmazonQuicksightDependencyProvider extends AbstractBundleDependencyProvide */ public const SERVICE_TWIG = 'twig'; + /** + * @uses \Spryker\Yves\Form\Plugin\Application\FormApplicationPlugin::SERVICE_FORM_CSRF_PROVIDER + * + * @var string + */ + public const SERVICE_FORM_CSRF_PROVIDER = 'form.csrf_provider'; + /** * @param \Spryker\Zed\Kernel\Container $container * @@ -71,6 +78,7 @@ public function provideCommunicationLayerDependencies(Container $container): Con { $container = parent::provideCommunicationLayerDependencies($container); $container = $this->addUserFacade($container); + $container = $this->addFormCsrfProviderService($container); return $container; } @@ -161,4 +169,18 @@ protected function addUtilEncodingService(Container $container): Container return $container; } + + /** + * @param \Spryker\Zed\Kernel\Container $container + * + * @return \Spryker\Zed\Kernel\Container + */ + protected function addFormCsrfProviderService(Container $container): Container + { + $container->set(static::SERVICE_FORM_CSRF_PROVIDER, function (Container $container) { + return $container->getApplicationService(static::SERVICE_FORM_CSRF_PROVIDER); + }); + + return $container; + } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Adder/ErrorAdder.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Adder/ErrorAdder.php index 83fdf56..b8a4f6a 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Adder/ErrorAdder.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Adder/ErrorAdder.php @@ -8,7 +8,6 @@ namespace SprykerEco\Zed\AmazonQuicksight\Business\Adder; use ArrayObject; -use Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer; use Generated\Shared\Transfer\UserCollectionResponseTransfer; class ErrorAdder implements ErrorAdderInterface @@ -32,21 +31,4 @@ public function addErrorsToUserCollectionResponse( return $userCollectionResponseTransfer; } - - /** - * @param \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer $quicksightUserCollectionResponseTransfer - * @param \ArrayObject $errorTransfers - * - * @return \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer - */ - public function addErrorsToQuicksightUserCollectionResponse( - QuicksightUserCollectionResponseTransfer $quicksightUserCollectionResponseTransfer, - ArrayObject $errorTransfers - ): QuicksightUserCollectionResponseTransfer { - foreach ($errorTransfers as $errorTransfer) { - $quicksightUserCollectionResponseTransfer->addError($errorTransfer); - } - - return $quicksightUserCollectionResponseTransfer; - } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Adder/ErrorAdderInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Adder/ErrorAdderInterface.php index 5e66762..4327236 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Adder/ErrorAdderInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Adder/ErrorAdderInterface.php @@ -8,7 +8,6 @@ namespace SprykerEco\Zed\AmazonQuicksight\Business\Adder; use ArrayObject; -use Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer; use Generated\Shared\Transfer\UserCollectionResponseTransfer; interface ErrorAdderInterface @@ -25,15 +24,4 @@ public function addErrorsToUserCollectionResponse( ArrayObject $errorTransfers, string $entityIdentifier ): UserCollectionResponseTransfer; - - /** - * @param \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer $quicksightUserCollectionResponseTransfer - * @param \ArrayObject $errorTransfers - * - * @return \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer - */ - public function addErrorsToQuicksightUserCollectionResponse( - QuicksightUserCollectionResponseTransfer $quicksightUserCollectionResponseTransfer, - ArrayObject $errorTransfers - ): QuicksightUserCollectionResponseTransfer; } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightBusinessFactory.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightBusinessFactory.php index 10e969d..2279ac8 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightBusinessFactory.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightBusinessFactory.php @@ -41,8 +41,6 @@ use SprykerEco\Zed\AmazonQuicksight\Business\Mapper\AmazonQuicksightMapperInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Matcher\QuicksightUserMatcher; use SprykerEco\Zed\AmazonQuicksight\Business\Matcher\QuicksightUserMatcherInterface; -use SprykerEco\Zed\AmazonQuicksight\Business\Processor\AssetBundleQuicksightUserProcessor; -use SprykerEco\Zed\AmazonQuicksight\Business\Processor\AssetBundleQuicksightUserProcessorInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Reader\QuicksightUserReader; use SprykerEco\Zed\AmazonQuicksight\Business\Reader\QuicksightUserReaderInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Reader\UserReader; @@ -51,8 +49,6 @@ use SprykerEco\Zed\AmazonQuicksight\Business\Synchronizer\QuicksightAssetBundleImportJobSynchronizerInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Updater\QuicksightAssetBundleImportJobUpdater; use SprykerEco\Zed\AmazonQuicksight\Business\Updater\QuicksightAssetBundleImportJobUpdaterInterface; -use SprykerEco\Zed\AmazonQuicksight\Business\Updater\QuicksightUserUpdater; -use SprykerEco\Zed\AmazonQuicksight\Business\Updater\QuicksightUserUpdaterInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Validator\QuicksightAnalyticsRequestValidator; use SprykerEco\Zed\AmazonQuicksight\Business\Validator\QuicksightAnalyticsRequestValidatorInterface; use SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface; @@ -90,14 +86,6 @@ public function createQuicksightUserCreator(): QuicksightUserCreatorInterface ); } - /** - * @return \SprykerEco\Zed\AmazonQuicksight\Business\Updater\QuicksightUserUpdaterInterface - */ - public function createQuicksightUserUpdater(): QuicksightUserUpdaterInterface - { - return new QuicksightUserUpdater($this->createUserAmazonQuicksightApiClient(), $this->getEntityManager()); - } - /** * @return \SprykerEco\Zed\AmazonQuicksight\Business\Deleter\QuicksightUserDeleterInterface */ @@ -238,24 +226,11 @@ public function createAssetBundleEnabler(): AssetBundleEnablerInterface $this->createQuicksightAssetBundleImportJobUpdater(), $this->getRepository(), $this->createQuicksightAnalyticsRequestValidator(), - $this->createAssetBundleQuicksightUserProcessor(), $this->createAssetBundleImportFileContentLoader(), $this->createDataSetDeleter(), ); } - /** - * @return \SprykerEco\Zed\AmazonQuicksight\Business\Processor\AssetBundleQuicksightUserProcessorInterface - */ - public function createAssetBundleQuicksightUserProcessor(): AssetBundleQuicksightUserProcessorInterface - { - return new AssetBundleQuicksightUserProcessor( - $this->createQuicksightUserCreator(), - $this->createQuicksightUserUpdater(), - $this->getRepository(), - ); - } - /** * @return \SprykerEco\Zed\AmazonQuicksight\Business\Synchronizer\QuicksightAssetBundleImportJobSynchronizerInterface */ diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php index 1d1e27c..18bff2d 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php @@ -40,23 +40,6 @@ public function expandUserCollectionWithQuicksightUsers( return $this->getFactory()->createUserExpander()->expandUserCollectionWithQuicksightUsers($userCollectionTransfer); } - /** - * {@inheritDoc} - * - * @api - * - * @param \Generated\Shared\Transfer\UserCollectionResponseTransfer $userCollectionResponseTransfer - * - * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer - */ - public function createQuicksightUsersByUserCollectionResponse( - UserCollectionResponseTransfer $userCollectionResponseTransfer - ): UserCollectionResponseTransfer { - return $this->getFactory() - ->createQuicksightUserCreator() - ->createQuicksightUsersByUserCollectionResponse($userCollectionResponseTransfer); - } - /** * {@inheritDoc} * @@ -107,20 +90,6 @@ public function createMatchedQuicksightUsers(): QuicksightUserCollectionResponse ->createMatchedQuicksightUsers(); } - /** - * {@inheritDoc} - * - * @api - * - * @return \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer - */ - public function deleteNotMatchedQuicksightUsers(): QuicksightUserCollectionResponseTransfer - { - return $this->getFactory() - ->createQuicksightUserDeleter() - ->deleteNotMatchedQuicksightUsers(); - } - /** * {@inheritDoc} * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php index d3e3f35..745bc56 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php @@ -36,28 +36,6 @@ public function expandUserCollectionWithQuicksightUsers( UserCollectionTransfer $userCollectionTransfer ): UserCollectionTransfer; - /** - * Specification: - * - Expects `UserCollectionResponseTransfer.users.quicksightUser.role` to be set. - * - Filters out users if `UserTransfer.quicksightUser.role` is not set. - * - Filters out users with already persisted Quicksight user. - * - Filters out users with statuses not applicable for registering a Quicksight user. - * - Uses {@link \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig::getUserStatusesApplicableForQuicksightUserRegistration()} to get a list of user statuses applicable for registering a Quicksight user. - * - Sends request to AWS API to register Quicksight users. For more information see {@link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RegisterUser.html}. - * - Adds errors to `UserCollectionResponseTransfer.errors` if Quicksight user registration failed. - * - Persists successfully registered Quicksight users to persistence. - * - Returns `UserCollectionResponseTransfer` with updated `UserTransfers`. - * - * @api - * - * @param \Generated\Shared\Transfer\UserCollectionResponseTransfer $userCollectionResponseTransfer - * - * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer - */ - public function createQuicksightUsersByUserCollectionResponse( - UserCollectionResponseTransfer $userCollectionResponseTransfer - ): UserCollectionResponseTransfer; - /** * Specification: * - Filters out users with statuses not applicable for deleting a Quicksight user. @@ -86,6 +64,7 @@ public function deleteQuicksightUsersByUserCollectionResponse( * - Renders a Quicksight analytics template. * - Creates `AnalyticsTransfer` and populates `AnalyticsTransfer.content` with the rendered content. * - Adds the newly introduced `AnalyticsTransfer` to `AnalyticsCollectionTransfer.analyticsList`. + * - Expands `AnalyticsCollectionTransfer.analyticsActions` with the synchronize Quicksight users action. * - If the provided user is allowed to reset the Analytics expands `AnalyticsCollectionTransfer.analyticsActions` with the reset action. * * @api @@ -117,30 +96,12 @@ public function expandAnalyticsCollectionWithQuicksightAnalytics( */ public function createMatchedQuicksightUsers(): QuicksightUserCollectionResponseTransfer; - /** - * Specification: - * - Sends request to AWS API to get list of registered Quicksight users. For more information see {@link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ListUsers.html}. - * - Filters out Quicksight users with unsupported roles using {@link \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig::getQuicksightUserRoles()}. - * - Fetches user transfers from persistence. - * - Finds registered on Quicksight side Quicksight users not matched with users from persistence. - * - Sends request to AWS API to delete Quicksight users. For more information see {@link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_DeleteUserByPrincipalId.html}. - * - Adds errors to `QuicksightUserCollectionResponseTransfer.errors` if any occurs. - * - Returns `QuicksightUserCollectionResponseTransfer` with deleted Quicksight users and errors if any occurs. - * - * @api - * - * @return \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer - */ - public function deleteNotMatchedQuicksightUsers(): QuicksightUserCollectionResponseTransfer; - /** * Specification: * - Requires `EnableQuicksightAnalyticsRequestTransfer.assetBundleImportJobId` to be set. * - Requires `EnableQuicksightAnalyticsRequestTransfer.user` to be set. * - Validates whether Analytics can be enabled and populates `EnableQuicksightAnalyticsResponseTransfer.errors` with errors encountered during the validation. * - If validation fails, Analytics will not be enabled and `EnableQuicksightAnalyticsResponseTransfer` will be returned. - * - If current user is not a Quicksight user, creates a new Quicksight user with AUTHOR role. - * - If current user is a Quicksight user with READER role, upgrades the user to AUTHOR. * - Starts the asset bundle import job for a file located at the path specified by {@link \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig::getAssetBundleImportFilePath()} to Quicksight. * - Throws {@link \SprykerEco\Zed\AmazonQuicksight\Business\Exception\AssetBundleImportFilePathNotDefinedException} if the path is not specified. * - Saves asset bundle import job to persistence and populates `EnableQuicksightAnalyticsResponseTransfer.quicksightAssetBundleImportJob` if the import job started successfully. diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php index 0763702..80a0fd4 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php @@ -17,10 +17,6 @@ use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer; use Generated\Shared\Transfer\QuicksightListUsersRequestTransfer; use Generated\Shared\Transfer\QuicksightListUsersResponseTransfer; -use Generated\Shared\Transfer\QuicksightUpdateUserRequestTransfer; -use Generated\Shared\Transfer\QuicksightUpdateUserResponseTransfer; -use Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer; -use Generated\Shared\Transfer\QuicksightUserRegisterResponseTransfer; use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\UserTransfer; use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig; @@ -35,13 +31,6 @@ class UserAmazonQuicksightApiClient implements UserAmazonQuicksightApiClientInte */ protected const QUICKSIGHT_USER_IDENTITY_TYPE = 'QUICKSIGHT'; - /** - * @link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_RegisterUser.html#API_RegisterUser_ResponseSyntax - * - * @var string - */ - protected const RESPONSE_KEY_USER = 'User'; - /** * @link https://docs.aws.amazon.com/quicksight/latest/APIReference/API_ListUsers.html#QS-ListUsers-response-UserList * @@ -63,11 +52,6 @@ class UserAmazonQuicksightApiClient implements UserAmazonQuicksightApiClientInte */ protected const RESPONSE_KEY_EMBED_URL = 'EmbedUrl'; - /** - * @var string - */ - protected const ERROR_MESSAGE_USER_REGISTRATION_FAILED = 'Failed to register Quicksight user.'; - /** * @var string */ @@ -78,11 +62,6 @@ class UserAmazonQuicksightApiClient implements UserAmazonQuicksightApiClientInte */ protected const ERROR_MESSAGE_USERS_LIST_RETRIEVE_FAILED = 'Failed to retrieve users list.'; - /** - * @var string - */ - protected const ERROR_MESSAGE_USER_UPDATING_FAILED = 'Failed to update Quicksight user.'; - /** * @var \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig */ @@ -121,46 +100,6 @@ public function __construct( $this->amazonQuicksightToAwsQuicksightClient = $amazonQuicksightToAwsQuicksightClient; } - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUserRegisterResponseTransfer - */ - public function registerUser(UserTransfer $userTransfer): QuicksightUserRegisterResponseTransfer - { - $quicksightUserRegisterRequestTransfer = $this->createQuicksightUserRegisterRequestTransfer(); - $quicksightUserRegisterRequestTransfer = $this->amazonQuicksightMapper->mapUserTransferToQuicksightUserRegisterRequestTransfer( - $userTransfer, - $quicksightUserRegisterRequestTransfer, - ); - - $requestData = $this->amazonQuicksightRequestDataFormatter->formatRequestData( - $quicksightUserRegisterRequestTransfer->toArray(true, true), - ); - - $quicksightUserRegisterResponseTransfer = new QuicksightUserRegisterResponseTransfer(); - try { - $response = $this->amazonQuicksightToAwsQuicksightClient->registerUser($requestData); - } catch (QuickSightException $quickSightException) { - return $quicksightUserRegisterResponseTransfer->addError( - (new ErrorTransfer())->setMessage($quickSightException->getAwsErrorMessage()), - ); - } - - if (!$response->hasKey(static::RESPONSE_KEY_USER)) { - return $quicksightUserRegisterResponseTransfer->addError( - (new ErrorTransfer())->setMessage(static::ERROR_MESSAGE_USER_REGISTRATION_FAILED), - ); - } - - $quicksightUserTransfer = $this->amazonQuicksightMapper->mapQuicksightUserDataToQuicksightUserTransfer( - $response->get(static::RESPONSE_KEY_USER), - $userTransfer->getQuicksightUserOrFail(), - ); - - return $quicksightUserRegisterResponseTransfer->setQuicksightUser($quicksightUserTransfer); - } - /** * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer * @@ -202,35 +141,6 @@ public function generateEmbedUrlForRegisteredUser( ); } - /** - * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer - * - * @return \Generated\Shared\Transfer\QuicksightDeleteUserResponseTransfer - */ - public function deleteUserByPrincipalId(QuicksightUserTransfer $quicksightUserTransfer): QuicksightDeleteUserResponseTransfer - { - $quicksightUserDeleteRequestTransfer = $this->createQuicksightUserDeleteRequestTransfer(); - $quicksightUserDeleteRequestTransfer = $this->amazonQuicksightMapper->mapQuicksightUserTransferToQuicksightDeleteUserRequestTransfer( - $quicksightUserTransfer, - $quicksightUserDeleteRequestTransfer, - ); - - $requestData = $this->amazonQuicksightRequestDataFormatter->formatRequestData( - $quicksightUserDeleteRequestTransfer->toArray(true, true), - ); - - $quicksightDeleteUserResponseTransfer = new QuicksightDeleteUserResponseTransfer(); - try { - $this->amazonQuicksightToAwsQuicksightClient->deleteUserByPrincipalId($requestData); - } catch (QuickSightException $quickSightException) { - return $quicksightDeleteUserResponseTransfer->addError( - (new ErrorTransfer())->setMessage($quickSightException->getAwsErrorMessage()), - ); - } - - return $quicksightDeleteUserResponseTransfer; - } - /** * @param \Generated\Shared\Transfer\UserTransfer $userTransfer * @@ -305,59 +215,6 @@ public function listUsers(): QuicksightListUsersResponseTransfer return $quicksightListUsersResponseTransfer; } - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUpdateUserResponseTransfer - */ - public function updateUser(UserTransfer $userTransfer): QuicksightUpdateUserResponseTransfer - { - $quicksightUpdateUserRequestTransfer = $this->createQuicksightUpdateUserRequestTransfer(); - $quicksightUpdateUserRequestTransfer = $this->amazonQuicksightMapper - ->mapUserTransferToQuicksightUpdateUserRequestTransfer( - $userTransfer, - $quicksightUpdateUserRequestTransfer, - ); - - $requestData = $this->amazonQuicksightRequestDataFormatter->formatRequestData( - $quicksightUpdateUserRequestTransfer->toArray(true, true), - ); - - $quicksightUpdateUserResponseTransfer = new QuicksightUpdateUserResponseTransfer(); - - try { - $response = $this->amazonQuicksightToAwsQuicksightClient->updateUser($requestData); - } catch (QuickSightException $quickSightException) { - return $quicksightUpdateUserResponseTransfer->addError( - (new ErrorTransfer())->setMessage($quickSightException->getAwsErrorMessage()), - ); - } - - if (!$response->hasKey(static::RESPONSE_KEY_USER)) { - return $quicksightUpdateUserResponseTransfer->addError( - (new ErrorTransfer())->setMessage(static::ERROR_MESSAGE_USER_UPDATING_FAILED), - ); - } - - $quicksightUserTransfer = $this->amazonQuicksightMapper->mapQuicksightUserDataToQuicksightUserTransfer( - $response->get(static::RESPONSE_KEY_USER), - $userTransfer->getQuicksightUserOrFail(), - ); - - return $quicksightUpdateUserResponseTransfer->setQuicksightUser($quicksightUserTransfer); - } - - /** - * @return \Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer - */ - protected function createQuicksightUserRegisterRequestTransfer(): QuicksightUserRegisterRequestTransfer - { - return (new QuicksightUserRegisterRequestTransfer()) - ->setIdentityType(static::QUICKSIGHT_USER_IDENTITY_TYPE) - ->setAwsAccountId($this->amazonQuicksightConfig->getAwsAccountId()) - ->setNamespace($this->amazonQuicksightConfig->getAwsQuicksightNamespace()); - } - /** * @return \Generated\Shared\Transfer\QuicksightGenerateEmbedUrlRequestTransfer */ @@ -392,14 +249,4 @@ protected function createQuicksightListUsersRequestDataTransfer(): QuicksightLis ->setAwsAccountId($this->amazonQuicksightConfig->getAwsAccountId()) ->setNamespace($this->amazonQuicksightConfig->getAwsQuicksightNamespace()); } - - /** - * @return \Generated\Shared\Transfer\QuicksightUpdateUserRequestTransfer - */ - protected function createQuicksightUpdateUserRequestTransfer(): QuicksightUpdateUserRequestTransfer - { - return (new QuicksightUpdateUserRequestTransfer()) - ->setAwsAccountId($this->amazonQuicksightConfig->getAwsAccountId()) - ->setNamespace($this->amazonQuicksightConfig->getAwsQuicksightNamespace()); - } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php index 19c78b9..6ef7e84 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php @@ -10,20 +10,11 @@ use Generated\Shared\Transfer\QuicksightDeleteUserResponseTransfer; use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer; use Generated\Shared\Transfer\QuicksightListUsersResponseTransfer; -use Generated\Shared\Transfer\QuicksightUpdateUserResponseTransfer; -use Generated\Shared\Transfer\QuicksightUserRegisterResponseTransfer; use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\UserTransfer; interface UserAmazonQuicksightApiClientInterface { - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUserRegisterResponseTransfer - */ - public function registerUser(UserTransfer $userTransfer): QuicksightUserRegisterResponseTransfer; - /** * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer * @@ -33,13 +24,6 @@ public function generateEmbedUrlForRegisteredUser( QuicksightUserTransfer $quicksightUserTransfer ): QuicksightGenerateEmbedUrlResponseTransfer; - /** - * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer - * - * @return \Generated\Shared\Transfer\QuicksightDeleteUserResponseTransfer - */ - public function deleteUserByPrincipalId(QuicksightUserTransfer $quicksightUserTransfer): QuicksightDeleteUserResponseTransfer; - /** * @param \Generated\Shared\Transfer\UserTransfer $userTransfer * @@ -51,11 +35,4 @@ public function deleteUserByUsername(UserTransfer $userTransfer): QuicksightDele * @return \Generated\Shared\Transfer\QuicksightListUsersResponseTransfer */ public function listUsers(): QuicksightListUsersResponseTransfer; - - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUpdateUserResponseTransfer - */ - public function updateUser(UserTransfer $userTransfer): QuicksightUpdateUserResponseTransfer; } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreator.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreator.php index a9eebbc..545c23d 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreator.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreator.php @@ -8,9 +8,7 @@ namespace SprykerEco\Zed\AmazonQuicksight\Business\Creator; use ArrayObject; -use Generated\Shared\Transfer\MessageTransfer; use Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer; -use Generated\Shared\Transfer\UserCollectionResponseTransfer; use Spryker\Zed\Kernel\Persistence\EntityManager\TransactionTrait; use SprykerEco\Zed\AmazonQuicksight\Business\Adder\ErrorAdderInterface; use SprykerEco\Zed\AmazonQuicksight\Business\ApiClient\UserAmazonQuicksightApiClientInterface; @@ -23,11 +21,6 @@ class QuicksightUserCreator implements QuicksightUserCreatorInterface { use TransactionTrait; - /** - * @var string - */ - protected const ERROR_MESSAGE_QUICKSIGHT_USER_REGISTRATION_FAILED = 'The user role for Analytics could not be set. Please try again later.'; - /** * @var \SprykerEco\Zed\AmazonQuicksight\Business\Filter\UserCollectionFilterInterface */ @@ -82,30 +75,6 @@ public function __construct( $this->errorAdder = $errorAdder; } - /** - * @param \Generated\Shared\Transfer\UserCollectionResponseTransfer $userCollectionResponseTransfer - * - * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer - */ - public function createQuicksightUsersByUserCollectionResponse( - UserCollectionResponseTransfer $userCollectionResponseTransfer - ): UserCollectionResponseTransfer { - $filteredUserTransfers = $this->userCollectionFilter->filterOutUserTransfersNotApplicableForQuicksightUserRegistration( - $userCollectionResponseTransfer->getUsers()->getArrayCopy(), - ); - - if ($filteredUserTransfers === []) { - return $userCollectionResponseTransfer; - } - - return $this->getTransactionHandler()->handleTransaction(function () use ($userCollectionResponseTransfer, $filteredUserTransfers) { - return $this->executeCreateQuicksightUsersForUserCollectionResponseTransaction( - $userCollectionResponseTransfer, - $filteredUserTransfers, - ); - }); - } - /** * @return \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer */ @@ -139,42 +108,6 @@ public function createMatchedQuicksightUsers(): QuicksightUserCollectionResponse return $quicksightUserCollectionResponseTransfer->setQuicksightUsers(new ArrayObject($persistedQuicksightUserTransfers)); } - /** - * @param \Generated\Shared\Transfer\UserCollectionResponseTransfer $userCollectionResponseTransfer - * @param array $userTransfers - * - * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer - */ - protected function executeCreateQuicksightUsersForUserCollectionResponseTransaction( - UserCollectionResponseTransfer $userCollectionResponseTransfer, - array $userTransfers - ): UserCollectionResponseTransfer { - foreach ($userTransfers as $entityIdentifier => $userTransfer) { - $quicksightUserRegisterResponseTransfer = $this->userAmazonQuicksightApiClient->registerUser($userTransfer); - if ($quicksightUserRegisterResponseTransfer->getErrors()->count() !== 0) { - $userCollectionResponseTransfer = $this->errorAdder->addErrorsToUserCollectionResponse( - $userCollectionResponseTransfer, - $quicksightUserRegisterResponseTransfer->getErrors(), - (string)$entityIdentifier, - ); - - $this->messengerFacade->addErrorMessage( - (new MessageTransfer())->setValue(static::ERROR_MESSAGE_QUICKSIGHT_USER_REGISTRATION_FAILED), - ); - - continue; - } - - $quicksightUserTransfer = $quicksightUserRegisterResponseTransfer->getQuicksightUserOrFail(); - $quicksightUserTransfer->setFkUser($userTransfer->getIdUserOrFail()); - - $quicksightUserTransfer = $this->amazonQuicksightEntityManager->createQuicksightUser($quicksightUserTransfer); - $userTransfer->setQuicksightUser($quicksightUserTransfer); - } - - return $userCollectionResponseTransfer; - } - /** * @param array $quicksightUserTransfers * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreatorInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreatorInterface.php index ac807c5..d0e504d 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreatorInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Creator/QuicksightUserCreatorInterface.php @@ -8,19 +8,9 @@ namespace SprykerEco\Zed\AmazonQuicksight\Business\Creator; use Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer; -use Generated\Shared\Transfer\UserCollectionResponseTransfer; interface QuicksightUserCreatorInterface { - /** - * @param \Generated\Shared\Transfer\UserCollectionResponseTransfer $userCollectionResponseTransfer - * - * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer - */ - public function createQuicksightUsersByUserCollectionResponse( - UserCollectionResponseTransfer $userCollectionResponseTransfer - ): UserCollectionResponseTransfer; - /** * @return \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer */ diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php index 6636c98..7df1aed 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php @@ -8,10 +8,7 @@ namespace SprykerEco\Zed\AmazonQuicksight\Business\Deleter; use Generated\Shared\Transfer\MessageTransfer; -use Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer; -use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\UserCollectionResponseTransfer; -use Spryker\Zed\Kernel\Persistence\EntityManager\TransactionTrait; use SprykerEco\Zed\AmazonQuicksight\Business\Adder\ErrorAdderInterface; use SprykerEco\Zed\AmazonQuicksight\Business\ApiClient\UserAmazonQuicksightApiClientInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Filter\UserCollectionFilterInterface; @@ -21,8 +18,6 @@ class QuicksightUserDeleter implements QuicksightUserDeleterInterface { - use TransactionTrait; - /** * @var string */ @@ -98,45 +93,7 @@ public function deleteQuicksightUsersByUserCollectionResponse( return $userCollectionResponseTransfer; } - return $this->getTransactionHandler()->handleTransaction(function () use ($userCollectionResponseTransfer, $filteredUserTransfers) { - return $this->executeDeleteQuicksightUsersByUserCollectionResponseTransaction( - $userCollectionResponseTransfer, - $filteredUserTransfers, - ); - }); - } - - /** - * @return \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer - */ - public function deleteNotMatchedQuicksightUsers(): QuicksightUserCollectionResponseTransfer - { - $quicksightUserCollectionResponseTransfer = new QuicksightUserCollectionResponseTransfer(); - - $quicksightListUsersResponseTransfer = $this->userAmazonQuicksightApiClient->listUsers(); - if ($quicksightListUsersResponseTransfer->getErrors()->count() !== 0) { - return $quicksightUserCollectionResponseTransfer->setErrors( - $quicksightListUsersResponseTransfer->getErrors(), - ); - } - - $quicksightUserTransfers = $quicksightListUsersResponseTransfer->getQuicksightUsers(); - if ($quicksightUserTransfers->count() === 0) { - return $quicksightUserCollectionResponseTransfer; - } - - $notMatchedQuicksightUserTransfers = $this->quicksightUserMatcher->getQuicksightUsersNotMatchedWithExistingUsers( - $quicksightUserTransfers, - ); - - foreach ($notMatchedQuicksightUserTransfers as $quicksightUserTransfer) { - $quicksightUserCollectionResponseTransfer = $this->deleteQuicksightUser( - $quicksightUserTransfer, - $quicksightUserCollectionResponseTransfer, - ); - } - - return $quicksightUserCollectionResponseTransfer; + return $this->deleteQuicksightUsers($userCollectionResponseTransfer, $filteredUserTransfers); } /** @@ -145,7 +102,7 @@ public function deleteNotMatchedQuicksightUsers(): QuicksightUserCollectionRespo * * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer */ - protected function executeDeleteQuicksightUsersByUserCollectionResponseTransaction( + protected function deleteQuicksightUsers( UserCollectionResponseTransfer $userCollectionResponseTransfer, array $userTransfers ): UserCollectionResponseTransfer { @@ -173,30 +130,4 @@ protected function executeDeleteQuicksightUsersByUserCollectionResponseTransacti return $userCollectionResponseTransfer; } - - /** - * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer - * @param \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer $quicksightUserCollectionResponseTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer - */ - protected function deleteQuicksightUser( - QuicksightUserTransfer $quicksightUserTransfer, - QuicksightUserCollectionResponseTransfer $quicksightUserCollectionResponseTransfer - ): QuicksightUserCollectionResponseTransfer { - $quicksightDeleteUserResponseTransfer = $this->userAmazonQuicksightApiClient->deleteUserByPrincipalId( - $quicksightUserTransfer, - ); - - if ($quicksightDeleteUserResponseTransfer->getErrors()->count() !== 0) { - return $this->errorAdder->addErrorsToQuicksightUserCollectionResponse( - $quicksightUserCollectionResponseTransfer, - $quicksightDeleteUserResponseTransfer->getErrors(), - ); - } - - $quicksightUserCollectionResponseTransfer->addQuicksightUser($quicksightUserTransfer); - - return $quicksightUserCollectionResponseTransfer; - } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleterInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleterInterface.php index 30b26bb..b458f8f 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleterInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleterInterface.php @@ -7,7 +7,6 @@ namespace SprykerEco\Zed\AmazonQuicksight\Business\Deleter; -use Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer; use Generated\Shared\Transfer\UserCollectionResponseTransfer; interface QuicksightUserDeleterInterface @@ -20,9 +19,4 @@ interface QuicksightUserDeleterInterface public function deleteQuicksightUsersByUserCollectionResponse( UserCollectionResponseTransfer $userCollectionResponseTransfer ): UserCollectionResponseTransfer; - - /** - * @return \Generated\Shared\Transfer\QuicksightUserCollectionResponseTransfer - */ - public function deleteNotMatchedQuicksightUsers(): QuicksightUserCollectionResponseTransfer; } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Enabler/AssetBundleEnabler.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Enabler/AssetBundleEnabler.php index 29fb570..28ad4df 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Enabler/AssetBundleEnabler.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Enabler/AssetBundleEnabler.php @@ -14,7 +14,6 @@ use SprykerEco\Zed\AmazonQuicksight\Business\Creator\QuicksightAssetBundleImportJobCreatorInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Deleter\DataSetDeleterInterface; use SprykerEco\Zed\AmazonQuicksight\Business\FileContentLoader\AssetBundleImportFileContentLoaderInterface; -use SprykerEco\Zed\AmazonQuicksight\Business\Processor\AssetBundleQuicksightUserProcessorInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Updater\QuicksightAssetBundleImportJobUpdaterInterface; use SprykerEco\Zed\AmazonQuicksight\Business\Validator\QuicksightAnalyticsRequestValidatorInterface; use SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface; @@ -41,11 +40,6 @@ class AssetBundleEnabler implements AssetBundleEnablerInterface */ protected QuicksightAnalyticsRequestValidatorInterface $quicksightAnalyticsRequestValidator; - /** - * @var \SprykerEco\Zed\AmazonQuicksight\Business\Processor\AssetBundleQuicksightUserProcessorInterface - */ - protected AssetBundleQuicksightUserProcessorInterface $assetBundleQuicksightUserProcessor; - /** * @var \SprykerEco\Zed\AmazonQuicksight\Business\FileContentLoader\AssetBundleImportFileContentLoaderInterface */ @@ -61,7 +55,6 @@ class AssetBundleEnabler implements AssetBundleEnablerInterface * @param \SprykerEco\Zed\AmazonQuicksight\Business\Updater\QuicksightAssetBundleImportJobUpdaterInterface $quicksightAssetBundleImportJobUpdater * @param \SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface $amazonQuicksightRepository * @param \SprykerEco\Zed\AmazonQuicksight\Business\Validator\QuicksightAnalyticsRequestValidatorInterface $quicksightAnalyticsRequestValidator - * @param \SprykerEco\Zed\AmazonQuicksight\Business\Processor\AssetBundleQuicksightUserProcessorInterface $assetBundleQuicksightUserProcessor * @param \SprykerEco\Zed\AmazonQuicksight\Business\FileContentLoader\AssetBundleImportFileContentLoaderInterface $assetBundleImportFileContentLoader * @param \SprykerEco\Zed\AmazonQuicksight\Business\Deleter\DataSetDeleterInterface $dataSetDeleter */ @@ -70,7 +63,6 @@ public function __construct( QuicksightAssetBundleImportJobUpdaterInterface $quicksightAssetBundleImportJobUpdater, AmazonQuicksightRepositoryInterface $amazonQuicksightRepository, QuicksightAnalyticsRequestValidatorInterface $quicksightAnalyticsRequestValidator, - AssetBundleQuicksightUserProcessorInterface $assetBundleQuicksightUserProcessor, AssetBundleImportFileContentLoaderInterface $assetBundleImportFileContentLoader, DataSetDeleterInterface $dataSetDeleter ) { @@ -78,7 +70,6 @@ public function __construct( $this->quicksightAssetBundleImportJobUpdater = $quicksightAssetBundleImportJobUpdater; $this->amazonQuicksightRepository = $amazonQuicksightRepository; $this->quicksightAnalyticsRequestValidator = $quicksightAnalyticsRequestValidator; - $this->assetBundleQuicksightUserProcessor = $assetBundleQuicksightUserProcessor; $this->assetBundleImportFileContentLoader = $assetBundleImportFileContentLoader; $this->dataSetDeleter = $dataSetDeleter; } @@ -107,14 +98,6 @@ public function enableAnalytics( return $enableQuicksightAnalyticsResponseTransfer; } - $userCollectionResponseTransfer = $this->assetBundleQuicksightUserProcessor->processQuicksightUserBeforeAnalyticsEnabling( - $enableQuicksightAnalyticsRequestTransfer->getUserOrFail(), - ); - - if ($userCollectionResponseTransfer->getErrors()->count() !== 0) { - return $enableQuicksightAnalyticsResponseTransfer->setErrors($userCollectionResponseTransfer->getErrors()); - } - $quicksightDeleteAssetBundleDataSetsResponseTransfer = $this->dataSetDeleter->deleteAssetBundleDataSets(); if ($quicksightDeleteAssetBundleDataSetsResponseTransfer->getErrors()->count() !== 0) { diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php index 498ece6..e6a7778 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php @@ -32,7 +32,22 @@ class AnalyticsExpander implements AnalyticsExpanderInterface /** * @var string */ - protected const TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_ACTIONS = '@AmazonQuicksight/_partials/quicksight-analytics-actions.twig'; + protected const TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_RESET_ACTION = '@AmazonQuicksight/_partials/quicksight-analytics-reset-action.twig'; + + /** + * @var string + */ + protected const TEMPLATE_PATH_SYNCHRONIZE_QUICKSIGHT_USERS_ACTION = '@AmazonQuicksight/_partials/synchronize-quicksight-users-action.twig'; + + /** + * @var string + */ + protected const FORM_NAME_SYNCHRONIZE_QUICKSIGHT_USERS = 'synchronizeQuicksightUsersForm'; + + /** + * @var string + */ + protected const FIELD_NAME_SYNCHRONIZE_QUICKSIGHT_USERS_FORM_TOKEN = '_token'; /** * @var \SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface @@ -129,25 +144,26 @@ protected function expandAnalytics( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): AnalyticsCollectionTransfer { - $isAssetBundleSuccessfullyInitialized = $this->quicksightAnalyticsRequestValidator - ->isAssetBundleSuccessfullyInitialized($quicksightAssetBundleImportJobTransfer); - $isAssetBundleInitializationInProgress = $this->quicksightAnalyticsRequestValidator - ->isAssetBundleInitializationInProgress($quicksightAssetBundleImportJobTransfer); - $isQuicksightUserRoleAvailable = $this->quicksightAnalyticsRequestValidator - ->isQuicksightUserRoleAvailable($quicksightUserTransfer); - $content = $this->twigEnvironment->render( static::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS, [ 'quicksightGenerateEmbedUrlResponse' => $this->getQuicksightGenerateEmbedUrlResponseTransfer( - $isAssetBundleSuccessfullyInitialized, - $isQuicksightUserRoleAvailable, + $this->quicksightAnalyticsRequestValidator + ->isAssetBundleSuccessfullyInitialized($quicksightAssetBundleImportJobTransfer), + $this->quicksightAnalyticsRequestValidator->isQuicksightUserRoleAvailable($quicksightUserTransfer), $quicksightUserTransfer, ), 'quicksightAssetBundleImportJob' => $quicksightAssetBundleImportJobTransfer, - 'isAssetBundleSuccessfullyInitialized' => $isAssetBundleSuccessfullyInitialized, - 'isAssetBundleInitializationInProgress' => $isAssetBundleInitializationInProgress, - 'isQuicksightUserRoleAvailable' => $isQuicksightUserRoleAvailable, + 'isAssetBundleInitializationInProgress' => $this->quicksightAnalyticsRequestValidator + ->isAssetBundleInitializationInProgress($quicksightAssetBundleImportJobTransfer), + 'isEnableAnalyticsAllowed' => $this->quicksightAnalyticsRequestValidator->isEnableAnalyticsAllowed( + $quicksightAssetBundleImportJobTransfer, + $quicksightUserTransfer, + ), + 'isDisplayAnalyticsAllowed' => $this->quicksightAnalyticsRequestValidator->isDisplayAnalyticsAllowed( + $quicksightAssetBundleImportJobTransfer, + $quicksightUserTransfer, + ), ], ); @@ -168,12 +184,20 @@ protected function expandAnalyticsActions( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): AnalyticsCollectionTransfer { - if (!$this->quicksightAnalyticsRequestValidator->isResetAnalyticsEnabled($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { + $analyticsCollectionTransfer->addAnalyticsAction((new AnalyticsActionTransfer())->setContent( + $this->twigEnvironment->render(static::TEMPLATE_PATH_SYNCHRONIZE_QUICKSIGHT_USERS_ACTION, [ + 'formName' => static::FORM_NAME_SYNCHRONIZE_QUICKSIGHT_USERS, + 'tokenFieldName' => static::FIELD_NAME_SYNCHRONIZE_QUICKSIGHT_USERS_FORM_TOKEN, + ]), + )); + + if (!$this->quicksightAnalyticsRequestValidator->isResetAnalyticsAllowed($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { return $analyticsCollectionTransfer; } - $content = $this->twigEnvironment->render(static::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_ACTIONS); - $analyticsCollectionTransfer->addAnalyticsAction((new AnalyticsActionTransfer())->setContent($content)); + $analyticsCollectionTransfer->addAnalyticsAction((new AnalyticsActionTransfer())->setContent( + $this->twigEnvironment->render(static::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_RESET_ACTION), + )); return $analyticsCollectionTransfer; } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Filter/UserCollectionFilter.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Filter/UserCollectionFilter.php index 7c5382a..f1c40e6 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Filter/UserCollectionFilter.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Filter/UserCollectionFilter.php @@ -34,23 +34,6 @@ public function __construct(AmazonQuicksightConfig $amazonQuicksightConfig, Quic $this->quicksightUserReader = $quicksightUserReader; } - /** - * @param array $userTransfers - * - * @return array - */ - public function filterOutUserTransfersNotApplicableForQuicksightUserRegistration(array $userTransfers): array - { - $filteredUserTransfers = $this->filterOutUsersWithNotApplicableStatus( - $userTransfers, - $this->amazonQuicksightConfig->getUserStatusesApplicableForQuicksightUserRegistration(), - ); - $filteredUserTransfers = $this->filterOutUserTransfersWithoutQuicksightUserRole($filteredUserTransfers); - $filteredUserTransfers = $this->filterOutUserTransfersWithPersistedQuicksightUser($filteredUserTransfers); - - return $filteredUserTransfers; - } - /** * @param array $userTransfers * @@ -92,18 +75,6 @@ protected function filterOutUsersWithNotApplicableStatus(array $userTransfers, a }); } - /** - * @param array $userTransfers - * - * @return array - */ - protected function filterOutUserTransfersWithoutQuicksightUserRole(array $userTransfers): array - { - return array_filter($userTransfers, function (UserTransfer $userTransfer) { - return $userTransfer->getQuicksightUser() && $userTransfer->getQuicksightUserOrFail()->getRole(); - }); - } - /** * @param array $userTransfers * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Filter/UserCollectionFilterInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Filter/UserCollectionFilterInterface.php index bb0e6b7..a5dabbb 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Filter/UserCollectionFilterInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Filter/UserCollectionFilterInterface.php @@ -11,13 +11,6 @@ interface UserCollectionFilterInterface { - /** - * @param array $userTransfers - * - * @return array - */ - public function filterOutUserTransfersNotApplicableForQuicksightUserRegistration(array $userTransfers): array; - /** * @param array $userTransfers * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php index ca4ada9..60fef73 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php @@ -19,8 +19,6 @@ use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlRequestTransfer; use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer; use Generated\Shared\Transfer\QuicksightStartAssetBundleImportJobRequestTransfer; -use Generated\Shared\Transfer\QuicksightUpdateUserRequestTransfer; -use Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer; use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\ResetQuicksightAnalyticsRequestTransfer; use Generated\Shared\Transfer\UserTransfer; @@ -48,22 +46,6 @@ class AmazonQuicksightMapper implements AmazonQuicksightMapperInterface */ protected const RESPONSE_KEY_ERRORS_MESSAGE = 'Message'; - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * @param \Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer $quicksightUserRegisterRequestTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer - */ - public function mapUserTransferToQuicksightUserRegisterRequestTransfer( - UserTransfer $userTransfer, - QuicksightUserRegisterRequestTransfer $quicksightUserRegisterRequestTransfer - ): QuicksightUserRegisterRequestTransfer { - return $quicksightUserRegisterRequestTransfer - ->setEmail($userTransfer->getUsernameOrFail()) - ->setUserName($userTransfer->getUsernameOrFail()) - ->setUserRole(strtoupper($userTransfer->getQuicksightUserOrFail()->getRoleOrFail())); - } - /** * @param array $quicksightUserData * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer @@ -105,19 +87,6 @@ public function mapGenerateEmbedUrlResponseDataToQuicksightGenerateEmbedUrlRespo ); } - /** - * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer - * @param \Generated\Shared\Transfer\QuicksightDeleteUserRequestTransfer $quicksightDeleteUserRequestTransfer - * - * @return \Generated\Shared\Transfer\QuicksightDeleteUserRequestTransfer - */ - public function mapQuicksightUserTransferToQuicksightDeleteUserRequestTransfer( - QuicksightUserTransfer $quicksightUserTransfer, - QuicksightDeleteUserRequestTransfer $quicksightDeleteUserRequestTransfer - ): QuicksightDeleteUserRequestTransfer { - return $quicksightDeleteUserRequestTransfer->fromArray($quicksightUserTransfer->toArray(), true); - } - /** * @param \Generated\Shared\Transfer\UserTransfer $userTransfer * @param \Generated\Shared\Transfer\QuicksightDeleteUserRequestTransfer $quicksightDeleteUserRequestTransfer @@ -268,22 +237,6 @@ public function mapQuicksightDescribeAssetBundleImportJobResponseTransferToQuick return $quicksightAssetBundleImportJobTransfer->fromArray($quicksightDescribeAssetBundleImportJobResponseTransfer->toArray(), true); } - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * @param \Generated\Shared\Transfer\QuicksightUpdateUserRequestTransfer $quicksightUpdateUserRequestTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUpdateUserRequestTransfer - */ - public function mapUserTransferToQuicksightUpdateUserRequestTransfer( - UserTransfer $userTransfer, - QuicksightUpdateUserRequestTransfer $quicksightUpdateUserRequestTransfer - ): QuicksightUpdateUserRequestTransfer { - return $quicksightUpdateUserRequestTransfer - ->setEmail($userTransfer->getUsernameOrFail()) - ->setUserName($userTransfer->getUsernameOrFail()) - ->setRole(strtoupper($userTransfer->getQuicksightUserOrFail()->getRoleOrFail())); - } - /** * @param \Generated\Shared\Transfer\QuicksightDeleteDataSetResponseTransfer $quicksightDeleteDataSetResponseTransfer * @param \Generated\Shared\Transfer\QuicksightDeleteAssetBundleDataSetsResponseTransfer $quicksightDeleteAssetBundleDataSetsResponseTransfer diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php index ad3e9e1..3d8b8dd 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php @@ -16,25 +16,12 @@ use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlRequestTransfer; use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer; use Generated\Shared\Transfer\QuicksightStartAssetBundleImportJobRequestTransfer; -use Generated\Shared\Transfer\QuicksightUpdateUserRequestTransfer; -use Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer; use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\ResetQuicksightAnalyticsRequestTransfer; use Generated\Shared\Transfer\UserTransfer; interface AmazonQuicksightMapperInterface { - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * @param \Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer $quicksightUserRegisterRequestTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer - */ - public function mapUserTransferToQuicksightUserRegisterRequestTransfer( - UserTransfer $userTransfer, - QuicksightUserRegisterRequestTransfer $quicksightUserRegisterRequestTransfer - ): QuicksightUserRegisterRequestTransfer; - /** * @param array $quicksightUserData * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer @@ -68,17 +55,6 @@ public function mapGenerateEmbedUrlResponseDataToQuicksightGenerateEmbedUrlRespo QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer ): QuicksightGenerateEmbedUrlResponseTransfer; - /** - * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer - * @param \Generated\Shared\Transfer\QuicksightDeleteUserRequestTransfer $quicksightDeleteUserRequestTransfer - * - * @return \Generated\Shared\Transfer\QuicksightDeleteUserRequestTransfer - */ - public function mapQuicksightUserTransferToQuicksightDeleteUserRequestTransfer( - QuicksightUserTransfer $quicksightUserTransfer, - QuicksightDeleteUserRequestTransfer $quicksightDeleteUserRequestTransfer - ): QuicksightDeleteUserRequestTransfer; - /** * @param \Generated\Shared\Transfer\UserTransfer $userTransfer * @param \Generated\Shared\Transfer\QuicksightDeleteUserRequestTransfer $quicksightDeleteUserRequestTransfer @@ -134,17 +110,6 @@ public function mapQuicksightDescribeAssetBundleImportJobResponseTransferToQuick QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer ): QuicksightAssetBundleImportJobTransfer; - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * @param \Generated\Shared\Transfer\QuicksightUpdateUserRequestTransfer $quicksightUpdateUserRequestTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUpdateUserRequestTransfer - */ - public function mapUserTransferToQuicksightUpdateUserRequestTransfer( - UserTransfer $userTransfer, - QuicksightUpdateUserRequestTransfer $quicksightUpdateUserRequestTransfer - ): QuicksightUpdateUserRequestTransfer; - /** * @param \Generated\Shared\Transfer\QuicksightDeleteDataSetResponseTransfer $quicksightDeleteDataSetResponseTransfer * @param \Generated\Shared\Transfer\QuicksightDeleteAssetBundleDataSetsResponseTransfer $quicksightDeleteAssetBundleDataSetsResponseTransfer diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Matcher/QuicksightUserMatcher.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Matcher/QuicksightUserMatcher.php index c370827..62c05dc 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Matcher/QuicksightUserMatcher.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Matcher/QuicksightUserMatcher.php @@ -78,37 +78,6 @@ public function getQuicksightUsersMatchedWithExistingUsers(ArrayObject $quicksig return $matchedQuicksightUserTransfers; } - /** - * @param \ArrayObject $quicksightUserTransfers - * - * @return list<\Generated\Shared\Transfer\QuicksightUserTransfer> - */ - public function getQuicksightUsersNotMatchedWithExistingUsers(ArrayObject $quicksightUserTransfers): array - { - $filteredQuicksightUserTransfers = $this->quicksightUserCollectionFilter->filterOutQuicksightUsersWithUnsupportedQuicksightUserRoles( - $quicksightUserTransfers, - ); - if ($filteredQuicksightUserTransfers === []) { - return []; - } - - $userCollectionTransfer = $this->userReader->getUsersApplicableForQuicksightUserRegistration(); - $userTransfersIndexedByUsername = $this->getUserTransfersIndexedByUsername( - $userCollectionTransfer->getUsers()->getArrayCopy(), - ); - - $notMatchedQuicksightUserTransfers = []; - foreach ($filteredQuicksightUserTransfers as $quicksightUserTransfer) { - if (isset($userTransfersIndexedByUsername[$quicksightUserTransfer->getUserNameOrFail()])) { - continue; - } - - $notMatchedQuicksightUserTransfers[] = $quicksightUserTransfer; - } - - return $notMatchedQuicksightUserTransfers; - } - /** * @param array $userTransfers * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Matcher/QuicksightUserMatcherInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Matcher/QuicksightUserMatcherInterface.php index 2f3c41f..27a1dd2 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Matcher/QuicksightUserMatcherInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Matcher/QuicksightUserMatcherInterface.php @@ -17,11 +17,4 @@ interface QuicksightUserMatcherInterface * @return list<\Generated\Shared\Transfer\QuicksightUserTransfer> */ public function getQuicksightUsersMatchedWithExistingUsers(ArrayObject $quicksightUserTransfers): array; - - /** - * @param \ArrayObject $quicksightUserTransfers - * - * @return list<\Generated\Shared\Transfer\QuicksightUserTransfer> - */ - public function getQuicksightUsersNotMatchedWithExistingUsers(ArrayObject $quicksightUserTransfers): array; } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Processor/AssetBundleQuicksightUserProcessor.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Processor/AssetBundleQuicksightUserProcessor.php deleted file mode 100644 index 0995e45..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Processor/AssetBundleQuicksightUserProcessor.php +++ /dev/null @@ -1,105 +0,0 @@ - - */ - protected const QUICKSIGHT_USER_ROLES_TO_UPDATE_TO_AUTHOR = [ - self::QUICKSIGHT_USER_ROLE_READER, - ]; - - /** - * @var \SprykerEco\Zed\AmazonQuicksight\Business\Creator\QuicksightUserCreatorInterface - */ - protected QuicksightUserCreatorInterface $quicksightUserCreator; - - /** - * @var \SprykerEco\Zed\AmazonQuicksight\Business\Updater\QuicksightUserUpdaterInterface - */ - protected QuicksightUserUpdaterInterface $quicksightUserUpdater; - - /** - * @var \SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface - */ - protected AmazonQuicksightRepositoryInterface $amazonQuicksightRepository; - - /** - * @param \SprykerEco\Zed\AmazonQuicksight\Business\Creator\QuicksightUserCreatorInterface $quicksightUserCreator - * @param \SprykerEco\Zed\AmazonQuicksight\Business\Updater\QuicksightUserUpdaterInterface $quicksightUserUpdater - * @param \SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface $amazonQuicksightRepository - */ - public function __construct( - QuicksightUserCreatorInterface $quicksightUserCreator, - QuicksightUserUpdaterInterface $quicksightUserUpdater, - AmazonQuicksightRepositoryInterface $amazonQuicksightRepository - ) { - $this->quicksightUserCreator = $quicksightUserCreator; - $this->quicksightUserUpdater = $quicksightUserUpdater; - $this->amazonQuicksightRepository = $amazonQuicksightRepository; - } - - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * - * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer - */ - public function processQuicksightUserBeforeAnalyticsEnabling( - UserTransfer $userTransfer - ): UserCollectionResponseTransfer { - $quicksightUserTransfer = $this->amazonQuicksightRepository->getQuicksightUserCollection( - (new QuicksightUserCriteriaTransfer())->setQuicksightUserConditions( - (new QuicksightUserConditionsTransfer())->addIdUser($userTransfer->getIdUserOrFail()), - ), - )->getQuicksightUsers()->getIterator()->current(); - - if (!$quicksightUserTransfer) { - return $this->quicksightUserCreator->createQuicksightUsersByUserCollectionResponse( - (new UserCollectionResponseTransfer())->addUser($userTransfer - ->setQuicksightUser((new QuicksightUserTransfer())->setRole(static::QUICKSIGHT_USER_ROLE_AUTHOR))), - ); - } - - if (in_array($quicksightUserTransfer->getRole(), static::QUICKSIGHT_USER_ROLES_TO_UPDATE_TO_AUTHOR)) { - $userTransfer->getQuicksightUserOrFail()->setRole(static::QUICKSIGHT_USER_ROLE_AUTHOR); - $quicksightUpdateUserResponseTransfer = $this->quicksightUserUpdater->updateQuicksightUser($userTransfer); - $userTransfer->setQuicksightUser($quicksightUpdateUserResponseTransfer->getQuicksightUserOrFail()); - - return (new UserCollectionResponseTransfer()) - ->addUser($userTransfer) - ->setErrors($quicksightUpdateUserResponseTransfer->getErrors()); - } - - return (new UserCollectionResponseTransfer())->addUser($userTransfer); - } -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Processor/AssetBundleQuicksightUserProcessorInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Processor/AssetBundleQuicksightUserProcessorInterface.php deleted file mode 100644 index 539c23a..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Processor/AssetBundleQuicksightUserProcessorInterface.php +++ /dev/null @@ -1,23 +0,0 @@ -userAmazonQuicksightApiClient = $userAmazonQuicksightApiClient; - $this->amazonQuicksightEntityManager = $amazonQuicksightEntityManager; - } - - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUpdateUserResponseTransfer - */ - public function updateQuicksightUser(UserTransfer $userTransfer): QuicksightUpdateUserResponseTransfer - { - $quicksightUserTransfer = $userTransfer->getQuicksightUserOrFail(); - $quicksightUpdateUserResponseTransfer = $this->userAmazonQuicksightApiClient->updateUser($userTransfer); - - if ($quicksightUpdateUserResponseTransfer->getErrors()->count() !== 0) { - return $quicksightUpdateUserResponseTransfer->setQuicksightUser($quicksightUserTransfer); - } - - $quicksightUserTransfer = $this->amazonQuicksightEntityManager->updateQuicksightUser($quicksightUserTransfer); - - return $quicksightUpdateUserResponseTransfer->setQuicksightUser($quicksightUserTransfer); - } -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Updater/QuicksightUserUpdaterInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Updater/QuicksightUserUpdaterInterface.php deleted file mode 100644 index b36539a..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Updater/QuicksightUserUpdaterInterface.php +++ /dev/null @@ -1,21 +0,0 @@ -getQuicksightAssetBundleImportJob(); + $quicksightUserTransfer = $enableQuicksightAnalyticsRequestTransfer->getUserOrFail()->getQuicksightUser(); - if (!$this->isEnableAnalyticsEnabled($quicksightAssetBundleImportJobTransfer)) { + if (!$this->isEnableAnalyticsAllowed($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { $enableQuicksightAnalyticsResponseTransfer->addError( (new ErrorTransfer())->setMessage(static::ERROR_MESSAGE_ENABLE_ANALYTICS_FAILED), ); @@ -75,7 +76,7 @@ public function validateResetQuicksightAnalyticsRequest( $quicksightAssetBundleImportJobTransfer = $resetQuicksightAnalyticsRequestTransfer->getQuicksightAssetBundleImportJob(); $quicksightUserTransfer = $resetQuicksightAnalyticsRequestTransfer->getUserOrFail()->getQuicksightUser(); - if (!$this->isResetAnalyticsEnabled($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { + if (!$this->isResetAnalyticsAllowed($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { $resetQuicksightAnalyticsResponseTransfer->addError( (new ErrorTransfer())->setMessage(static::ERROR_MESSAGE_RESET_ANALYTICS_FAILED), ); @@ -90,7 +91,7 @@ public function validateResetQuicksightAnalyticsRequest( * * @return bool */ - public function isResetAnalyticsEnabled( + public function isResetAnalyticsAllowed( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): bool { @@ -101,14 +102,32 @@ public function isResetAnalyticsEnabled( /** * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer|null $quicksightAssetBundleImportJobTransfer + * @param \Generated\Shared\Transfer\QuicksightUserTransfer|null $quicksightUserTransfer * * @return bool */ - public function isEnableAnalyticsEnabled( - ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer + public function isEnableAnalyticsAllowed( + ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, + ?QuicksightUserTransfer $quicksightUserTransfer ): bool { return !$this->isAssetBundleSuccessfullyInitialized($quicksightAssetBundleImportJobTransfer) - && !$this->isAssetBundleInitializationInProgress($quicksightAssetBundleImportJobTransfer); + && !$this->isAssetBundleInitializationInProgress($quicksightAssetBundleImportJobTransfer) + && $this->isQuicksightUserAuthor($quicksightUserTransfer); + } + + /** + * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer|null $quicksightAssetBundleImportJobTransfer + * @param \Generated\Shared\Transfer\QuicksightUserTransfer|null $quicksightUserTransfer + * + * @return bool + */ + public function isDisplayAnalyticsAllowed( + ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, + ?QuicksightUserTransfer $quicksightUserTransfer + ): bool { + return $this->isAssetBundleSuccessfullyInitialized($quicksightAssetBundleImportJobTransfer) + && !$this->isAssetBundleInitializationInProgress($quicksightAssetBundleImportJobTransfer) + && $this->isQuicksightUserRoleAvailable($quicksightUserTransfer); } /** diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php index de87cab..15ecef3 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php @@ -44,18 +44,31 @@ public function validateResetQuicksightAnalyticsRequest( * * @return bool */ - public function isResetAnalyticsEnabled( + public function isResetAnalyticsAllowed( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): bool; /** * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer|null $quicksightAssetBundleImportJobTransfer + * @param \Generated\Shared\Transfer\QuicksightUserTransfer|null $quicksightUserTransfer * * @return bool */ - public function isEnableAnalyticsEnabled( - ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer + public function isEnableAnalyticsAllowed( + ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, + ?QuicksightUserTransfer $quicksightUserTransfer + ): bool; + + /** + * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer|null $quicksightAssetBundleImportJobTransfer + * @param \Generated\Shared\Transfer\QuicksightUserTransfer|null $quicksightUserTransfer + * + * @return bool + */ + public function isDisplayAnalyticsAllowed( + ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, + ?QuicksightUserTransfer $quicksightUserTransfer ): bool; /** diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php index 6fc131f..9e0ecab 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php @@ -9,16 +9,11 @@ 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\Form\EnableAnalyticsForm; use SprykerEco\Zed\AmazonQuicksight\Communication\Form\ResetAnalyticsForm; -use SprykerEco\Zed\AmazonQuicksight\Communication\Transformer\QuicksightUserRoleDataTransformer; use SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToUserFacadeInterface; -use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\FormInterface; +use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; /** * @method \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig getConfig() @@ -28,34 +23,6 @@ */ 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> - */ - public function createQuicksightUserRoleDataTransformer(): DataTransformerInterface - { - return new QuicksightUserRoleDataTransformer(); - } - - /** - * @return \SprykerEco\Zed\AmazonQuicksight\Communication\DataProvider\QuicksightUserFormDataProviderInterface - */ - public function createQuicksightUserFormDataProvider(): QuicksightUserFormDataProviderInterface - { - return new QuicksightUserFormDataProvider($this->getConfig()); - } - /** * @return \Symfony\Component\Form\FormInterface */ @@ -79,4 +46,12 @@ public function getUserFacade(): AmazonQuicksightToUserFacadeInterface { return $this->getProvidedDependency(AmazonQuicksightDependencyProvider::FACADE_USER); } + + /** + * @return \Symfony\Component\Security\Csrf\CsrfTokenManagerInterface + */ + public function getCsrfTokenManager(): CsrfTokenManagerInterface + { + return $this->getProvidedDependency(AmazonQuicksightDependencyProvider::SERVICE_FORM_CSRF_PROVIDER); + } } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Console/QuicksightUserSyncDeleteConsole.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Console/QuicksightUserSyncDeleteConsole.php deleted file mode 100644 index 988cd55..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Console/QuicksightUserSyncDeleteConsole.php +++ /dev/null @@ -1,65 +0,0 @@ -setName(static::COMMAND_NAME) - ->setDescription(static::COMMAND_DESCRIPTION); - } - - /** - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Symfony\Component\Console\Output\OutputInterface $output - * - * @return int - */ - public function execute(InputInterface $input, OutputInterface $output): int - { - $quicksightUserCollectionResponseTransfer = $this->getFacade() - ->deleteNotMatchedQuicksightUsers(); - - if ($quicksightUserCollectionResponseTransfer->getErrors()->count() === 0) { - return static::CODE_SUCCESS; - } - - foreach ($quicksightUserCollectionResponseTransfer->getErrors() as $errorTransfer) { - $this->output->writeln( - sprintf('%s', $errorTransfer->getMessage()), - ); - } - - return static::CODE_ERROR; - } -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php index 4d9672d..23466e3 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php @@ -33,7 +33,7 @@ class AnalyticsController extends AbstractController /** * @var string */ - protected const ERROR_MESSAGE_CSRF_TOKEN_INVALID = 'CSRF token is not valid'; + protected const ERROR_MESSAGE_CSRF_TOKEN_INVALID = 'CSRF token is not valid.'; /** * @param \Symfony\Component\HttpFoundation\Request $request diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php new file mode 100644 index 0000000..c1d8729 --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php @@ -0,0 +1,103 @@ + + */ + public function synchronizeQuicksightUsersAction(Request $request): RedirectResponse|array + { + $tokenValue = (string)$request->get(static::FIELD_NAME_SYNCHRONIZE_QUICKSIGHT_USERS_FORM_TOKEN); + + if (!$this->validateCsrfToken(static::FORM_NAME_SYNCHRONIZE_QUICKSIGHT_USERS, $tokenValue)) { + $this->addErrorMessage(static::ERROR_MESSAGE_CSRF_TOKEN_INVALID); + + return $this->getRedirectResponseReferer($request); + } + + $quicksightUserCollectionResponseTransfer = $this->getFacade()->createMatchedQuicksightUsers(); + + if ($quicksightUserCollectionResponseTransfer->getErrors()->count() === 0) { + $this->addSuccessMessage(static::SUCCESS_MESSAGE_USERS_SYNCHRONIZED); + + return $this->getRedirectResponseReferer($request); + } + + foreach ($quicksightUserCollectionResponseTransfer->getErrors() as $errorTransfer) { + $this->addErrorMessage($errorTransfer->getMessageOrFail()); + } + + return $this->getRedirectResponseReferer($request); + } + + /** + * @param string $tokenId + * @param string $value + * + * @return bool + */ + protected function validateCsrfToken(string $tokenId, string $value): bool + { + $csrfToken = new CsrfToken($tokenId, $value); + + return $this->getFactory()->getCsrfTokenManager()->isTokenValid($csrfToken); + } + + /** + * @param \Symfony\Component\HttpFoundation\Request $request + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + protected function getRedirectResponseReferer(Request $request): RedirectResponse + { + return $this->redirectResponse($request->headers->get(static::PARAM_REFERER)); + } +} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProvider.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProvider.php deleted file mode 100644 index 7674c4e..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProvider.php +++ /dev/null @@ -1,51 +0,0 @@ -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 deleted file mode 100644 index 97aeb57..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProviderInterface.php +++ /dev/null @@ -1,16 +0,0 @@ - - */ - public function getQuicksightUserRoleChoices(): array; -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php deleted file mode 100644 index 997b347..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php +++ /dev/null @@ -1,105 +0,0 @@ -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> - */ - 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> $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); - } -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpanderInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpanderInterface.php deleted file mode 100644 index 06041d0..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpanderInterface.php +++ /dev/null @@ -1,20 +0,0 @@ - $builder - * - * @return void - */ - public function expandForm(FormBuilderInterface $builder): void; -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/CreateQuicksightUserPostUpdatePlugin.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/CreateQuicksightUserPostUpdatePlugin.php deleted file mode 100644 index 09b69da..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/CreateQuicksightUserPostUpdatePlugin.php +++ /dev/null @@ -1,43 +0,0 @@ -getFacade()->createQuicksightUsersByUserCollectionResponse($userCollectionResponseTransfer); - } -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserPostCreatePlugin.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserPostCreatePlugin.php deleted file mode 100644 index 2f2803e..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserPostCreatePlugin.php +++ /dev/null @@ -1,43 +0,0 @@ -getFacade()->createQuicksightUsersByUserCollectionResponse($userCollectionResponseTransfer); - } -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserRoleUserFormExpanderPlugin.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserRoleUserFormExpanderPlugin.php deleted file mode 100644 index 27c365f..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserRoleUserFormExpanderPlugin.php +++ /dev/null @@ -1,37 +0,0 @@ -getFactory() - ->createQuicksightUserFormExpander() - ->expandForm($builder); - } -} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php deleted file mode 100644 index d9c6e45..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php +++ /dev/null @@ -1,71 +0,0 @@ -, array> - */ -class QuicksightUserRoleDataTransformer implements DataTransformerInterface -{ - /** - * @uses \SprykerEco\Zed\AmazonQuicksight\Communication\Expander\QuicksightUserFormExpander::FIELD_QUICKSIGHT_USER_ROLE - * - * @var string - */ - protected const FIELD_QUICKSIGHT_USER_ROLE = 'quicksight_user_role'; - - /** - * @var string - */ - protected const KEY_QUICKSIGHT_USER = 'quicksight_user'; - - /** - * @var string - */ - protected const KEY_ROLE = 'role'; - - /** - * @param mixed $value - * - * @return mixed|array - */ - 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/External/AmazonQuicksightToAwsQuicksightClientAdapter.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php index d5968fa..7cacef3 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php @@ -28,16 +28,6 @@ public function __construct(AmazonQuicksightConfig $config) $this->quicksightClient = new QuickSightClient($this->getQuicksightClientConfiguration($config)); } - /** - * @param array $registerUserRequestData - * - * @return \Aws\ResultInterface - */ - public function registerUser(array $registerUserRequestData): ResultInterface - { - return $this->quicksightClient->registerUser($registerUserRequestData); - } - /** * @param array $generateEmbedUrlRequestData * @@ -48,16 +38,6 @@ public function generateEmbedUrlForRegisteredUser(array $generateEmbedUrlRequest return $this->quicksightClient->generateEmbedUrlForRegisteredUser($generateEmbedUrlRequestData); } - /** - * @param array $deleteUserRequestData - * - * @return \Aws\ResultInterface - */ - public function deleteUserByPrincipalId(array $deleteUserRequestData): ResultInterface - { - return $this->quicksightClient->deleteUserByPrincipalId($deleteUserRequestData); - } - /** * @param array $deleteUserRequestData * @@ -78,16 +58,6 @@ public function listUsers(array $listUsersRequestData): ResultInterface return $this->quicksightClient->listUsers($listUsersRequestData); } - /** - * @param array $updateUserRequestData - * - * @return \Aws\ResultInterface - */ - public function updateUser(array $updateUserRequestData): ResultInterface - { - return $this->quicksightClient->updateUser($updateUserRequestData); - } - /** * @param array $startAssetBundleImportJobRequestData * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php index 6c96199..8b650e0 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php @@ -11,13 +11,6 @@ interface AmazonQuicksightToAwsQuicksightClientInterface { - /** - * @param array $registerUserRequestData - * - * @return \Aws\ResultInterface - */ - public function registerUser(array $registerUserRequestData): ResultInterface; - /** * @param array $generateEmbedUrlRequestData * @@ -25,13 +18,6 @@ public function registerUser(array $registerUserRequestData): ResultInterface; */ public function generateEmbedUrlForRegisteredUser(array $generateEmbedUrlRequestData): ResultInterface; - /** - * @param array $deleteUserRequestData - * - * @return \Aws\ResultInterface - */ - public function deleteUserByPrincipalId(array $deleteUserRequestData): ResultInterface; - /** * @param array $deleteUserRequestData * @@ -46,13 +32,6 @@ public function deleteUser(array $deleteUserRequestData): ResultInterface; */ public function listUsers(array $listUsersRequestData): ResultInterface; - /** - * @param array $updateUserRequestData - * - * @return \Aws\ResultInterface - */ - public function updateUser(array $updateUserRequestData): ResultInterface; - /** * @param array $startAssetBundleImportJobRequestData * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToMessengerFacadeBridge.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToMessengerFacadeBridge.php index 8b1abe0..89183d7 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToMessengerFacadeBridge.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToMessengerFacadeBridge.php @@ -24,16 +24,6 @@ public function __construct($messengerFacade) $this->messengerFacade = $messengerFacade; } - /** - * @param \Generated\Shared\Transfer\MessageTransfer $message - * - * @return void - */ - public function addErrorMessage(MessageTransfer $message): void - { - $this->messengerFacade->addErrorMessage($message); - } - /** * @param \Generated\Shared\Transfer\MessageTransfer $message * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToMessengerFacadeInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToMessengerFacadeInterface.php index 83f2ebf..69f632d 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToMessengerFacadeInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/Facade/AmazonQuicksightToMessengerFacadeInterface.php @@ -11,13 +11,6 @@ interface AmazonQuicksightToMessengerFacadeInterface { - /** - * @param \Generated\Shared\Transfer\MessageTransfer $message - * - * @return void - */ - public function addErrorMessage(MessageTransfer $message): void; - /** * @param \Generated\Shared\Transfer\MessageTransfer $message * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php index 69c38b9..d4c5abc 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php @@ -36,46 +36,6 @@ public function createQuicksightUser(QuicksightUserTransfer $quicksightUserTrans ->mapQuicksightUserEntityToQuicksightUserTransfer($quicksightUserEntity, $quicksightUserTransfer); } - /** - * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUserTransfer - */ - public function updateQuicksightUser(QuicksightUserTransfer $quicksightUserTransfer): QuicksightUserTransfer - { - $quicksightUserQuery = $this->getFactory()->getQuicksightUserQuery(); - $quicksightUserQuery->filterByIdQuicksightUser($quicksightUserTransfer->getIdQuicksightUserOrFail()); - - $quicksightUserEntity = $quicksightUserQuery->findOne(); - - if ($quicksightUserEntity === null) { - return $quicksightUserTransfer; - } - - $quicksightUserEntity = $this->getFactory() - ->createQuicksightUserMapper() - ->mapQuicksightUserTransferToQuicksightUserEntity($quicksightUserTransfer, $quicksightUserEntity); - - $quicksightUserEntity->save(); - - return $this->getFactory() - ->createQuicksightUserMapper() - ->mapQuicksightUserEntityToQuicksightUserTransfer($quicksightUserEntity, $quicksightUserTransfer); - } - - /** - * @param list $quicksightUserIds - * - * @return void - */ - public function deleteQuicksightUsers(array $quicksightUserIds): void - { - $this->getFactory() - ->getQuicksightUserQuery() - ->filterByIdQuicksightUser_In($quicksightUserIds) - ->delete(); - } - /** * @param list $userIds * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php index 209f100..4d5b45b 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php @@ -19,20 +19,6 @@ interface AmazonQuicksightEntityManagerInterface */ public function createQuicksightUser(QuicksightUserTransfer $quicksightUserTransfer): QuicksightUserTransfer; - /** - * @param \Generated\Shared\Transfer\QuicksightUserTransfer $quicksightUserTransfer - * - * @return \Generated\Shared\Transfer\QuicksightUserTransfer - */ - public function updateQuicksightUser(QuicksightUserTransfer $quicksightUserTransfer): QuicksightUserTransfer; - - /** - * @param list $quicksightUserIds - * - * @return void - */ - public function deleteQuicksightUsers(array $quicksightUserIds): void; - /** * @param list $userIds * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig index 01fe805..2a6f215 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig @@ -12,7 +12,15 @@ {% block content %} {% embed '@Gui/Partials/widget.twig' %} {% block widget_content %} -

{{ 'Please be aware that all Analytics dashboards and configurations, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon reset process. Owner of default assets will be replaced with the user who initiated the reset process by clicking this button.' | trans }}

+

+ {{ 'If you want to start fresh with a new setup in Analytics, keep these critical points in mind:' | trans }} +

+
    +
  • {{ 'Resetting Analytics restores all default assets (dashboards, analyses, datasets) to their original state, erasing any modifications you\'ve made.' | trans }}
  • +
  • {{ 'The user performing the reset becomes the owner of the default assets, and all other users lose access to them.' | trans }}
  • +
  • {{ 'Custom assets created by other users remain under their ownership.' | trans }}
  • +
  • {{ 'IMPORTANT: If you or other authors use default datasets in custom analyses, such analyses won\'t be able to access data for all visuals. To avoid this, duplicate the relevant default datasets and associate them with the custom analyses before proceeding.' | trans | raw }}
  • +
{{ form_start(resetAnalyticsForm) }} {{ viewActionButton(app.request.headers.get('referer'), 'Cancel' | trans) }} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics-actions.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics-reset-action.twig similarity index 100% rename from src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics-actions.twig rename to src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics-reset-action.twig diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig index 7c4205a..d4c2edb 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig @@ -13,36 +13,34 @@ {% endfor %} {% endif %} -{% if isAssetBundleSuccessfullyInitialized and not isAssetBundleInitializationInProgress %} - {% if isQuicksightUserRoleAvailable %} - {% if quicksightGenerateEmbedUrlResponse.errors | length %} - {% for error in quicksightGenerateEmbedUrlResponse.errors %} - - {% endfor %} - {% endif %} - {% if quicksightGenerateEmbedUrlResponse.embedUrl is not null and quicksightGenerateEmbedUrlResponse.embedUrl.url is not null %} -
- - - {% endif %} - {% else %} -
- {{ 'No Analytics permission has been granted to the current user.' | trans }} -
- {% endif %} -{% elseif isAssetBundleInitializationInProgress %} - -{% else %} +{% if isEnableAnalyticsAllowed %}
-

{{ 'Spryker Analytics is not enabled yet' | trans }}

-

{{ 'You can enable Spryker Analytics to view and modify default dashboards with the ability to share them with other users. ' | trans }}

+

{{ 'Analytics is not enabled yet' | trans }}

+

{{ 'You can enable Analytics to view and modify dashboards with the ability to share them with other users. ' | trans }}

{{ viewActionButton(url('/amazon-quicksight/analytics/enable'), 'Enable Analytics' | trans) }}
+{% elseif isDisplayAnalyticsAllowed %} + {% if quicksightGenerateEmbedUrlResponse.errors | length %} + {% for error in quicksightGenerateEmbedUrlResponse.errors %} + + {% endfor %} + {% endif %} + {% if quicksightGenerateEmbedUrlResponse.embedUrl is not null and quicksightGenerateEmbedUrlResponse.embedUrl.url is not null %} +
+ + + {% endif %} +{% elseif isAssetBundleInitializationInProgress %} + +{% else %} +
+ {{ 'No Analytics permission has been granted to the current user.' | trans }} +
{% endif %} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig new file mode 100644 index 0000000..274a99d --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig @@ -0,0 +1,5 @@ +
+ + +
+ 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 deleted file mode 100644 index f3fc39d..0000000 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig +++ /dev/null @@ -1,9 +0,0 @@ -
- -
- {{ form_errors(userForm.quicksight_user_role) }} - {{ form_widget(userForm.quicksight_user_role) }} -
- {{ userForm.quicksight_user_role.vars.help | trans | raw }} -
-
diff --git a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersByUserCollectionResponseTest.php b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersByUserCollectionResponseTest.php deleted file mode 100644 index 9b089a7..0000000 --- a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersByUserCollectionResponseTest.php +++ /dev/null @@ -1,293 +0,0 @@ -getMockBuilder(AmazonQuicksightToMessengerFacadeInterface::class) - ->getMock(); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::FACADE_MESSENGER, $messengerFacadeMock); - } - - /** - * @return void - */ - public function testShouldPersistQuicksightUserWhenUserSuccessfullyRegisteredInQuicksight(): void - { - // Arrange - $userTransfer = $this->tester->haveUserWithNotPersistedQuicksightUserRole(static::QUICKSIGHT_USER_ROLE_READER); - - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $this->tester->getAwsQuicksightClientMockWithSuccessfulResponse( - $this->createRegisterUserSuccessfulResponse($userTransfer), - 'registerUser', - ), - ); - - $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); - - // Act - $userCollectionResponseTransfer = $this->tester->getFacade() - ->createQuicksightUsersByUserCollectionResponse($userCollectionResponseTransfer); - - // Assert - $this->assertCount(0, $userCollectionResponseTransfer->getErrors()); - $this->assertCount(1, $userCollectionResponseTransfer->getUsers()); - - $quicksightUserEntity = $this->tester->findQuicksightUserByIdUser($userTransfer->getIdUserOrFail()); - $this->assertNotNull($quicksightUserEntity); - - /** @var \Generated\Shared\Transfer\UserTransfer $userTransfer */ - $userTransfer = $userCollectionResponseTransfer->getUsers()->getIterator()->current(); - $this->assertNotNull($userTransfer->getQuicksightUser()); - $this->assertNotNull($userTransfer->getQuicksightUserOrFail()->getIdQuicksightUser()); - $this->assertNotNull($userTransfer->getQuicksightUserOrFail()->getArn()); - $this->assertNotNull($userTransfer->getQuicksightUserOrFail()->getPrincipalId()); - } - - /** - * @return void - */ - public function testShouldReturnErrorWhenQuicksightClientThrowsException(): void - { - // Arrange - $userTransfer = $this->tester->haveUserWithNotPersistedQuicksightUserRole(static::QUICKSIGHT_USER_ROLE_READER); - - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $this->tester->getAwsQuicksightClientMockWithErrorResponse( - $this->tester->getQuicksightExceptionMock(static::ERROR_MESSAGE_QUICKSIGHT_USER_REGISTER_FAILURE), - 'registerUser', - ), - ); - - $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); - - // Act - $userCollectionResponseTransfer = $this->tester->getFacade() - ->createQuicksightUsersByUserCollectionResponse($userCollectionResponseTransfer); - - // Assert - $this->assertCount(1, $userCollectionResponseTransfer->getErrors()); - $this->assertCount(1, $userCollectionResponseTransfer->getUsers()); - - /** @var \Generated\Shared\Transfer\ErrorTransfer $errorTransfer */ - $errorTransfer = $userCollectionResponseTransfer->getErrors()->getIterator()->current(); - $this->assertSame(static::ERROR_MESSAGE_QUICKSIGHT_USER_REGISTER_FAILURE, $errorTransfer->getMessage()); - $this->assertSame((string)$userCollectionResponseTransfer->getUsers()->getIterator()->key(), $errorTransfer->getEntityIdentifier()); - - /** @var \Generated\Shared\Transfer\UserTransfer $userTransfer */ - $userTransfer = $userCollectionResponseTransfer->getUsers()->getIterator()->current(); - $this->assertNotNull($userTransfer->getQuicksightUser()); - $this->assertNull($userTransfer->getQuicksightUserOrFail()->getIdQuicksightUser()); - $this->assertNull($userTransfer->getQuicksightUserOrFail()->getArn()); - $this->assertNull($userTransfer->getQuicksightUserOrFail()->getPrincipalId()); - } - - /** - * @return void - */ - public function testShouldReturnErrorWhenQuicksightUserRegisterResponseDoesNotContainUserKey(): void - { - // Arrange - $userTransfer = $this->tester->haveUserWithNotPersistedQuicksightUserRole(static::QUICKSIGHT_USER_ROLE_READER); - - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $this->tester->getAwsQuicksightClientMockWithSuccessfulResponse(new Result(), 'registerUser'), - ); - - $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); - - // Act - $userCollectionResponseTransfer = $this->tester->getFacade() - ->createQuicksightUsersByUserCollectionResponse($userCollectionResponseTransfer); - - // Assert - $this->assertCount(1, $userCollectionResponseTransfer->getErrors()); - $this->assertCount(1, $userCollectionResponseTransfer->getUsers()); - - /** @var \Generated\Shared\Transfer\ErrorTransfer $errorTransfer */ - $errorTransfer = $userCollectionResponseTransfer->getErrors()->getIterator()->current(); - $this->assertSame(static::ERROR_MESSAGE_USER_REGISTRATION_FAILED, $errorTransfer->getMessage()); - $this->assertSame((string)$userCollectionResponseTransfer->getUsers()->getIterator()->key(), $errorTransfer->getEntityIdentifier()); - - /** @var \Generated\Shared\Transfer\UserTransfer $userTransfer */ - $userTransfer = $userCollectionResponseTransfer->getUsers()->getIterator()->current(); - $this->assertNotNull($userTransfer->getQuicksightUser()); - $this->assertNull($userTransfer->getQuicksightUserOrFail()->getIdQuicksightUser()); - $this->assertNull($userTransfer->getQuicksightUserOrFail()->getArn()); - $this->assertNull($userTransfer->getQuicksightUserOrFail()->getPrincipalId()); - } - - /** - * @return void - */ - public function testShouldDoNothingWhenQuicksightUserRoleIsNotProvidedForUser(): void - { - // Arrange - $userTransfer = $this->tester->haveUser(); - - $awsQuicksightClientMock = $this->tester->getAwsQuicksightClientMock(); - $awsQuicksightClientMock->expects($this->never())->method('registerUser'); - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $awsQuicksightClientMock, - ); - - // Act - $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); - - // Act - $userCollectionResponseTransfer = $this->tester->getFacade() - ->createQuicksightUsersByUserCollectionResponse($userCollectionResponseTransfer); - - // Assert - $this->assertCount(0, $userCollectionResponseTransfer->getErrors()); - $this->assertCount(1, $userCollectionResponseTransfer->getUsers()); - $this->assertNull($userCollectionResponseTransfer->getUsers()->getIterator()->current()->getQuicksightUser()); - } - - /** - * @return void - */ - public function testShouldDoNothingWhenQuicksightUserAlreadyExistsForProvidedForUser(): void - { - // Arrange - $userTransfer = $this->tester->haveUser(); - $this->tester->haveQuicksightUser($userTransfer); - - $awsQuicksightClientMock = $this->tester->getAwsQuicksightClientMock(); - $awsQuicksightClientMock->expects($this->never())->method('registerUser'); - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $awsQuicksightClientMock, - ); - - // Act - $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); - - // Act - $userCollectionResponseTransfer = $this->tester->getFacade() - ->createQuicksightUsersByUserCollectionResponse($userCollectionResponseTransfer); - - // Assert - $this->assertCount(0, $userCollectionResponseTransfer->getErrors()); - $this->assertCount(1, $userCollectionResponseTransfer->getUsers()); - $this->assertNull($userCollectionResponseTransfer->getUsers()->getIterator()->current()->getQuicksightUser()); - } - - /** - * @return void - */ - public function testShouldDoNothingWhenQuicksightUserStatusIsNotApplicableForRegisteringQuicksightUser(): void - { - // Arrange - $userTransfer = $this->tester->haveUser([ - UserTransfer::STATUS => static::USER_STATUS_BLOCKED, - ]); - - $awsQuicksightClientMock = $this->tester->getAwsQuicksightClientMock(); - $awsQuicksightClientMock->expects($this->never())->method('registerUser'); - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $awsQuicksightClientMock, - ); - - // Act - $userCollectionResponseTransfer = (new UserCollectionResponseTransfer())->addUser($userTransfer); - - // Act - $userCollectionResponseTransfer = $this->tester->getFacade() - ->createQuicksightUsersByUserCollectionResponse($userCollectionResponseTransfer); - - // Assert - $this->assertCount(0, $userCollectionResponseTransfer->getErrors()); - $this->assertCount(1, $userCollectionResponseTransfer->getUsers()); - $this->assertNull($userCollectionResponseTransfer->getUsers()->getIterator()->current()->getQuicksightUser()); - } - - /** - * @param \Generated\Shared\Transfer\UserTransfer $userTransfer - * - * @return \Aws\ResultInterface - */ - protected function createRegisterUserSuccessfulResponse(UserTransfer $userTransfer): ResultInterface - { - $responseData = [ - 'RequestId' => time(), - 'User' => [ - 'Arn' => 'arn:aws:quicksight:eu-central-1:123456789012:user/default/' . $userTransfer->getUsername(), - 'PrincipalId' => '123456789012', - 'Role' => $userTransfer->getQuicksightUserOrFail()->getRoleOrFail(), - ], - ]; - - return new Result($responseData); - } -} diff --git a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/DeleteNotMatchedQuicksightUsersTest.php b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/DeleteNotMatchedQuicksightUsersTest.php deleted file mode 100644 index 5dfa401..0000000 --- a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/DeleteNotMatchedQuicksightUsersTest.php +++ /dev/null @@ -1,342 +0,0 @@ -tester->haveUser(); - $matchingQuicksightUserTransfer = (new QuicksightUserBuilder([ - QuicksightUserTransfer::USER_NAME => $userTransfer->getUsernameOrFail(), - QuicksightUserTransfer::ROLE => static::QUICKSIGHT_USER_ROLE_READER, - ]))->build(); - $notMatchingQuicksightUserTransfer = (new QuicksightUserBuilder([ - QuicksightUserTransfer::USER_NAME => 'non-existing-user@spryker.com', - QuicksightUserTransfer::ROLE => static::QUICKSIGHT_USER_ROLE_READER, - ]))->build(); - - $quicksightClientMock = $this->tester->getAwsQuicksightClientMockWithSuccessfulResponse( - $this->createListUsersSuccessfulResponse([ - $matchingQuicksightUserTransfer, - $notMatchingQuicksightUserTransfer, - ]), - 'listUsers', - ); - $quicksightClientMock->expects($this->once()) - ->method('deleteUserByPrincipalId') - ->willReturn(new Result()); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, $quicksightClientMock); - - // Act - $quicksightUserCollectionResponseTransfer = $this->tester->getFacade()->deleteNotMatchedQuicksightUsers(); - - // Assert - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getErrors()); - $this->assertCount(1, $quicksightUserCollectionResponseTransfer->getQuicksightUsers()); - - $this->assertSame( - $notMatchingQuicksightUserTransfer->getUserNameOrFail(), - $quicksightUserCollectionResponseTransfer->getQuicksightUsers()->getIterator()->current()->getUserNameOrFail(), - ); - } - - /** - * @return void - */ - public function testShouldDeleteRegisteredQuicksightUserWhenMatchedUserHasDeletedStatus(): void - { - // Arrange - $userTransfer = $this->tester->haveUser([UserTransfer::STATUS => static::USER_STATUS_DELETED]); - $quicksightUserTransfer = (new QuicksightUserBuilder([ - QuicksightUserTransfer::USER_NAME => $userTransfer->getUsernameOrFail(), - QuicksightUserTransfer::ROLE => static::QUICKSIGHT_USER_ROLE_READER, - ]))->build(); - - $quicksightClientMock = $this->tester->getAwsQuicksightClientMockWithSuccessfulResponse( - $this->createListUsersSuccessfulResponse([$quicksightUserTransfer]), - 'listUsers', - ); - $quicksightClientMock->expects($this->once()) - ->method('deleteUserByPrincipalId') - ->willReturn(new Result()); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, $quicksightClientMock); - - // Act - $quicksightUserCollectionResponseTransfer = $this->tester->getFacade()->deleteNotMatchedQuicksightUsers(); - - // Assert - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getErrors()); - $this->assertCount(1, $quicksightUserCollectionResponseTransfer->getQuicksightUsers()); - $this->assertSame( - $quicksightUserTransfer->getUserNameOrFail(), - $quicksightUserCollectionResponseTransfer->getQuicksightUsers()->getIterator()->current()->getUserNameOrFail(), - ); - } - - /** - * @return void - */ - public function testShouldDoNothingWhenEmptyUserListIsReturned(): void - { - // Arrange - $this->tester->haveUser(); - - $quicksightClientMock = $this->tester->getAwsQuicksightClientMockWithSuccessfulResponse( - $this->createListUsersSuccessfulResponse([]), - 'listUsers', - ); - $quicksightClientMock->expects($this->never()) - ->method('deleteUserByPrincipalId') - ->willReturn(new Result()); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, $quicksightClientMock); - - // Act - $quicksightUserCollectionResponseTransfer = $this->tester->getFacade()->deleteNotMatchedQuicksightUsers(); - - // Assert - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getErrors()); - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getQuicksightUsers()); - } - - /** - * @return void - */ - public function testShouldDoNothingWhenMatchedUserHavePersistedQuicksightUser(): void - { - // Arrange - $userTransfer = $this->tester->haveUser(); - $quicksightUserTransfer = $this->tester->haveQuicksightUser($userTransfer, [ - QuicksightUserTransfer::USER_NAME => $userTransfer->getUsernameOrFail(), - QuicksightUserTransfer::ROLE => static::QUICKSIGHT_USER_ROLE_READER, - ]); - - $quicksightClientMock = $this->tester->getAwsQuicksightClientMockWithSuccessfulResponse( - $this->createListUsersSuccessfulResponse([$quicksightUserTransfer]), - 'listUsers', - ); - $quicksightClientMock->expects($this->never()) - ->method('deleteUserByPrincipalId') - ->willReturn(new Result()); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, $quicksightClientMock); - - // Act - $quicksightUserCollectionResponseTransfer = $this->tester->getFacade()->deleteNotMatchedQuicksightUsers(); - - // Assert - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getErrors()); - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getQuicksightUsers()); - } - - /** - * @return void - */ - public function testShouldReturnEmptyCollectionWhenRegisteredQuicksightUserHasUnsupportedRole(): void - { - // Arrange - $userTransfer = $this->tester->haveUser(); - $quicksightUserTransfer = (new QuicksightUserBuilder([ - QuicksightUserTransfer::USER_NAME => 'non-existing-user@spryker.com', - QuicksightUserTransfer::ROLE => static::QUICKSIGHT_USER_ROLE_ADMIN, - ]))->build(); - - $quicksightClientMock = $this->tester->getAwsQuicksightClientMockWithSuccessfulResponse( - $this->createListUsersSuccessfulResponse([$quicksightUserTransfer]), - 'listUsers', - ); - $quicksightClientMock->expects($this->never()) - ->method('deleteUserByPrincipalId') - ->willReturn(new Result()); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, $quicksightClientMock); - - // Act - $quicksightUserCollectionResponseTransfer = $this->tester->getFacade()->deleteNotMatchedQuicksightUsers(); - - // Assert - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getErrors()); - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getQuicksightUsers()); - } - - /** - * @return void - */ - public function testShouldReturnErrorWhenQuicksightClientMethodListUsersThrowsException(): void - { - // Arrange - $this->tester->haveUser(); - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $this->tester->getAwsQuicksightClientMockWithErrorResponse( - $this->tester->getQuicksightExceptionMock(static::ERROR_MESSAGE_QUICKSIGHT_API_FAILURE), - 'listUsers', - ), - ); - - // Act - $quicksightUserCollectionResponseTransfer = $this->tester->getFacade()->deleteNotMatchedQuicksightUsers(); - - // Assert - $this->assertCount(1, $quicksightUserCollectionResponseTransfer->getErrors()); - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getQuicksightUsers()); - - $this->assertSame( - static::ERROR_MESSAGE_QUICKSIGHT_API_FAILURE, - $quicksightUserCollectionResponseTransfer->getErrors()->getIterator()->current()->getMessage(), - ); - } - - /** - * @return void - */ - public function testShouldReturnErrorWhenQuicksightClientMethodDeleteUserByPrincipalIdThrowsException(): void - { - // Arrange - $userTransfer = $this->tester->haveUser(); - $quicksightUserTransfer = (new QuicksightUserBuilder([ - QuicksightUserTransfer::USER_NAME => 'non-existing-user@spryker.com', - QuicksightUserTransfer::ROLE => static::QUICKSIGHT_USER_ROLE_READER, - ]))->build(); - - $quicksightClientMock = $this->tester->getAwsQuicksightClientMockWithSuccessfulResponse( - $this->createListUsersSuccessfulResponse([$quicksightUserTransfer]), - 'listUsers', - ); - $quicksightClientMock->method('deleteUserByPrincipalId') - ->willThrowException($this->tester->getQuicksightExceptionMock(static::ERROR_MESSAGE_QUICKSIGHT_API_FAILURE)); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, $quicksightClientMock); - - // Act - $quicksightUserCollectionResponseTransfer = $this->tester->getFacade()->deleteNotMatchedQuicksightUsers(); - - // Assert - $this->assertCount(1, $quicksightUserCollectionResponseTransfer->getErrors()); - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getQuicksightUsers()); - - $this->assertSame( - static::ERROR_MESSAGE_QUICKSIGHT_API_FAILURE, - $quicksightUserCollectionResponseTransfer->getErrors()->getIterator()->current()->getMessage(), - ); - } - - /** - * @return void - */ - public function testShouldReturnErrorWhenQuicksightListUsersResponseDoesNotContainUserListKey(): void - { - // Arrange - $this->tester->haveUser(); - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $this->tester->getAwsQuicksightClientMockWithSuccessfulResponse( - new Result([]), - 'listUsers', - ), - ); - - // Act - $quicksightUserCollectionResponseTransfer = $this->tester->getFacade()->deleteNotMatchedQuicksightUsers(); - - // Assert - $this->assertCount(1, $quicksightUserCollectionResponseTransfer->getErrors()); - $this->assertCount(0, $quicksightUserCollectionResponseTransfer->getQuicksightUsers()); - - $this->assertSame( - static::ERROR_MESSAGE_USERS_LIST_RETRIEVE_FAILED, - $quicksightUserCollectionResponseTransfer->getErrors()->getIterator()->current()->getMessage(), - ); - } - - /** - * @param list<\Generated\Shared\Transfer\QuicksightUserTransfer> $quicksightUserTransfers - * - * @return \Aws\ResultInterface - */ - protected function createListUsersSuccessfulResponse(array $quicksightUserTransfers): ResultInterface - { - $quicksightUserList = []; - foreach ($quicksightUserTransfers as $quicksightUserTransfer) { - $quicksightUserList[] = [ - 'Arn' => $quicksightUserTransfer->getArnOrFail(), - 'PrincipalId' => $quicksightUserTransfer->getPrincipalIdOrFail(), - 'UserName' => $quicksightUserTransfer->getUserNameOrFail(), - 'Role' => $quicksightUserTransfer->getRoleOrFail(), - ]; - } - - return new Result([ - static::RESPONSE_KEY_USER_LIST => $quicksightUserList, - ]); - } -} diff --git a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/EnableAnalyticsTest.php b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/EnableAnalyticsTest.php index c0bc981..220e19e 100644 --- a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/EnableAnalyticsTest.php +++ b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/EnableAnalyticsTest.php @@ -14,11 +14,9 @@ use Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer; use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\UserTransfer; -use Spryker\Shared\Kernel\Transfer\Exception\NullValueException; use Spryker\Shared\Kernel\Transfer\Exception\RequiredTransferPropertyException; use SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightDependencyProvider; use SprykerEco\Zed\AmazonQuicksight\Dependency\External\AmazonQuicksightToAwsQuicksightClientInterface; -use SprykerEco\Zed\AmazonQuicksight\Dependency\Facade\AmazonQuicksightToMessengerFacadeInterface; use SprykerEcoTest\Zed\AmazonQuicksight\AmazonQuicksightBusinessTester; class EnableAnalyticsTest extends Unit @@ -63,11 +61,6 @@ class EnableAnalyticsTest extends Unit */ protected const ERROR_MESSAGE_TEST = 'test error message'; - /** - * @var string - */ - protected const USER_STATUS_ACTIVE = 'active'; - /** * @uses \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig::QUICKSIGHT_USER_ROLE_READER * @@ -126,42 +119,20 @@ public function testThrowsRequiredTransferPropertyExceptionWhenRequiredPropertie $this->tester->getFacade()->enableAnalytics($enableQuicksightAnalyticsRequestTransfer); } - /** - * @return void - */ - public function testThrowsNullValueExceptionWhenRequiredPropertiesAreNotSet(): void - { - // Arrange - $enableQuicksightAnalyticsRequestTransfer = (new EnableQuicksightAnalyticsRequestTransfer()) - ->setUser(new UserTransfer()) - ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID); - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $this->tester->getAwsQuicksightClientMock(), - ); - - // Assert - $this->expectException(NullValueException::class); - - // Act - $this->tester->getFacade()->enableAnalytics($enableQuicksightAnalyticsRequestTransfer); - } - /** * @dataProvider returnsResponseWithErrorWhenValidationFailsDataProvider * * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer + * @param \Generated\Shared\Transfer\EnableQuicksightAnalyticsRequestTransfer $enableQuicksightAnalyticsRequestTransfer * * @return void */ public function testReturnsResponseWithErrorWhenValidationFails( - QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer + QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, + EnableQuicksightAnalyticsRequestTransfer $enableQuicksightAnalyticsRequestTransfer ): void { // Arrange $this->tester->haveQuicksightAssetBundleImportJob($quicksightAssetBundleImportJobTransfer->toArray()); - $enableQuicksightAnalyticsRequestTransfer = (new EnableQuicksightAnalyticsRequestTransfer()) - ->setUser(new UserTransfer()) - ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID); $this->tester->setDependency( AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, $this->tester->getAwsQuicksightClientMock(), @@ -180,69 +151,6 @@ public function testReturnsResponseWithErrorWhenValidationFails( ); } - /** - * @return void - */ - public function testReturnsResponseWithErrorWhenUserCreationFails(): void - { - // Arrange - $userTransfer = $this->tester->haveUser(); - $enableQuicksightAnalyticsRequestTransfer = (new EnableQuicksightAnalyticsRequestTransfer()) - ->setUser($userTransfer->setStatus(static::USER_STATUS_ACTIVE)) - ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID); - $messengerFacadeMock = $this - ->getMockBuilder(AmazonQuicksightToMessengerFacadeInterface::class) - ->getMock(); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::FACADE_MESSENGER, $messengerFacadeMock); - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $this->tester->getAwsQuicksightClientMockWithErrorResponse( - $this->tester->getQuicksightExceptionMock(static::ERROR_MESSAGE_TEST), - 'registerUser', - ), - ); - - // Act - $enableQuicksightAnalyticsResponseTransfer = $this->tester - ->getFacade() - ->enableAnalytics($enableQuicksightAnalyticsRequestTransfer); - - // Assert - $this->assertCount(1, $enableQuicksightAnalyticsResponseTransfer->getErrors()); - $this->assertSame( - static::ERROR_MESSAGE_TEST, - $enableQuicksightAnalyticsResponseTransfer->getErrors()->getIterator()->current()->getMessage(), - ); - } - - /** - * @return void - */ - public function testReturnsResponseWithErrorWhenUserUpdateFails(): void - { - // Arrange - $enableQuicksightAnalyticsRequestTransfer = $this->createEnableQuicksightAnalyticsRequestTransferWithUser(static::QUICKSIGHT_USER_ROLE_READER); - $this->tester->setDependency( - AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, - $this->tester->getAwsQuicksightClientMockWithErrorResponse( - $this->tester->getQuicksightExceptionMock(static::ERROR_MESSAGE_TEST), - 'updateUser', - ), - ); - - // Act - $enableQuicksightAnalyticsResponseTransfer = $this->tester - ->getFacade() - ->enableAnalytics($enableQuicksightAnalyticsRequestTransfer); - - // Assert - $this->assertCount(1, $enableQuicksightAnalyticsResponseTransfer->getErrors()); - $this->assertSame( - static::ERROR_MESSAGE_TEST, - $enableQuicksightAnalyticsResponseTransfer->getErrors()->getIterator()->current()->getMessage(), - ); - } - /** * @return void */ @@ -359,86 +267,6 @@ public function testResetsNotFinishedAssetBundleImportJob(): void ); } - /** - * @return void - */ - public function testCreatesNewQuicksightAuthorUser(): void - { - // Arrange - $userTransfer = $this->tester->haveUser(); - $enableQuicksightAnalyticsRequestTransfer = (new EnableQuicksightAnalyticsRequestTransfer()) - ->setUser($userTransfer->setStatus(static::USER_STATUS_ACTIVE)) - ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID); - $awsQuicksightClientMock = $this->getAwsQuicksightClientMockWithExpectation(new Result(), 'startAssetBundleImportJob'); - $principalId = '123456789012'; - $arn = 'arn:aws:quicksight:eu-central-1:123456789012:user/default/' . $userTransfer->getUsername(); - $awsQuicksightClientMock->expects($this->once())->method('registerUser')->willReturn(new Result([ - 'RequestId' => time(), - 'User' => [ - 'Arn' => $arn, - 'PrincipalId' => $principalId, - 'Role' => static::QUICKSIGHT_USER_ROLE_AUTHOR, - ], - ])); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, $awsQuicksightClientMock); - - // Act - $enableQuicksightAnalyticsResponseTransfer = $this->tester - ->getFacadeWithMocks() - ->enableAnalytics($enableQuicksightAnalyticsRequestTransfer); - - // Assert - $quicksightUserEntity = $this->tester->findQuicksightUserByIdUser($userTransfer->getIdUserOrFail()); - $this->assertNotNull($quicksightUserEntity); - $this->assertSame(static::QUICKSIGHT_USER_ROLE_AUTHOR, $quicksightUserEntity->getRole()); - $this->assertSame($principalId, $quicksightUserEntity->getPrincipalId()); - $this->assertSame($arn, $quicksightUserEntity->getArn()); - $this->assertCount(0, $enableQuicksightAnalyticsResponseTransfer->getErrors()); - $this->assertNotNull($this->tester->findQuicksightAssetBundleImportJobQueryByJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID)); - } - - /** - * @return void - */ - public function testUpdatesQuicksightReaderUserToAuthor(): void - { - // Arrange - $userTransfer = $this->tester->haveUser(); - $userTransfer->setQuicksightUser($this->tester->haveQuicksightUser($userTransfer, [ - QuicksightUserTransfer::ROLE => static::QUICKSIGHT_USER_ROLE_READER, - ])); - $enableQuicksightAnalyticsRequestTransfer = (new EnableQuicksightAnalyticsRequestTransfer()) - ->setUser($userTransfer->setStatus(static::USER_STATUS_ACTIVE)) - ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID); - - $awsQuicksightClientMock = $this->getAwsQuicksightClientMockWithExpectation(new Result(), 'startAssetBundleImportJob'); - $principalId = '123456789012'; - $arn = 'arn:aws:quicksight:eu-central-1:123456789012:user/default/' . $userTransfer->getUsername(); - $awsQuicksightClientMock->expects($this->once())->method('updateUser')->willReturn(new Result([ - 'RequestId' => time(), - 'User' => [ - 'Arn' => $arn, - 'PrincipalId' => $principalId, - 'Role' => static::QUICKSIGHT_USER_ROLE_AUTHOR, - ], - ])); - $this->tester->setDependency(AmazonQuicksightDependencyProvider::AWS_QUICKSIGHT_CLIENT, $awsQuicksightClientMock); - - // Act - $enableQuicksightAnalyticsResponseTransfer = $this->tester - ->getFacadeWithMocks() - ->enableAnalytics($enableQuicksightAnalyticsRequestTransfer); - - // Assert - $quicksightUserEntity = $this->tester->findQuicksightUserByIdUser($userTransfer->getIdUserOrFail()); - $this->assertNotNull($quicksightUserEntity); - $this->assertSame(static::QUICKSIGHT_USER_ROLE_AUTHOR, $quicksightUserEntity->getRole()); - $this->assertSame($principalId, $quicksightUserEntity->getPrincipalId()); - $this->assertSame($arn, $quicksightUserEntity->getArn()); - $this->assertCount(0, $enableQuicksightAnalyticsResponseTransfer->getErrors()); - $this->assertNotNull($this->tester->findQuicksightAssetBundleImportJobQueryByJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID)); - } - /** * @return array> */ @@ -455,7 +283,7 @@ protected function throwsRequiredTransferPropertyExceptionWhenRequiredProperties } /** - * @return array> + * @return array> */ protected function returnsResponseWithErrorWhenValidationFailsDataProvider(): array { @@ -465,12 +293,42 @@ protected function returnsResponseWithErrorWhenValidationFailsDataProvider(): ar ->setIsInitialized(true) ->setJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID) ->setStatus(static::ASSET_BUNDLE_IMPORT_JOB_STATUS_SUCCESSFUL), + (new EnableQuicksightAnalyticsRequestTransfer()) + ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID) + ->setUser((new UserTransfer())->setQuicksightUser( + (new QuicksightUserTransfer())->setRole(static::QUICKSIGHT_USER_ROLE_AUTHOR), + )), ], 'Asset bundle initialization is in progress' => [ (new QuicksightAssetBundleImportJobTransfer()) ->setIsInitialized(false) ->setJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID) ->setStatus(static::ASSET_BUNDLE_IMPORT_JOB_STATUS_IN_PROGRESS), + (new EnableQuicksightAnalyticsRequestTransfer()) + ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID) + ->setUser((new UserTransfer())->setQuicksightUser( + (new QuicksightUserTransfer())->setRole(static::QUICKSIGHT_USER_ROLE_AUTHOR), + )), + ], + 'Quicksight user does not exist' => [ + (new QuicksightAssetBundleImportJobTransfer()) + ->setIsInitialized(false) + ->setJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID) + ->setStatus(static::ASSET_BUNDLE_IMPORT_JOB_STATUS_FAILED_ROLLBACK_COMPLETED), + (new EnableQuicksightAnalyticsRequestTransfer()) + ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID) + ->setUser(new UserTransfer()), + ], + 'Quicksight user is not Author' => [ + (new QuicksightAssetBundleImportJobTransfer()) + ->setIsInitialized(false) + ->setJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID) + ->setStatus(static::ASSET_BUNDLE_IMPORT_JOB_STATUS_FAILED_ROLLBACK_COMPLETED), + (new EnableQuicksightAnalyticsRequestTransfer()) + ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID) + ->setUser((new UserTransfer())->setQuicksightUser( + (new QuicksightUserTransfer())->setRole(static::QUICKSIGHT_USER_ROLE_READER), + )), ], ]; } @@ -489,7 +347,7 @@ protected function createEnableQuicksightAnalyticsRequestTransferWithUser( ])); return (new EnableQuicksightAnalyticsRequestTransfer()) - ->setUser($userTransfer->setStatus(static::USER_STATUS_ACTIVE)) + ->setUser($userTransfer) ->setAssetBundleImportJobId(static::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID); } diff --git a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php index 5bd6ed7..f1b264e 100644 --- a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php +++ b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php @@ -73,11 +73,32 @@ class ExpandAnalyticsCollectionWithQuicksightAnalyticsTest extends Unit protected const TEMPLATE_PATH_QUICKSIGHT_ANALYTICS = '@AmazonQuicksight/_partials/quicksight-analytics.twig'; /** - * @uses \SprykerEco\Zed\AmazonQuicksight\Business\Expander\AnalyticsExpander::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_ACTIONS + * @uses \SprykerEco\Zed\AmazonQuicksight\Business\Expander\AnalyticsExpander::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_RESET_ACTION * * @var string */ - protected const TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_ACTIONS = '@AmazonQuicksight/_partials/quicksight-analytics-actions.twig'; + protected const TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_RESET_ACTION = '@AmazonQuicksight/_partials/quicksight-analytics-reset-action.twig'; + + /** + * @uses \SprykerEco\Zed\AmazonQuicksight\Business\Expander\AnalyticsExpander::TEMPLATE_PATH_SYNCHRONIZE_QUICKSIGHT_USERS_ACTION + * + * @var string + */ + protected const TEMPLATE_PATH_SYNCHRONIZE_QUICKSIGHT_USERS_ACTION = '@AmazonQuicksight/_partials/synchronize-quicksight-users-action.twig'; + + /** + * @uses \SprykerEco\Zed\AmazonQuicksight\Business\Expander\AnalyticsExpander::FORM_NAME_SYNCHRONIZE_QUICKSIGHT_USERS + * + * @var string + */ + protected const FORM_NAME_SYNCHRONIZE_QUICKSIGHT_USERS = 'synchronizeQuicksightUsersForm'; + + /** + * @uses \SprykerEco\Zed\AmazonQuicksight\Business\Expander\AnalyticsExpander::FIELD_NAME_TOKEN + * + * @var string + */ + protected const FIELD_NAME_TOKEN = '_token'; /** * @uses \SprykerEco\Zed\AmazonQuicksight\AmazonQuicksightConfig::DEFAULT_ASSET_BUNDLE_IMPORT_JOB_ID @@ -195,16 +216,17 @@ public function testExpandsCollectionWhenQuicksightUserExistsWithoutRole(): void * @dataProvider expandsCollectionWhenQuicksightUserExistsWithRoleDataProvider * * @param string $role + * @param bool $isEnableAnalyticsAllowed * * @return void */ - public function testExpandsCollectionWhenQuicksightUserExistsWithRole(string $role): void + public function testExpandsCollectionWhenQuicksightUserExistsWithRole(string $role, bool $isEnableAnalyticsAllowed): void { // Arrange $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( + $isEnableAnalyticsAllowed, false, false, - true, new QuicksightGenerateEmbedUrlResponseTransfer(), )); $analyticsRequestTransfer = $this->tester->haveAnalyticsRequestWithQuicksightUser($role); @@ -228,6 +250,8 @@ public function testExpandsCollectionWhenQuicksightUserExistsWithRole(string $ro * @param bool $isInitializedInitially * @param bool $isInitializedAfterSync * @param bool $isInitializationInProgress + * @param bool $isEnableAnalyticsAllowed + * @param bool $isDisplayAnalyticsAllowed * @param string $jobStatusAfterSync * @param \Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer * @@ -237,14 +261,16 @@ public function testExpandsCollectionWhenQuicksightAssetBundleImportJobIsInProgr bool $isInitializedInitially, bool $isInitializedAfterSync, bool $isInitializationInProgress, + bool $isEnableAnalyticsAllowed, + bool $isDisplayAnalyticsAllowed, string $jobStatusAfterSync, QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer ): void { // Arrange $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( - $isInitializedAfterSync, + $isEnableAnalyticsAllowed, $isInitializationInProgress, - true, + $isDisplayAnalyticsAllowed, $quicksightGenerateEmbedUrlResponseTransfer, (new QuicksightAssetBundleImportJobTransfer()) ->setIsInitialized($isInitializedAfterSync) @@ -291,7 +317,7 @@ public function testExpandsCollectionWhenDescribeAssetBundleImportJobApiRequestF $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( false, true, - true, + false, new QuicksightGenerateEmbedUrlResponseTransfer(), (new QuicksightAssetBundleImportJobTransfer()) ->setIsInitialized(false) @@ -332,7 +358,7 @@ public function testExpandsCollectionWhenGenerateEmbedUrlApiRequestFails(bool $t { // Arrange $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( - true, + false, false, true, (new QuicksightGenerateEmbedUrlResponseTransfer()) @@ -369,15 +395,19 @@ public function testExpandsCollectionWhenGenerateEmbedUrlApiRequestFails(bool $t * @dataProvider expandsCollectionWhenQuicksightAssetBundleImportJobFinishedDataProvider * * @param bool $isInitializedInitially + * @param bool $isEnableAnalyticsAllowed + * @param bool $isDisplayAnalyticsAllowed * @param string $initialJobStatus * @param \Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer - * @param array $errorTransfers + * @param list<\Generated\Shared\Transfer\ErrorTransfer> $errorTransfers * * @return void */ public function testExpandsCollectionWhenQuicksightAssetBundleImportJobFinished( bool $isInitializedInitially, + bool $isEnableAnalyticsAllowed, + bool $isDisplayAnalyticsAllowed, string $initialJobStatus, QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer, QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, @@ -385,9 +415,9 @@ public function testExpandsCollectionWhenQuicksightAssetBundleImportJobFinished( ): void { // Arrange $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( - $isInitializedInitially, + $isEnableAnalyticsAllowed, false, - true, + $isDisplayAnalyticsAllowed, $quicksightGenerateEmbedUrlResponseTransfer, $quicksightAssetBundleImportJobTransfer, )); @@ -449,13 +479,13 @@ protected function throwsExceptionWhenRequiredPropertiesAreNotSetDataProvider(): } /** - * @return array> + * @return array> */ protected function expandsCollectionWhenQuicksightUserExistsWithRoleDataProvider(): array { return [ - 'Author role' => [static::QUICKSIGHT_USER_ROLE_AUTHOR], - 'Reader role' => [static::QUICKSIGHT_USER_ROLE_READER], + 'Author role' => [static::QUICKSIGHT_USER_ROLE_AUTHOR, true], + 'Reader role' => [static::QUICKSIGHT_USER_ROLE_READER, false], ]; } @@ -469,6 +499,8 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobIsInProgre false, false, true, + false, + false, static::ASSET_BUNDLE_IMPORT_JOB_STATUS_IN_PROGRESS, new QuicksightGenerateEmbedUrlResponseTransfer(), ], @@ -476,6 +508,8 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobIsInProgre false, true, false, + false, + true, static::ASSET_BUNDLE_IMPORT_JOB_STATUS_SUCCESSFUL, (new QuicksightGenerateEmbedUrlResponseTransfer())->setEmbedUrl((new QuicksightEmbedUrlTransfer())->setUrl(static::EMBED_URL_TEST)), ], @@ -483,6 +517,8 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobIsInProgre true, true, true, + false, + false, static::ASSET_BUNDLE_IMPORT_JOB_STATUS_IN_PROGRESS, (new QuicksightGenerateEmbedUrlResponseTransfer())->setEmbedUrl((new QuicksightEmbedUrlTransfer())->setUrl(static::EMBED_URL_TEST)), ], @@ -490,6 +526,8 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobIsInProgre true, true, false, + false, + true, static::ASSET_BUNDLE_IMPORT_JOB_STATUS_SUCCESSFUL, (new QuicksightGenerateEmbedUrlResponseTransfer())->setEmbedUrl((new QuicksightEmbedUrlTransfer())->setUrl(static::EMBED_URL_TEST)), ], @@ -525,6 +563,8 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobFinishedDa { return [ 'Job successfully finished' => [ + true, + false, true, static::ASSET_BUNDLE_IMPORT_JOB_STATUS_SUCCESSFUL, (new QuicksightGenerateEmbedUrlResponseTransfer())->setEmbedUrl((new QuicksightEmbedUrlTransfer())->setUrl(static::EMBED_URL_TEST)), @@ -536,6 +576,8 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobFinishedDa [], ], 'Reset job finished with errors' => [ + true, + false, true, static::ASSET_BUNDLE_IMPORT_JOB_STATUS_FAILED_ROLLBACK_COMPLETED, (new QuicksightGenerateEmbedUrlResponseTransfer())->setEmbedUrl((new QuicksightEmbedUrlTransfer())->setUrl(static::EMBED_URL_TEST)), @@ -552,6 +594,8 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobFinishedDa [(new ErrorTransfer())->setMessage(static::ERROR_MESSAGE_DESCRIBE_ASSET_BUNDLE_IMPORT_JOB_FAILED)], ], 'Enable job finished with errors' => [ + false, + true, false, static::ASSET_BUNDLE_IMPORT_JOB_STATUS_FAILED_ROLLBACK_COMPLETED, new QuicksightGenerateEmbedUrlResponseTransfer(), @@ -571,18 +615,18 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobFinishedDa } /** - * @param bool $isAssetBundleSuccessfullyInitialized + * @param bool $isEnableAnalyticsAllowed * @param bool $isAssetBundleInitializationInProgress - * @param bool $isQuicksightUserRoleAvailable + * @param bool $isDisplayAnalyticsAllowed * @param \Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer|null $quicksightAssetBundleImportJobTransfer * * @return \PHPUnit\Framework\MockObject\MockObject|\Twig\Environment */ protected function getTwigMock( - bool $isAssetBundleSuccessfullyInitialized, + bool $isEnableAnalyticsAllowed, bool $isAssetBundleInitializationInProgress, - bool $isQuicksightUserRoleAvailable, + bool $isDisplayAnalyticsAllowed, QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer, ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer = null ): Environment { @@ -595,15 +639,22 @@ protected function getTwigMock( [ $this->equalTo(static::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS), $this->equalTo([ - 'isAssetBundleSuccessfullyInitialized' => $isAssetBundleSuccessfullyInitialized, + 'isEnableAnalyticsAllowed' => $isEnableAnalyticsAllowed, 'isAssetBundleInitializationInProgress' => $isAssetBundleInitializationInProgress, - 'isQuicksightUserRoleAvailable' => $isQuicksightUserRoleAvailable, + 'isDisplayAnalyticsAllowed' => $isDisplayAnalyticsAllowed, 'quicksightGenerateEmbedUrlResponse' => $quicksightGenerateEmbedUrlResponseTransfer, 'quicksightAssetBundleImportJob' => $quicksightAssetBundleImportJobTransfer, ]), ], [ - $this->equalTo(static::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_ACTIONS), + $this->equalTo(static::TEMPLATE_PATH_SYNCHRONIZE_QUICKSIGHT_USERS_ACTION), + $this->equalTo([ + 'formName' => static::FORM_NAME_SYNCHRONIZE_QUICKSIGHT_USERS, + 'tokenFieldName' => static::FIELD_NAME_TOKEN, + ]), + ], + [ + $this->equalTo(static::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS_RESET_ACTION), $this->equalTo([]), ], );