-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.2-develop' of github.com:magento-troll/magento2ce int…
…o MAGETWO-70790
- Loading branch information
Showing
14 changed files
with
738 additions
and
51 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
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,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Integration\Plugin\Model; | ||
|
||
use Magento\Integration\Model\AdminTokenService; | ||
|
||
/** | ||
* Plugin to delete admin tokens when admin becomes inactive | ||
*/ | ||
class AdminUser | ||
{ | ||
/** | ||
* @var AdminTokenService | ||
*/ | ||
private $adminTokenService; | ||
|
||
/** | ||
* @param AdminTokenService $adminTokenService | ||
*/ | ||
public function __construct( | ||
AdminTokenService $adminTokenService | ||
) { | ||
$this->adminTokenService = $adminTokenService; | ||
} | ||
|
||
/** | ||
* Check if admin is inactive - if so, invalidate their tokens | ||
* | ||
* @param \Magento\User\Model\User $subject | ||
* @param \Magento\Framework\DataObject $object | ||
* @return $this | ||
*/ | ||
public function afterSave( | ||
\Magento\User\Model\User $subject, | ||
\Magento\Framework\DataObject $object | ||
) { | ||
$isActive = $object->getIsActive(); | ||
if (isset($isActive) && $isActive == 0) { | ||
$this->adminTokenService->revokeAdminAccessToken($object->getId()); | ||
} | ||
return $subject; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/code/Magento/Integration/Plugin/Model/CustomerUser.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,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Integration\Plugin\Model; | ||
|
||
use Magento\Integration\Model\CustomerTokenService; | ||
|
||
/** | ||
* Plugin to delete customer tokens when customer becomes inactive | ||
*/ | ||
class CustomerUser | ||
{ | ||
/** | ||
* @var CustomerTokenService | ||
*/ | ||
private $customerTokenService; | ||
|
||
/** | ||
* @param CustomerTokenService $customerTokenService | ||
*/ | ||
public function __construct( | ||
CustomerTokenService $customerTokenService | ||
) { | ||
$this->customerTokenService = $customerTokenService; | ||
} | ||
|
||
/** | ||
* Check if customer is inactive - if so, invalidate their tokens | ||
* | ||
* @param \Magento\Customer\Model\Customer $subject | ||
* @param \Magento\Framework\DataObject $object | ||
* @return $this | ||
*/ | ||
public function afterSave( | ||
\Magento\Customer\Model\Customer $subject, | ||
\Magento\Framework\DataObject $object | ||
) { | ||
$isActive = $object->getIsActive(); | ||
if (isset($isActive) && $isActive == 0) { | ||
$this->customerTokenService->revokeCustomerAccessToken($object->getId()); | ||
} | ||
return $subject; | ||
} | ||
} |
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,96 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Integration\Setup; | ||
|
||
use Magento\Framework\Setup\UpgradeDataInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
|
||
/** | ||
* Upgrade data script for Integration module | ||
*/ | ||
class UpgradeData implements UpgradeDataInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) | ||
{ | ||
$setup->startSetup(); | ||
|
||
if (version_compare($context->getVersion(), '2.2.0', '<')) { | ||
$this->removeRevokedTokens($setup); | ||
$this->removeTokensFromInactiveAdmins($setup); | ||
$this->removeTokensFromInactiveCustomers($setup); | ||
} | ||
|
||
$setup->endSetup(); | ||
} | ||
|
||
/** | ||
* Remove any revoked tokens from oauth_token table | ||
* | ||
* @param ModuleDataSetupInterface $setup | ||
* @return void | ||
*/ | ||
private function removeRevokedTokens($setup) | ||
{ | ||
$oauthTokenTable = $setup->getTable('oauth_token'); | ||
|
||
$where = ['revoked = ?' => 1]; | ||
$setup->getConnection()->delete($oauthTokenTable, $where); | ||
} | ||
|
||
/** | ||
* Remove any tokens from oauth_token table where admin is inactive | ||
* | ||
* @param ModuleDataSetupInterface $setup | ||
* @return void | ||
*/ | ||
private function removeTokensFromInactiveAdmins($setup) | ||
{ | ||
$oauthTokenTable = $setup->getTable('oauth_token'); | ||
$adminUserTable = $setup->getTable('admin_user'); | ||
|
||
$select = $setup->getConnection()->select()->from( | ||
$adminUserTable, | ||
['user_id', 'is_active'] | ||
); | ||
|
||
$admins = $setup->getConnection()->fetchAll($select); | ||
foreach ($admins as $admin) { | ||
if ($admin['is_active'] == 0) { | ||
$where = ['admin_id = ?' => (int)$admin['user_id']]; | ||
$setup->getConnection()->delete($oauthTokenTable, $where); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Remove any tokens from oauth_token table where customer is inactive | ||
* | ||
* @param ModuleDataSetupInterface $setup | ||
* @return void | ||
*/ | ||
private function removeTokensFromInactiveCustomers($setup) | ||
{ | ||
$oauthTokenTable = $setup->getTable('oauth_token'); | ||
$adminUserTable = $setup->getTable('customer_entity'); | ||
|
||
$select = $setup->getConnection()->select()->from( | ||
$adminUserTable, | ||
['entity_id', 'is_active'] | ||
); | ||
|
||
$admins = $setup->getConnection()->fetchAll($select); | ||
foreach ($admins as $admin) { | ||
if ($admin['is_active'] == 0) { | ||
$where = ['customer_id = ?' => (int)$admin['entity_id']]; | ||
$setup->getConnection()->delete($oauthTokenTable, $where); | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.