-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from bold-commerce/Q1-661
Expose Bold modules installed and their versions through an api endpoint
- Loading branch information
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
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
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,123 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bold\Checkout\Setup\Patch\Data; | ||
|
||
use Magento\Authorization\Model\UserContextInterface; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
|
||
/** | ||
* Perform integration permissions upgrade. | ||
*/ | ||
class AddIntegrationPermissionsPatch implements DataPatchInterface | ||
{ | ||
private const RESOURCE = 'Bold_Checkout::integration'; | ||
|
||
/** | ||
* @var ModuleDataSetupInterface | ||
*/ | ||
private $moduleDataSetup; | ||
|
||
/** | ||
* @param ModuleDataSetupInterface $moduleDataSetup | ||
*/ | ||
public function __construct( | ||
ModuleDataSetupInterface $moduleDataSetup | ||
) | ||
{ | ||
$this->moduleDataSetup = $moduleDataSetup; | ||
} | ||
|
||
/** | ||
* Perform integration permissions upgrade. | ||
* | ||
* @return void | ||
*/ | ||
public function apply(): void | ||
{ | ||
$this->moduleDataSetup->startSetup(); | ||
|
||
$this->moduleDataSetup->getConnection()->delete( | ||
$this->moduleDataSetup->getTable('authorization_rule'), | ||
[ | ||
'resource_id = ?' => self::RESOURCE, | ||
'role_id IN (?)' => $this->getRoleIdsToDelete(), | ||
] | ||
); | ||
$this->moduleDataSetup->getConnection()->insertMultiple( | ||
$this->moduleDataSetup->getTable('authorization_rule'), | ||
$this->getNewAuthorizationRules() | ||
); | ||
|
||
$this->moduleDataSetup->endSetup(); | ||
} | ||
|
||
/** | ||
* Get role IDs to delete. | ||
* | ||
* @return array | ||
*/ | ||
private function getRoleIdsToDelete(): array | ||
{ | ||
$select = $this->moduleDataSetup->getConnection() | ||
->select() | ||
->from(['ar' => $this->moduleDataSetup->getTable('authorization_role')], 'role_id') | ||
->join( | ||
['i' => $this->moduleDataSetup->getTable('integration')], | ||
'i.integration_id = ar.user_id', | ||
[] | ||
) | ||
->where('ar.user_type = ?', UserContextInterface::USER_TYPE_INTEGRATION) | ||
->where('i.name LIKE ?', 'BoldPlatformIntegration%'); | ||
|
||
return $this->moduleDataSetup->getConnection()->fetchCol($select); | ||
} | ||
|
||
/** | ||
* Get new authorization rules data. | ||
* | ||
* @return array | ||
*/ | ||
private function getNewAuthorizationRules(): array | ||
{ | ||
$select = $this->moduleDataSetup->getConnection() | ||
->select() | ||
->from(['ar' => $this->moduleDataSetup->getTable('authorization_role')], ['role_id']) | ||
->join( | ||
['i' => $this->moduleDataSetup->getTable('integration')], | ||
'i.integration_id = ar.user_id', | ||
[] | ||
) | ||
->where('ar.user_type = ?', UserContextInterface::USER_TYPE_INTEGRATION) | ||
->where('i.name LIKE ?', 'BoldPlatformIntegration%'); | ||
$roleIds = $this->moduleDataSetup->getConnection()->fetchCol($select); | ||
$data = []; | ||
foreach ($roleIds as $roleId) { | ||
$data[] = [ | ||
'role_id' => $roleId, | ||
'resource_id' => self::RESOURCE, | ||
'permission' => 'allow', | ||
]; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getAliases() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getDependencies() | ||
{ | ||
return []; | ||
} | ||
} |