-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
c8ffdb5
commit f752db3
Showing
2 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
Setup/Patch/Data/FixDefaultExtendIntegrationsScopes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
/* | ||
* Copyright Extend (c) 2022. All rights reserved. | ||
* See Extend-COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Extend\Integration\Setup\Patch\Data; | ||
|
||
use Exception; | ||
use Magento\Framework\Exception\FileSystemException; | ||
use Magento\Framework\Phrase; | ||
use Magento\Framework\Setup\Exception as SetupException; | ||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
use Magento\Framework\Setup\Patch\PatchRevertableInterface; | ||
use Magento\Integration\Model\IntegrationService; | ||
use Magento\Integration\Model\AuthorizationService; | ||
|
||
/** | ||
* This patch will add the scopes back to the default Extend integrations | ||
*/ | ||
class FixDefaultExtendIntegrationsScopes implements DataPatchInterface, PatchRevertableInterface | ||
{ | ||
private IntegrationService $integrationService; | ||
private AuthorizationService $authorizationService; | ||
|
||
private $DEFAULT_INTEGRATION_RESOURCES = [ | ||
"Magento_Backend::admin", | ||
"Magento_Backend::system", | ||
"Magento_Backend::stores", | ||
"Magento_Backend::store", | ||
"Extend_Integration::manage", | ||
"Magento_Sales::sales", | ||
"Magento_Sales::sales_operation", | ||
"Magento_Sales::sales_creditmemo", | ||
"Magento_Sales::actions_view", | ||
"Magento_Sales::shipment", | ||
"Magento_Catalog::catalog", | ||
"Magento_Catalog::products", | ||
"Magento_Catalog::categories", | ||
]; | ||
|
||
public function __construct( | ||
IntegrationService $integrationService, | ||
AuthorizationService $authorizationService | ||
) { | ||
$this->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()] | ||
) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters