From 082b8eb692419e1c5c69033f51d3ce53b3cd375b Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Mon, 4 Nov 2024 10:40:56 +0100 Subject: [PATCH 01/18] Removed create/update users when enabling the analytics --- .../Transfer/amazon_quicksight.transfer.xml | 13 -- .../AmazonQuicksightBusinessFactory.php | 25 --- .../AmazonQuicksightFacadeInterface.php | 2 - .../UserAmazonQuicksightApiClient.php | 59 ----- ...UserAmazonQuicksightApiClientInterface.php | 8 - .../Business/Enabler/AssetBundleEnabler.php | 17 -- .../Business/Expander/AnalyticsExpander.php | 25 ++- .../Mapper/AmazonQuicksightMapper.php | 17 -- .../AmazonQuicksightMapperInterface.php | 12 - .../AssetBundleQuicksightUserProcessor.php | 105 --------- ...BundleQuicksightUserProcessorInterface.php | 23 -- .../Updater/QuicksightUserUpdater.php | 57 ----- .../QuicksightUserUpdaterInterface.php | 21 -- .../QuicksightAnalyticsRequestValidator.php | 25 ++- ...ightAnalyticsRequestValidatorInterface.php | 15 +- ...QuicksightToAwsQuicksightClientAdapter.php | 10 - ...icksightToAwsQuicksightClientInterface.php | 7 - .../AmazonQuicksightEntityManager.php | 27 --- ...AmazonQuicksightEntityManagerInterface.php | 7 - .../_partials/quicksight-analytics.twig | 38 ++-- .../Business/Facade/EnableAnalyticsTest.php | 212 +++--------------- 21 files changed, 102 insertions(+), 623 deletions(-) delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Business/Processor/AssetBundleQuicksightUserProcessor.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Business/Processor/AssetBundleQuicksightUserProcessorInterface.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Business/Updater/QuicksightUserUpdater.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Business/Updater/QuicksightUserUpdaterInterface.php diff --git a/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml b/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml index 2c0405c..6dadc6f 100644 --- a/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml +++ b/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml @@ -266,19 +266,6 @@ - - - - - - - - - - - - - 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/AmazonQuicksightFacadeInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php index d3e3f35..0b05a1f 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php @@ -139,8 +139,6 @@ public function deleteNotMatchedQuicksightUsers(): QuicksightUserCollectionRespo * - 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..228384b 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php @@ -17,8 +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; @@ -78,11 +76,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 */ @@ -305,48 +298,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 */ @@ -392,14 +343,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..5eceeb1 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php @@ -10,7 +10,6 @@ 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; @@ -51,11 +50,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/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..938a413 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php @@ -129,25 +129,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), + 'isEnableAnalyticsEnabled' => $this->quicksightAnalyticsRequestValidator->isEnableAnalyticsEnabled( + $quicksightAssetBundleImportJobTransfer, + $quicksightUserTransfer, + ), + 'isDisplayAnalyticsEnabled' => $this->quicksightAnalyticsRequestValidator->isDisplayAnalyticsEnabled( + $quicksightAssetBundleImportJobTransfer, + $quicksightUserTransfer, + ), ], ); diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php index ca4ada9..ee2b062 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php @@ -19,7 +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; @@ -268,22 +267,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..ea6fd94 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php @@ -16,7 +16,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; @@ -134,17 +133,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/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->isEnableAnalyticsEnabled($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { $enableQuicksightAnalyticsResponseTransfer->addError( (new ErrorTransfer())->setMessage(static::ERROR_MESSAGE_ENABLE_ANALYTICS_FAILED), ); @@ -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 + ?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 isDisplayAnalyticsEnabled( + ?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..01496bc 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php @@ -51,11 +51,24 @@ public function isResetAnalyticsEnabled( /** * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer|null $quicksightAssetBundleImportJobTransfer + * @param \Generated\Shared\Transfer\QuicksightUserTransfer|null $quicksightUserTransfer * * @return bool */ public function isEnableAnalyticsEnabled( - ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer + ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, + ?QuicksightUserTransfer $quicksightUserTransfer + ): bool; + + /** + * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer|null $quicksightAssetBundleImportJobTransfer + * @param \Generated\Shared\Transfer\QuicksightUserTransfer|null $quicksightUserTransfer + * + * @return bool + */ + public function isDisplayAnalyticsEnabled( + ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, + ?QuicksightUserTransfer $quicksightUserTransfer ): bool; /** diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php index d5968fa..7937019 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php @@ -78,16 +78,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..a0c18bf 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php @@ -46,13 +46,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/Persistence/AmazonQuicksightEntityManager.php b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php index 69c38b9..451ec67 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php @@ -36,33 +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 * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php index 209f100..09ad2b0 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php @@ -19,13 +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 * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig index 7c4205a..b328a16 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig @@ -13,26 +13,7 @@ {% 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 isEnableAnalyticsEnabled %}
@@ -45,4 +26,21 @@ {{ viewActionButton(url('/amazon-quicksight/analytics/enable'), 'Enable Analytics' | trans) }}
+{% elseif isDisplayAnalyticsEnabled %} + {% 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/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); } From 5782c4c8dda28e495d143ae8049e4ae53234ca8e Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Mon, 4 Nov 2024 17:34:47 +0100 Subject: [PATCH 02/18] Sync users --- data/translation/Zed/de_DE.csv | 3 + data/translation/Zed/en_US.csv | 3 + .../AmazonQuicksightDependencyProvider.php | 22 +++++ .../Business/Expander/AnalyticsExpander.php | 29 +++++- .../AmazonQuicksightCommunicationFactory.php | 9 ++ .../Controller/AnalyticsController.php | 2 +- .../Controller/UserController.php | 95 +++++++++++++++++++ ...=> quicksight-analytics-reset-action.twig} | 0 .../synchronize-quicksight-users-action.twig | 5 + 9 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php rename src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/{quicksight-analytics-actions.twig => quicksight-analytics-reset-action.twig} (100%) create mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig diff --git a/data/translation/Zed/de_DE.csv b/data/translation/Zed/de_DE.csv index 82c77bd..4ccd2c1 100644 --- a/data/translation/Zed/de_DE.csv +++ b/data/translation/Zed/de_DE.csv @@ -12,3 +12,6 @@ Analytics,Analytics "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 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..a1715d0 100644 --- a/data/translation/Zed/en_US.csv +++ b/data/translation/Zed/en_US.csv @@ -12,3 +12,6 @@ Analytics,Analytics "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 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/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/Expander/AnalyticsExpander.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php index 938a413..06a8b03 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_TOKEN = '_token'; /** * @var \SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface @@ -169,12 +184,20 @@ protected function expandAnalyticsActions( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): AnalyticsCollectionTransfer { + $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_TOKEN, + ]), + )); + if (!$this->quicksightAnalyticsRequestValidator->isResetAnalyticsEnabled($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/Communication/AmazonQuicksightCommunicationFactory.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php index 6fc131f..07aa488 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php @@ -19,6 +19,7 @@ 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() @@ -79,4 +80,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/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..bafb38b --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php @@ -0,0 +1,95 @@ + + */ + public function synchronizeQuicksightUsersAction(Request $request): RedirectResponse|array + { + $tokenValue = (string)$request->get(static::FIELD_NAME_TOKEN); + + if (!$this->validateCsrfToken(static::FORM_NAME_SYNCHRONIZE_QUICKSIGHT_USERS, $tokenValue)) { + $this->addErrorMessage(static::ERROR_MESSAGE_CSRF_TOKEN_INVALID); + + return $this->redirectResponse(static::URL_ANALYTICS); + } + + $quicksightUserCollectionResponseTransfer = $this->getFacade()->createMatchedQuicksightUsers(); + + if ($quicksightUserCollectionResponseTransfer->getErrors()->count() === 0) { + $this->addSuccessMessage(static::SUCCESS_MESSAGE_USERS_SYNCHRONIZED); + + return $this->redirectResponse(static::URL_ANALYTICS); + } + + foreach ($quicksightUserCollectionResponseTransfer->getErrors() as $errorTransfer) { + $this->addErrorMessage($errorTransfer->getMessageOrFail()); + } + + return $this->redirectResponse(static::URL_ANALYTICS); + } + + /** + * @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); + } +} 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/synchronize-quicksight-users-action.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig new file mode 100644 index 0000000..6849add --- /dev/null +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig @@ -0,0 +1,5 @@ +
+ + +
+ From 332e6758a03098c2cdc437c2ac6a2daf87d61066 Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Mon, 4 Nov 2024 17:44:02 +0100 Subject: [PATCH 03/18] Removed QuicksightUserRoleUserFormExpanderPlugin --- .../AmazonQuicksightConfig.php | 13 --- .../AmazonQuicksightCommunicationFactory.php | 34 ------ .../QuicksightUserFormDataProvider.php | 51 --------- ...uicksightUserFormDataProviderInterface.php | 16 --- .../Expander/QuicksightUserFormExpander.php | 105 ------------------ .../QuicksightUserFormExpanderInterface.php | 20 ---- ...icksightUserRoleUserFormExpanderPlugin.php | 37 ------ .../QuicksightUserRoleDataTransformer.php | 71 ------------ .../user-form-quicksight-user-role-field.twig | 9 -- 9 files changed, 356 deletions(-) delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProvider.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/DataProvider/QuicksightUserFormDataProviderInterface.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpander.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Expander/QuicksightUserFormExpanderInterface.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserRoleUserFormExpanderPlugin.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Transformer/QuicksightUserRoleDataTransformer.php delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/user-form-quicksight-user-role-field.twig 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/Communication/AmazonQuicksightCommunicationFactory.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php index 07aa488..9e0ecab 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/AmazonQuicksightCommunicationFactory.php @@ -9,15 +9,9 @@ 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; @@ -29,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 */ 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/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/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 }} -
-
From 1c65cb00b954bc4a97eda5bd2dc69a994707e891 Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Mon, 4 Nov 2024 18:09:58 +0100 Subject: [PATCH 04/18] Removed QuicksightUserSyncDeleteConsole.php --- .../Business/Adder/ErrorAdder.php | 18 - .../Business/Adder/ErrorAdderInterface.php | 12 - .../Business/AmazonQuicksightFacade.php | 14 - .../AmazonQuicksightFacadeInterface.php | 16 - .../UserAmazonQuicksightApiClient.php | 29 -- ...UserAmazonQuicksightApiClientInterface.php | 7 - .../Deleter/QuicksightUserDeleter.php | 61 ---- .../QuicksightUserDeleterInterface.php | 6 - .../Mapper/AmazonQuicksightMapper.php | 13 - .../AmazonQuicksightMapperInterface.php | 11 - .../Matcher/QuicksightUserMatcher.php | 31 -- .../QuicksightUserMatcherInterface.php | 7 - .../QuicksightUserSyncDeleteConsole.php | 65 ---- ...QuicksightToAwsQuicksightClientAdapter.php | 10 - ...icksightToAwsQuicksightClientInterface.php | 7 - .../DeleteNotMatchedQuicksightUsersTest.php | 342 ------------------ 16 files changed, 649 deletions(-) delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Console/QuicksightUserSyncDeleteConsole.php delete mode 100644 tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/DeleteNotMatchedQuicksightUsersTest.php 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/AmazonQuicksightFacade.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php index 1d1e27c..16a08d8 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php @@ -107,20 +107,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 0b05a1f..9e3f9be 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php @@ -117,22 +117,6 @@ 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. diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php index 228384b..44334b0 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php @@ -195,35 +195,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 * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php index 5eceeb1..b03c615 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php @@ -32,13 +32,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 * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php index 6636c98..34cda2e 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php @@ -8,8 +8,6 @@ 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; @@ -106,39 +104,6 @@ public function deleteQuicksightUsersByUserCollectionResponse( }); } - /** - * @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; - } - /** * @param \Generated\Shared\Transfer\UserCollectionResponseTransfer $userCollectionResponseTransfer * @param array $userTransfers @@ -173,30 +138,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/Mapper/AmazonQuicksightMapper.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php index ee2b062..ede4987 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php @@ -104,19 +104,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 diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php index ea6fd94..97972dd 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php @@ -67,17 +67,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 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/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/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php index 7937019..999728c 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php @@ -48,16 +48,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 * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php index a0c18bf..7f302c8 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php @@ -25,13 +25,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 * 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, - ]); - } -} From d324b4c8a94e44195dd3547f24074b6a97b6f45b Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Mon, 4 Nov 2024 18:16:30 +0100 Subject: [PATCH 05/18] Removed CreateQuicksightUserPostUpdatePlugin --- .../CreateQuicksightUserPostUpdatePlugin.php | 43 ------------------- 1 file changed, 43 deletions(-) delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/CreateQuicksightUserPostUpdatePlugin.php 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); - } -} From 5d688b00cdc831dfa632490c0c3cb12b76fb0cbe Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Mon, 4 Nov 2024 18:45:35 +0100 Subject: [PATCH 06/18] Removed QuicksightUserPostCreatePlugin.php --- data/translation/Zed/de_DE.csv | 1 - data/translation/Zed/en_US.csv | 1 - .../Transfer/amazon_quicksight.transfer.xml | 14 - .../Business/AmazonQuicksightFacade.php | 17 - .../AmazonQuicksightFacadeInterface.php | 22 -- .../UserAmazonQuicksightApiClient.php | 58 ---- ...UserAmazonQuicksightApiClientInterface.php | 8 - .../Creator/QuicksightUserCreator.php | 67 ---- .../QuicksightUserCreatorInterface.php | 10 - .../Business/Filter/UserCollectionFilter.php | 29 -- .../Filter/UserCollectionFilterInterface.php | 7 - .../Mapper/AmazonQuicksightMapper.php | 17 - .../AmazonQuicksightMapperInterface.php | 12 - .../User/QuicksightUserPostCreatePlugin.php | 43 --- ...QuicksightToAwsQuicksightClientAdapter.php | 10 - ...icksightToAwsQuicksightClientInterface.php | 7 - ...mazonQuicksightToMessengerFacadeBridge.php | 10 - ...onQuicksightToMessengerFacadeInterface.php | 7 - ...sightUsersByUserCollectionResponseTest.php | 293 ------------------ 19 files changed, 633 deletions(-) delete mode 100644 src/SprykerEco/Zed/AmazonQuicksight/Communication/Plugin/User/QuicksightUserPostCreatePlugin.php delete mode 100644 tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/CreateQuicksightUsersByUserCollectionResponseTest.php diff --git a/data/translation/Zed/de_DE.csv b/data/translation/Zed/de_DE.csv index 4ccd2c1..1223107 100644 --- a/data/translation/Zed/de_DE.csv +++ b/data/translation/Zed/de_DE.csv @@ -1,7 +1,6 @@ "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." diff --git a/data/translation/Zed/en_US.csv b/data/translation/Zed/en_US.csv index a1715d0..341c0ad 100644 --- a/data/translation/Zed/en_US.csv +++ b/data/translation/Zed/en_US.csv @@ -1,7 +1,6 @@ "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." diff --git a/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml b/src/SprykerEco/Shared/AmazonQuicksight/Transfer/amazon_quicksight.transfer.xml index 6dadc6f..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 @@
- - - - - - - - - - - - - - diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacade.php index 16a08d8..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} * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php index 9e3f9be..304b1fd 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. diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php index 44334b0..4716a5b 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php @@ -17,8 +17,6 @@ use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer; use Generated\Shared\Transfer\QuicksightListUsersRequestTransfer; use Generated\Shared\Transfer\QuicksightListUsersResponseTransfer; -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; @@ -61,11 +59,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 */ @@ -114,46 +107,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 * @@ -269,17 +222,6 @@ public function listUsers(): QuicksightListUsersResponseTransfer return $quicksightListUsersResponseTransfer; } - /** - * @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 */ diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php index b03c615..6ef7e84 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClientInterface.php @@ -10,19 +10,11 @@ use Generated\Shared\Transfer\QuicksightDeleteUserResponseTransfer; use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer; use Generated\Shared\Transfer\QuicksightListUsersResponseTransfer; -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 * 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/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 ede4987..60fef73 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapper.php @@ -19,7 +19,6 @@ use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlRequestTransfer; use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer; use Generated\Shared\Transfer\QuicksightStartAssetBundleImportJobRequestTransfer; -use Generated\Shared\Transfer\QuicksightUserRegisterRequestTransfer; use Generated\Shared\Transfer\QuicksightUserTransfer; use Generated\Shared\Transfer\ResetQuicksightAnalyticsRequestTransfer; use Generated\Shared\Transfer\UserTransfer; @@ -47,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 diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php index 97972dd..3d8b8dd 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Mapper/AmazonQuicksightMapperInterface.php @@ -16,24 +16,12 @@ use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlRequestTransfer; use Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer; use Generated\Shared\Transfer\QuicksightStartAssetBundleImportJobRequestTransfer; -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 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/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientAdapter.php index 999728c..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 * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Dependency/External/AmazonQuicksightToAwsQuicksightClientInterface.php index 7f302c8..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 * 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/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); - } -} From 79e1b60f07bae624a32e826ef9345872a605ac57 Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Tue, 5 Nov 2024 10:18:57 +0100 Subject: [PATCH 07/18] Fixing tests --- ...nalyticsCollectionWithQuicksightAnalyticsTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php index 5bd6ed7..892a05c 100644 --- a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php +++ b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php @@ -571,18 +571,18 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobFinishedDa } /** - * @param bool $isAssetBundleSuccessfullyInitialized + * @param bool $isEnableAnalyticsEnabled * @param bool $isAssetBundleInitializationInProgress - * @param bool $isQuicksightUserRoleAvailable + * @param bool $isDisplayAnalyticsEnabled * @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 $isEnableAnalyticsEnabled, bool $isAssetBundleInitializationInProgress, - bool $isQuicksightUserRoleAvailable, + bool $isDisplayAnalyticsEnabled, QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer, ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer = null ): Environment { @@ -595,9 +595,9 @@ protected function getTwigMock( [ $this->equalTo(static::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS), $this->equalTo([ - 'isAssetBundleSuccessfullyInitialized' => $isAssetBundleSuccessfullyInitialized, + 'isEnableAnalyticsEnabled' => $isEnableAnalyticsEnabled, 'isAssetBundleInitializationInProgress' => $isAssetBundleInitializationInProgress, - 'isQuicksightUserRoleAvailable' => $isQuicksightUserRoleAvailable, + 'isDisplayAnalyticsEnabled' => $isDisplayAnalyticsEnabled, 'quicksightGenerateEmbedUrlResponse' => $quicksightGenerateEmbedUrlResponseTransfer, 'quicksightAssetBundleImportJob' => $quicksightAssetBundleImportJobTransfer, ]), From 4ed9e095898363816d6358eef2ad876e3048f7cc Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Tue, 5 Nov 2024 13:16:49 +0100 Subject: [PATCH 08/18] Fixed tests --- ...sCollectionWithQuicksightAnalyticsTest.php | 81 +++++++++++++++---- 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php index 892a05c..062cb63 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 $isEnableAnalyticsEnabled * * @return void */ - public function testExpandsCollectionWhenQuicksightUserExistsWithRole(string $role): void + public function testExpandsCollectionWhenQuicksightUserExistsWithRole(string $role, bool $isEnableAnalyticsEnabled): void { // Arrange $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( + $isEnableAnalyticsEnabled, 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 $isEnableAnalyticsEnabled + * @param bool $isDisplayAnalyticsEnabled * @param string $jobStatusAfterSync * @param \Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer * @@ -237,14 +261,16 @@ public function testExpandsCollectionWhenQuicksightAssetBundleImportJobIsInProgr bool $isInitializedInitially, bool $isInitializedAfterSync, bool $isInitializationInProgress, + bool $isEnableAnalyticsEnabled, + bool $isDisplayAnalyticsEnabled, string $jobStatusAfterSync, QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer ): void { // Arrange $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( - $isInitializedAfterSync, + $isEnableAnalyticsEnabled, $isInitializationInProgress, - true, + $isDisplayAnalyticsEnabled, $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 $isEnableAnalyticsEnabled + * @param bool $isDisplayAnalyticsEnabled * @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 $isEnableAnalyticsEnabled, + bool $isDisplayAnalyticsEnabled, 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, + $isEnableAnalyticsEnabled, false, - true, + $isDisplayAnalyticsEnabled, $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(), @@ -603,7 +647,14 @@ protected function getTwigMock( ]), ], [ - $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([]), ], ); From 0f9426c1404a0236fda4b7b23d0049d3673a841c Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Tue, 5 Nov 2024 17:06:22 +0100 Subject: [PATCH 09/18] Renamings --- data/translation/Zed/de_DE.csv | 8 ++++---- data/translation/Zed/en_US.csv | 8 ++++---- .../AmazonQuicksight/Presentation/Analytics/reset.twig | 2 +- .../Presentation/_partials/quicksight-analytics.twig | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/data/translation/Zed/de_DE.csv b/data/translation/Zed/de_DE.csv index 1223107..79b13f7 100644 --- a/data/translation/Zed/de_DE.csv +++ b/data/translation/Zed/de_DE.csv @@ -3,14 +3,14 @@ Analytics,Analytics "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." +"Please be aware that all default dashboards and analyses, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon the reset process. The owner of default assets will be replaced with the user who initiated the reset process.","Bitte beachten Sie, dass alle Standard-Dashboards und -Analysen, einschließlich Ihrer Änderungen, zurückgesetzt und durch die Standarddaten ersetzt werden. Außerdem werden alle Benutzer beim Zurücksetzen von den Assets getrennt. Der Besitzer der Standard-Assets wird durch den Benutzer ersetzt, der den Zurücksetzungsvorgang initiiert hat." "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 341c0ad..d74b2a5 100644 --- a/data/translation/Zed/en_US.csv +++ b/data/translation/Zed/en_US.csv @@ -3,14 +3,14 @@ Analytics,Analytics "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." +"Please be aware that all default dashboards and analyses, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon the reset process. The owner of default assets will be replaced with the user who initiated the reset process.","Please be aware that all default dashboards and analyses, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon the reset process. The owner of default assets will be replaced with the user who initiated the reset process." "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/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig index 01fe805..555f0de 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig @@ -12,7 +12,7 @@ {% 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 }}

+

{{ 'Please be aware that all default dashboards and analyses, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon the reset process. The owner of default assets will be replaced with the user who initiated the reset process.' | trans }}

{{ form_start(resetAnalyticsForm) }} {{ viewActionButton(app.request.headers.get('referer'), 'Cancel' | trans) }} diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig index b328a16..26e79f6 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig @@ -18,8 +18,8 @@
-

{{ '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 }}

@@ -38,7 +38,7 @@ {% endif %} {% elseif isAssetBundleInitializationInProgress %} - + {% else %}
{{ 'No Analytics permission has been granted to the current user.' | trans }} From 35e9c11f8fdb053781d0a2da99e97efad67a0c90 Mon Sep 17 00:00:00 2001 From: tolerants Date: Wed, 6 Nov 2024 13:47:07 +0200 Subject: [PATCH 10/18] Fixed iframe height. --- assets/Zed/js/modules/quicksight-analytics.js | 1 - .../Presentation/_partials/quicksight-analytics.twig | 2 +- .../_partials/synchronize-quicksight-users-action.twig | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) 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/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig index 26e79f6..7f30883 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig @@ -33,7 +33,7 @@ {% endfor %} {% endif %} {% if quicksightGenerateEmbedUrlResponse.embedUrl is not null and quicksightGenerateEmbedUrlResponse.embedUrl.url is not null %} -
+
{% 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 index 6849add..edf3f81 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig @@ -1,5 +1,5 @@
- +
From c8178046b43f3bdc93dcdf7c1d9aa5479adbf791 Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Thu, 7 Nov 2024 12:38:23 +0100 Subject: [PATCH 11/18] Adjusted specification --- .../Business/AmazonQuicksightFacadeInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php index 304b1fd..745bc56 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/AmazonQuicksightFacadeInterface.php @@ -64,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 From cbf901e6cc9951b57dc4ae86334d266a97294afa Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Thu, 7 Nov 2024 14:01:52 +0100 Subject: [PATCH 12/18] Adjusted a button HTML --- .../_partials/synchronize-quicksight-users-action.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index edf3f81..274a99d 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/synchronize-quicksight-users-action.twig @@ -1,5 +1,5 @@
- +
From 9ebe3b13d55130a7b94edf6ba8ec7693df4d9387 Mon Sep 17 00:00:00 2001 From: Alexander Kovalenko Date: Thu, 7 Nov 2024 16:02:50 +0200 Subject: [PATCH 13/18] Update src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig --- .../Presentation/_partials/quicksight-analytics.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig index 7f30883..6780baf 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig @@ -33,7 +33,7 @@ {% endfor %} {% endif %} {% if quicksightGenerateEmbedUrlResponse.embedUrl is not null and quicksightGenerateEmbedUrlResponse.embedUrl.url is not null %} -
+
{% endif %} From c0945dfa390c34fb1bb681093a76220816cfcc84 Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Thu, 14 Nov 2024 13:40:49 +0100 Subject: [PATCH 14/18] Fixed comments --- .../UserAmazonQuicksightApiClient.php | 7 ------- .../Deleter/QuicksightUserDeleter.php | 12 ++--------- .../Business/Expander/AnalyticsExpander.php | 4 ++-- .../Controller/AnalyticsController.php | 18 ++++++++++++----- .../Controller/UserController.php | 20 +++++++++++++------ 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php index 4716a5b..80a0fd4 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/ApiClient/UserAmazonQuicksightApiClient.php @@ -31,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 * diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php index 34cda2e..7df1aed 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Deleter/QuicksightUserDeleter.php @@ -9,7 +9,6 @@ use Generated\Shared\Transfer\MessageTransfer; 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; @@ -19,8 +18,6 @@ class QuicksightUserDeleter implements QuicksightUserDeleterInterface { - use TransactionTrait; - /** * @var string */ @@ -96,12 +93,7 @@ public function deleteQuicksightUsersByUserCollectionResponse( return $userCollectionResponseTransfer; } - return $this->getTransactionHandler()->handleTransaction(function () use ($userCollectionResponseTransfer, $filteredUserTransfers) { - return $this->executeDeleteQuicksightUsersByUserCollectionResponseTransaction( - $userCollectionResponseTransfer, - $filteredUserTransfers, - ); - }); + return $this->deleteQuicksightUsers($userCollectionResponseTransfer, $filteredUserTransfers); } /** @@ -110,7 +102,7 @@ public function deleteQuicksightUsersByUserCollectionResponse( * * @return \Generated\Shared\Transfer\UserCollectionResponseTransfer */ - protected function executeDeleteQuicksightUsersByUserCollectionResponseTransaction( + protected function deleteQuicksightUsers( UserCollectionResponseTransfer $userCollectionResponseTransfer, array $userTransfers ): UserCollectionResponseTransfer { diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php index 06a8b03..71945fb 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php @@ -47,7 +47,7 @@ class AnalyticsExpander implements AnalyticsExpanderInterface /** * @var string */ - protected const FIELD_NAME_TOKEN = '_token'; + protected const FIELD_NAME_SYNCHRONIZE_QUICKSIGHT_USERS_FORM_TOKEN = '_token'; /** * @var \SprykerEco\Zed\AmazonQuicksight\Persistence\AmazonQuicksightRepositoryInterface @@ -187,7 +187,7 @@ protected function expandAnalyticsActions( $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_TOKEN, + 'tokenFieldName' => static::FIELD_NAME_SYNCHRONIZE_QUICKSIGHT_USERS_FORM_TOKEN, ]), )); diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php index 23466e3..c220ac1 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php @@ -24,11 +24,9 @@ class AnalyticsController extends AbstractController { /** - * @uses \Spryker\Zed\AnalyticsGui\Communication\Controller\AnalyticsController::indexAction() - * * @var string */ - protected const URL_ANALYTICS = '/analytics-gui/analytics'; + protected const PARAM_REFERER = 'referer'; /** * @var string @@ -65,7 +63,7 @@ public function enableAction(Request $request): RedirectResponse|array $this->addErrorMessage($errorTransfer->getMessageOrFail()); } - return $this->redirectResponse(static::URL_ANALYTICS); + return $this->getRedirectResponseReferer($request); } /** @@ -98,7 +96,7 @@ public function resetAction(Request $request): RedirectResponse|array $this->addErrorMessage($errorTransfer->getMessageOrFail()); } - return $this->redirectResponse(static::URL_ANALYTICS); + return $this->getRedirectResponseReferer($request); } /** @@ -116,4 +114,14 @@ protected function findCurrentUser(): ?UserTransfer return $userCollectionTransfer->getUsers()->getIterator()->current(); } + + /** + * @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/Controller/UserController.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php index bafb38b..19329b1 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php @@ -20,11 +20,9 @@ class UserController extends AbstractController { /** - * @uses \Spryker\Zed\AnalyticsGui\Communication\Controller\AnalyticsController::indexAction() - * * @var string */ - protected const URL_ANALYTICS = '/analytics-gui/analytics'; + protected const PARAM_REFERER = 'referer'; /** * @var string @@ -62,7 +60,7 @@ public function synchronizeQuicksightUsersAction(Request $request): RedirectResp if (!$this->validateCsrfToken(static::FORM_NAME_SYNCHRONIZE_QUICKSIGHT_USERS, $tokenValue)) { $this->addErrorMessage(static::ERROR_MESSAGE_CSRF_TOKEN_INVALID); - return $this->redirectResponse(static::URL_ANALYTICS); + return $this->getRedirectResponseReferer($request); } $quicksightUserCollectionResponseTransfer = $this->getFacade()->createMatchedQuicksightUsers(); @@ -70,14 +68,14 @@ public function synchronizeQuicksightUsersAction(Request $request): RedirectResp if ($quicksightUserCollectionResponseTransfer->getErrors()->count() === 0) { $this->addSuccessMessage(static::SUCCESS_MESSAGE_USERS_SYNCHRONIZED); - return $this->redirectResponse(static::URL_ANALYTICS); + return $this->getRedirectResponseReferer($request); } foreach ($quicksightUserCollectionResponseTransfer->getErrors() as $errorTransfer) { $this->addErrorMessage($errorTransfer->getMessageOrFail()); } - return $this->redirectResponse(static::URL_ANALYTICS); + return $this->getRedirectResponseReferer($request); } /** @@ -92,4 +90,14 @@ protected function validateCsrfToken(string $tokenId, string $value): bool 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)); + } } From e892caa9279670fe68c1439e3ca0fecf00b9ae6e Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Wed, 20 Nov 2024 15:59:40 +0100 Subject: [PATCH 15/18] Fixed comments --- data/translation/Zed/de_DE.csv | 2 +- data/translation/Zed/en_US.csv | 2 +- .../Business/Expander/AnalyticsExpander.php | 6 +-- .../QuicksightAnalyticsRequestValidator.php | 10 ++--- ...ightAnalyticsRequestValidatorInterface.php | 6 +-- .../Controller/AnalyticsController.php | 18 +++----- .../_partials/quicksight-analytics.twig | 4 +- ...sCollectionWithQuicksightAnalyticsTest.php | 42 +++++++++---------- 8 files changed, 41 insertions(+), 49 deletions(-) diff --git a/data/translation/Zed/de_DE.csv b/data/translation/Zed/de_DE.csv index 79b13f7..0cbbb35 100644 --- a/data/translation/Zed/de_DE.csv +++ b/data/translation/Zed/de_DE.csv @@ -3,7 +3,7 @@ Analytics,Analytics "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 default dashboards and analyses, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon the reset process. The owner of default assets will be replaced with the user who initiated the reset process.","Bitte beachten Sie, dass alle Standard-Dashboards und -Analysen, einschließlich Ihrer Änderungen, zurückgesetzt und durch die Standarddaten ersetzt werden. Außerdem werden alle Benutzer beim Zurücksetzen von den Assets getrennt. Der Besitzer der Standard-Assets wird durch den Benutzer ersetzt, der den Zurücksetzungsvorgang initiiert hat." +"Please be aware that all default Analytics assets (dashboards, analyses, datasets), including your changes in those, will be reset to the default state. Upon the reset process, all users will be detached from these assets, and the owner of default Analytics assets will be replaced with the user who initiated the reset process.","Bitte beachten Sie, dass alle Standard-Analytics-Assets (Dashboards, Analysen, Datensätze), einschließlich Ihrer Änderungen, auf den Standardzustand zurückgesetzt werden. Beim Zurücksetzen werden alle Benutzer von diesen Assets getrennt und der Besitzer der Standard-Analytics-Assets wird durch den Benutzer ersetzt, der den Zurücksetzungsprozess initiiert hat." "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." "Analytics is not enabled yet","Analytics ist noch nicht eingeschaltet" diff --git a/data/translation/Zed/en_US.csv b/data/translation/Zed/en_US.csv index d74b2a5..66ffee4 100644 --- a/data/translation/Zed/en_US.csv +++ b/data/translation/Zed/en_US.csv @@ -3,7 +3,7 @@ Analytics,Analytics "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 default dashboards and analyses, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon the reset process. The owner of default assets will be replaced with the user who initiated the reset process.","Please be aware that all default dashboards and analyses, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon the reset process. The owner of default assets will be replaced with the user who initiated the reset process." +"Please be aware that all default Analytics assets (dashboards, analyses, datasets), including your changes in those, will be reset to the default state. Upon the reset process, all users will be detached from these assets, and the owner of default Analytics assets will be replaced with the user who initiated the reset process.","Please be aware that all default Analytics assets (dashboards, analyses, datasets), including your changes in those, will be reset to the default state. Upon the reset process, all users will be detached from these assets, and the owner of default Analytics assets will be replaced with the user who initiated the reset process." "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." "Analytics is not enabled yet","Analytics is not enabled yet" diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php index 71945fb..e6a7778 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Expander/AnalyticsExpander.php @@ -156,11 +156,11 @@ protected function expandAnalytics( 'quicksightAssetBundleImportJob' => $quicksightAssetBundleImportJobTransfer, 'isAssetBundleInitializationInProgress' => $this->quicksightAnalyticsRequestValidator ->isAssetBundleInitializationInProgress($quicksightAssetBundleImportJobTransfer), - 'isEnableAnalyticsEnabled' => $this->quicksightAnalyticsRequestValidator->isEnableAnalyticsEnabled( + 'isEnableAnalyticsAllowed' => $this->quicksightAnalyticsRequestValidator->isEnableAnalyticsAllowed( $quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer, ), - 'isDisplayAnalyticsEnabled' => $this->quicksightAnalyticsRequestValidator->isDisplayAnalyticsEnabled( + 'isDisplayAnalyticsAllowed' => $this->quicksightAnalyticsRequestValidator->isDisplayAnalyticsAllowed( $quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer, ), @@ -191,7 +191,7 @@ protected function expandAnalyticsActions( ]), )); - if (!$this->quicksightAnalyticsRequestValidator->isResetAnalyticsEnabled($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { + if (!$this->quicksightAnalyticsRequestValidator->isResetAnalyticsAllowed($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { return $analyticsCollectionTransfer; } diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidator.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidator.php index b9fcfaf..24c7d94 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidator.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidator.php @@ -54,7 +54,7 @@ public function validateEnableQuicksightAnalyticsRequest( $quicksightAssetBundleImportJobTransfer = $enableQuicksightAnalyticsRequestTransfer->getQuicksightAssetBundleImportJob(); $quicksightUserTransfer = $enableQuicksightAnalyticsRequestTransfer->getUserOrFail()->getQuicksightUser(); - if (!$this->isEnableAnalyticsEnabled($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { + if (!$this->isEnableAnalyticsAllowed($quicksightAssetBundleImportJobTransfer, $quicksightUserTransfer)) { $enableQuicksightAnalyticsResponseTransfer->addError( (new ErrorTransfer())->setMessage(static::ERROR_MESSAGE_ENABLE_ANALYTICS_FAILED), ); @@ -76,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), ); @@ -91,7 +91,7 @@ public function validateResetQuicksightAnalyticsRequest( * * @return bool */ - public function isResetAnalyticsEnabled( + public function isResetAnalyticsAllowed( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): bool { @@ -106,7 +106,7 @@ public function isResetAnalyticsEnabled( * * @return bool */ - public function isEnableAnalyticsEnabled( + public function isEnableAnalyticsAllowed( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): bool { @@ -121,7 +121,7 @@ public function isEnableAnalyticsEnabled( * * @return bool */ - public function isDisplayAnalyticsEnabled( + public function isDisplayAnalyticsAllowed( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): bool { diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php b/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php index 01496bc..15ecef3 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Business/Validator/QuicksightAnalyticsRequestValidatorInterface.php @@ -44,7 +44,7 @@ public function validateResetQuicksightAnalyticsRequest( * * @return bool */ - public function isResetAnalyticsEnabled( + public function isResetAnalyticsAllowed( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): bool; @@ -55,7 +55,7 @@ public function isResetAnalyticsEnabled( * * @return bool */ - public function isEnableAnalyticsEnabled( + public function isEnableAnalyticsAllowed( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): bool; @@ -66,7 +66,7 @@ public function isEnableAnalyticsEnabled( * * @return bool */ - public function isDisplayAnalyticsEnabled( + public function isDisplayAnalyticsAllowed( ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, ?QuicksightUserTransfer $quicksightUserTransfer ): bool; diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php index c220ac1..23466e3 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/AnalyticsController.php @@ -24,9 +24,11 @@ class AnalyticsController extends AbstractController { /** + * @uses \Spryker\Zed\AnalyticsGui\Communication\Controller\AnalyticsController::indexAction() + * * @var string */ - protected const PARAM_REFERER = 'referer'; + protected const URL_ANALYTICS = '/analytics-gui/analytics'; /** * @var string @@ -63,7 +65,7 @@ public function enableAction(Request $request): RedirectResponse|array $this->addErrorMessage($errorTransfer->getMessageOrFail()); } - return $this->getRedirectResponseReferer($request); + return $this->redirectResponse(static::URL_ANALYTICS); } /** @@ -96,7 +98,7 @@ public function resetAction(Request $request): RedirectResponse|array $this->addErrorMessage($errorTransfer->getMessageOrFail()); } - return $this->getRedirectResponseReferer($request); + return $this->redirectResponse(static::URL_ANALYTICS); } /** @@ -114,14 +116,4 @@ protected function findCurrentUser(): ?UserTransfer return $userCollectionTransfer->getUsers()->getIterator()->current(); } - - /** - * @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/Presentation/_partials/quicksight-analytics.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig index 6780baf..d4c2edb 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig +++ b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/_partials/quicksight-analytics.twig @@ -13,7 +13,7 @@ {% endfor %} {% endif %} -{% if isEnableAnalyticsEnabled %} +{% if isEnableAnalyticsAllowed %}
@@ -26,7 +26,7 @@ {{ viewActionButton(url('/amazon-quicksight/analytics/enable'), 'Enable Analytics' | trans) }}
-{% elseif isDisplayAnalyticsEnabled %} +{% elseif isDisplayAnalyticsAllowed %} {% if quicksightGenerateEmbedUrlResponse.errors | length %} {% for error in quicksightGenerateEmbedUrlResponse.errors %} diff --git a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php index 062cb63..f1b264e 100644 --- a/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php +++ b/tests/SprykerEcoTest/Zed/AmazonQuicksight/Business/Facade/ExpandAnalyticsCollectionWithQuicksightAnalyticsTest.php @@ -216,15 +216,15 @@ public function testExpandsCollectionWhenQuicksightUserExistsWithoutRole(): void * @dataProvider expandsCollectionWhenQuicksightUserExistsWithRoleDataProvider * * @param string $role - * @param bool $isEnableAnalyticsEnabled + * @param bool $isEnableAnalyticsAllowed * * @return void */ - public function testExpandsCollectionWhenQuicksightUserExistsWithRole(string $role, bool $isEnableAnalyticsEnabled): void + public function testExpandsCollectionWhenQuicksightUserExistsWithRole(string $role, bool $isEnableAnalyticsAllowed): void { // Arrange $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( - $isEnableAnalyticsEnabled, + $isEnableAnalyticsAllowed, false, false, new QuicksightGenerateEmbedUrlResponseTransfer(), @@ -250,8 +250,8 @@ public function testExpandsCollectionWhenQuicksightUserExistsWithRole(string $ro * @param bool $isInitializedInitially * @param bool $isInitializedAfterSync * @param bool $isInitializationInProgress - * @param bool $isEnableAnalyticsEnabled - * @param bool $isDisplayAnalyticsEnabled + * @param bool $isEnableAnalyticsAllowed + * @param bool $isDisplayAnalyticsAllowed * @param string $jobStatusAfterSync * @param \Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer * @@ -261,16 +261,16 @@ public function testExpandsCollectionWhenQuicksightAssetBundleImportJobIsInProgr bool $isInitializedInitially, bool $isInitializedAfterSync, bool $isInitializationInProgress, - bool $isEnableAnalyticsEnabled, - bool $isDisplayAnalyticsEnabled, + bool $isEnableAnalyticsAllowed, + bool $isDisplayAnalyticsAllowed, string $jobStatusAfterSync, QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer ): void { // Arrange $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( - $isEnableAnalyticsEnabled, + $isEnableAnalyticsAllowed, $isInitializationInProgress, - $isDisplayAnalyticsEnabled, + $isDisplayAnalyticsAllowed, $quicksightGenerateEmbedUrlResponseTransfer, (new QuicksightAssetBundleImportJobTransfer()) ->setIsInitialized($isInitializedAfterSync) @@ -395,8 +395,8 @@ public function testExpandsCollectionWhenGenerateEmbedUrlApiRequestFails(bool $t * @dataProvider expandsCollectionWhenQuicksightAssetBundleImportJobFinishedDataProvider * * @param bool $isInitializedInitially - * @param bool $isEnableAnalyticsEnabled - * @param bool $isDisplayAnalyticsEnabled + * @param bool $isEnableAnalyticsAllowed + * @param bool $isDisplayAnalyticsAllowed * @param string $initialJobStatus * @param \Generated\Shared\Transfer\QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer * @param \Generated\Shared\Transfer\QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer @@ -406,8 +406,8 @@ public function testExpandsCollectionWhenGenerateEmbedUrlApiRequestFails(bool $t */ public function testExpandsCollectionWhenQuicksightAssetBundleImportJobFinished( bool $isInitializedInitially, - bool $isEnableAnalyticsEnabled, - bool $isDisplayAnalyticsEnabled, + bool $isEnableAnalyticsAllowed, + bool $isDisplayAnalyticsAllowed, string $initialJobStatus, QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer, QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer, @@ -415,9 +415,9 @@ public function testExpandsCollectionWhenQuicksightAssetBundleImportJobFinished( ): void { // Arrange $this->tester->getContainer()->set(static::SERVICE_TWIG, $this->getTwigMock( - $isEnableAnalyticsEnabled, + $isEnableAnalyticsAllowed, false, - $isDisplayAnalyticsEnabled, + $isDisplayAnalyticsAllowed, $quicksightGenerateEmbedUrlResponseTransfer, $quicksightAssetBundleImportJobTransfer, )); @@ -615,18 +615,18 @@ protected function expandsCollectionWhenQuicksightAssetBundleImportJobFinishedDa } /** - * @param bool $isEnableAnalyticsEnabled + * @param bool $isEnableAnalyticsAllowed * @param bool $isAssetBundleInitializationInProgress - * @param bool $isDisplayAnalyticsEnabled + * @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 $isEnableAnalyticsEnabled, + bool $isEnableAnalyticsAllowed, bool $isAssetBundleInitializationInProgress, - bool $isDisplayAnalyticsEnabled, + bool $isDisplayAnalyticsAllowed, QuicksightGenerateEmbedUrlResponseTransfer $quicksightGenerateEmbedUrlResponseTransfer, ?QuicksightAssetBundleImportJobTransfer $quicksightAssetBundleImportJobTransfer = null ): Environment { @@ -639,9 +639,9 @@ protected function getTwigMock( [ $this->equalTo(static::TEMPLATE_PATH_QUICKSIGHT_ANALYTICS), $this->equalTo([ - 'isEnableAnalyticsEnabled' => $isEnableAnalyticsEnabled, + 'isEnableAnalyticsAllowed' => $isEnableAnalyticsAllowed, 'isAssetBundleInitializationInProgress' => $isAssetBundleInitializationInProgress, - 'isDisplayAnalyticsEnabled' => $isDisplayAnalyticsEnabled, + 'isDisplayAnalyticsAllowed' => $isDisplayAnalyticsAllowed, 'quicksightGenerateEmbedUrlResponse' => $quicksightGenerateEmbedUrlResponseTransfer, 'quicksightAssetBundleImportJob' => $quicksightAssetBundleImportJobTransfer, ]), From 21f3814808aad3b98b198a0fb55e7c6064682607 Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Thu, 21 Nov 2024 12:51:26 +0100 Subject: [PATCH 16/18] Fixed comments --- .../Communication/Controller/UserController.php | 6 +++--- .../Persistence/AmazonQuicksightEntityManager.php | 13 ------------- .../AmazonQuicksightEntityManagerInterface.php | 7 ------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php index 19329b1..c1d8729 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Communication/Controller/UserController.php @@ -35,11 +35,11 @@ class UserController extends AbstractController protected const SUCCESS_MESSAGE_USERS_SYNCHRONIZED = 'Analytics users have been successfully synchronized.'; /** - * @uses \SprykerEco\Zed\AmazonQuicksight\Business\Expander\AnalyticsExpander::FIELD_NAME_TOKEN + * @uses \SprykerEco\Zed\AmazonQuicksight\Business\Expander\AnalyticsExpander::FIELD_NAME_SYNCHRONIZE_QUICKSIGHT_USERS_FORM_TOKEN * * @var string */ - protected const FIELD_NAME_TOKEN = '_token'; + protected const FIELD_NAME_SYNCHRONIZE_QUICKSIGHT_USERS_FORM_TOKEN = '_token'; /** * @uses \SprykerEco\Zed\AmazonQuicksight\Business\Expander\AnalyticsExpander::FORM_NAME_SYNCHRONIZE_QUICKSIGHT_USERS @@ -55,7 +55,7 @@ class UserController extends AbstractController */ public function synchronizeQuicksightUsersAction(Request $request): RedirectResponse|array { - $tokenValue = (string)$request->get(static::FIELD_NAME_TOKEN); + $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); diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php index 451ec67..d4c5abc 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManager.php @@ -36,19 +36,6 @@ public function createQuicksightUser(QuicksightUserTransfer $quicksightUserTrans ->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 09ad2b0..4d5b45b 100644 --- a/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php +++ b/src/SprykerEco/Zed/AmazonQuicksight/Persistence/AmazonQuicksightEntityManagerInterface.php @@ -19,13 +19,6 @@ interface AmazonQuicksightEntityManagerInterface */ public function createQuicksightUser(QuicksightUserTransfer $quicksightUserTransfer): QuicksightUserTransfer; - /** - * @param list $quicksightUserIds - * - * @return void - */ - public function deleteQuicksightUsers(array $quicksightUserIds): void; - /** * @param list $userIds * From 55092ae01d2d5a6a8c6b9d00f1d804ee4f14529e Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Tue, 26 Nov 2024 11:52:16 +0100 Subject: [PATCH 17/18] Adjusted Reset notification --- data/translation/Zed/de_DE.csv | 6 +++++- data/translation/Zed/en_US.csv | 6 +++++- .../AmazonQuicksight/Presentation/Analytics/reset.twig | 10 +++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/data/translation/Zed/de_DE.csv b/data/translation/Zed/de_DE.csv index 0cbbb35..5b38d75 100644 --- a/data/translation/Zed/de_DE.csv +++ b/data/translation/Zed/de_DE.csv @@ -3,7 +3,11 @@ Analytics,Analytics "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 default Analytics assets (dashboards, analyses, datasets), including your changes in those, will be reset to the default state. Upon the reset process, all users will be detached from these assets, and the owner of default Analytics assets will be replaced with the user who initiated the reset process.","Bitte beachten Sie, dass alle Standard-Analytics-Assets (Dashboards, Analysen, Datensätze), einschließlich Ihrer Änderungen, auf den Standardzustand zurückgesetzt werden. Beim Zurücksetzen werden alle Benutzer von diesen Assets getrennt und der Besitzer der Standard-Analytics-Assets wird durch den Benutzer ersetzt, der den Zurücksetzungsprozess initiiert hat." +"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." "Analytics is not enabled yet","Analytics ist noch nicht eingeschaltet" diff --git a/data/translation/Zed/en_US.csv b/data/translation/Zed/en_US.csv index 66ffee4..5f5725f 100644 --- a/data/translation/Zed/en_US.csv +++ b/data/translation/Zed/en_US.csv @@ -3,7 +3,11 @@ Analytics,Analytics "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 default Analytics assets (dashboards, analyses, datasets), including your changes in those, will be reset to the default state. Upon the reset process, all users will be detached from these assets, and the owner of default Analytics assets will be replaced with the user who initiated the reset process.","Please be aware that all default Analytics assets (dashboards, analyses, datasets), including your changes in those, will be reset to the default state. Upon the reset process, all users will be detached from these assets, and the owner of default Analytics assets will be replaced with the user who initiated the reset process." +"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." "Analytics is not enabled yet","Analytics is not enabled yet" diff --git a/src/SprykerEco/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig b/src/SprykerEco/Zed/AmazonQuicksight/Presentation/Analytics/reset.twig index 555f0de..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 default dashboards and analyses, including your changes, will be reset and replaced with the default data. Also, all users will be detached from assets upon the reset process. The owner of default assets will be replaced with the user who initiated the reset process.' | 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) }} From 66bab914dc3b32eb042b1db75d4d9c184e563128 Mon Sep 17 00:00:00 2001 From: ilyakubanov Date: Wed, 27 Nov 2024 16:36:26 +0100 Subject: [PATCH 18/18] Removed deprecation message. --- README.md | 2 -- 1 file changed, 2 deletions(-) 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 ```