Skip to content

Commit fe7b9d7

Browse files
committed
MC-39523: Fix customer assistance plugin
1 parent 76e0abe commit fe7b9d7

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

app/code/Magento/LoginAsCustomerAssistance/Plugin/CustomerPlugin.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Authorization\Model\UserContextInterface;
1111
use Magento\Customer\Api\CustomerRepositoryInterface;
1212
use Magento\Customer\Api\Data\CustomerInterface;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\AuthorizationInterface;
1415
use Magento\LoginAsCustomerAssistance\Api\SetAssistanceInterface;
1516
use Magento\LoginAsCustomerAssistance\Model\IsAssistanceEnabled;
@@ -36,17 +37,17 @@ class CustomerPlugin
3637

3738
/**
3839
* @param SetAssistanceInterface $setAssistance
39-
* @param AuthorizationInterface $authorization
40-
* @param UserContextInterface $userContext
40+
* @param AuthorizationInterface|null $authorization
41+
* @param UserContextInterface|null $userContext
4142
*/
4243
public function __construct(
4344
SetAssistanceInterface $setAssistance,
44-
AuthorizationInterface $authorization,
45-
UserContextInterface $userContext
45+
?AuthorizationInterface $authorization = null,
46+
?UserContextInterface $userContext = null
4647
) {
4748
$this->setAssistance = $setAssistance;
48-
$this->authorization = $authorization;
49-
$this->userContext = $userContext;
49+
$this->authorization = $authorization ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
50+
$this->userContext = $userContext ?? ObjectManager::getInstance()->get(UserContextInterface::class);
5051
}
5152

5253
/**
@@ -64,8 +65,9 @@ public function afterSave(
6465
CustomerInterface $customer
6566
): CustomerInterface {
6667
$enoughPermission = true;
67-
if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_ADMIN ||
68-
$this->userContext->getUserType() === UserContextInterface::USER_TYPE_INTEGRATION) {
68+
if ($this->userContext->getUserType() === UserContextInterface::USER_TYPE_ADMIN
69+
|| $this->userContext->getUserType() === UserContextInterface::USER_TYPE_INTEGRATION
70+
) {
6971
$enoughPermission = $this->authorization->isAllowed('Magento_LoginAsCustomer::allow_shopping_assistance');
7072
}
7173
$customerId = (int)$result->getId();

dev/tests/api-functional/testsuite/Magento/LoginAsCustomerAssistance/Plugin/CustomerMeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testUpdateSelf(int $state, bool $expected): void
9494
Customer::EMAIL => $customerData['email'],
9595
Customer::FIRSTNAME => $customerData['firstname'],
9696
Customer::LASTNAME => $updatedLastname,
97-
Customer::EXTENSION_ATTRIBUTES_KEY => ['assistance_allowed' => $state]
97+
Customer::EXTENSION_ATTRIBUTES_KEY => ['assistance_allowed' => $state],
9898
];
9999

100100
$serviceInfo = $this->getServiceInfo('SaveSelf', $customerToken);
@@ -138,6 +138,7 @@ private function getCustomerData(int $customerId): Customer
138138
{
139139
$customerData = $this->customerRepository->getById($customerId);
140140
$this->customerRegistry->remove($customerId);
141+
141142
return $customerData;
142143
}
143144

dev/tests/api-functional/testsuite/Magento/LoginAsCustomerAssistance/Plugin/CustomerPluginTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public function testUpdateCustomerWithLimitedResources(int $state): void
128128
];
129129

130130
$serviceInfo = $this->getServiceInfo($customerId, 'Save');
131-
OauthHelper::clearApiAccessCredentials();
132-
$apiCredentials = OauthHelper::getApiAccessCredentials($resources);
131+
OauthHelper::getApiAccessCredentials($resources);
133132
$response = $this->_webApiCall($serviceInfo, $requestData);
134133
$this->assertNotNull($response);
135134

@@ -168,6 +167,7 @@ private function getCustomerData(int $customerId): Customer
168167
{
169168
$customerData = $this->customerRepository->getById($customerId);
170169
$this->customerRegistry->remove($customerId);
170+
171171
return $customerData;
172172
}
173173

@@ -181,4 +181,13 @@ public function assistanceStatesDataProvider(): array
181181
'Assistance Denied' => [IsAssistanceEnabledInterface::DENIED, false],
182182
];
183183
}
184+
185+
/**
186+
* @inheritDoc
187+
*/
188+
protected function tearDown(): void
189+
{
190+
OauthHelper::clearApiAccessCredentials();
191+
parent::tearDown();
192+
}
184193
}

0 commit comments

Comments
 (0)