From f752db34f8350915436bd6cb6da26e551a1057f5 Mon Sep 17 00:00:00 2001 From: Jomar Santos Date: Mon, 17 Jun 2024 09:00:26 -0700 Subject: [PATCH] fix: [MINT-2297] demo and prod integration scopes (#117) * fix: [MINT-2297] demo and prod integration scopes * [MINT-2297] new patch * [MINT-2297] revert unrelated file * auto-changelog * auto-changelog --------- Co-authored-by: magento-bot --- .../FixDefaultExtendIntegrationsScopes.php | 117 ++++++++++++++++++ .../MakeDefaultExtendIntegrationsMutable.php | 2 +- 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 Setup/Patch/Data/FixDefaultExtendIntegrationsScopes.php diff --git a/Setup/Patch/Data/FixDefaultExtendIntegrationsScopes.php b/Setup/Patch/Data/FixDefaultExtendIntegrationsScopes.php new file mode 100644 index 0000000..286bea0 --- /dev/null +++ b/Setup/Patch/Data/FixDefaultExtendIntegrationsScopes.php @@ -0,0 +1,117 @@ +integrationService = $integrationService; + $this->authorizationService = $authorizationService; + } + + /** + * This patch depends on the MakeDefaultExtendIntegrationsMutable patch since it re-applies the default scopes which were removed by that patch + */ + public static function getDependencies() + { + return [ + \Extend\Integration\Setup\Patch\Data\MakeDefaultExtendIntegrationsMutable::class + ]; + } + + /** + * @inheritDoc + */ + public function getAliases() + { + return []; + } + + /** + * @inheritDoc + * @throws SetupException + */ + public function apply() + { + try { + if ($prodIntegration = $this->integrationService->findByName('Extend Integration - Production')) { + $this->authorizationService->grantPermissions($prodIntegration->getId(), $this->DEFAULT_INTEGRATION_RESOURCES); + } + if ($demoIntegration = $this->integrationService->findByName('Extend Integration - Demo')) { + $this->authorizationService->grantPermissions($demoIntegration->getId(), $this->DEFAULT_INTEGRATION_RESOURCES); + } + } catch (Exception $exception) { + throw new SetupException( + new Phrase( + 'There was a problem applying the Extend Integration Patch to fix the default scopes: %1', + [$exception->getMessage()] + ) + ); + } + } + + /** + * @inheritDoc + * @throws FileSystemException|SetupException + */ + public function revert() + { + try { + // for rollback, we need to set the scopes back to empty since the last patch removed them + $prodIntegration = $this->integrationService->findByName('Extend Integration - Production'); + if ($prodIntegration) { + $this->authorizationService->grantPermissions($prodIntegration->getId(), []); + } + + $demoIntegration = $this->integrationService->findByName('Extend Integration - Demo'); + if ($demoIntegration) { + $this->authorizationService->grantPermissions($demoIntegration->getId(), []); + } + } catch (Exception $exception) { + throw new SetupException( + new Phrase( + 'There was a problem reverting the Extend Integration Patch to fix the default scopes: %1', + [$exception->getMessage()] + ) + ); + } + } +} diff --git a/Setup/Patch/Data/MakeDefaultExtendIntegrationsMutable.php b/Setup/Patch/Data/MakeDefaultExtendIntegrationsMutable.php index 53fc59c..923812a 100644 --- a/Setup/Patch/Data/MakeDefaultExtendIntegrationsMutable.php +++ b/Setup/Patch/Data/MakeDefaultExtendIntegrationsMutable.php @@ -84,7 +84,7 @@ public function revert() ->setSetupType(1); $this->integrationService->update($prodIntegration->getData()); $demoIntegration = $this->integrationService - ->findByName('Extend Integration - Dem') + ->findByName('Extend Integration - Demo') ->setSetupType(1); $this->integrationService->update($demoIntegration->getData()); } catch (Exception $exception) {