Skip to content

Commit a1c4d33

Browse files
author
Valeriy Nayda
committed
GraphQL-55: [Mutations] My Account > Change account information
-- fixes after merge with mainline
1 parent 706af91 commit a1c4d33

File tree

5 files changed

+19
-31
lines changed

5 files changed

+19
-31
lines changed

app/code/Magento/CustomerGraphQl/Model/Resolver/ChangePassword.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public function resolve(
7979

8080
$currentUserId = $context->getUserId();
8181
$currentUserType = $context->getUserType();
82-
$currentUserId = (int)$currentUserId;
83-
8482
$this->checkCustomerAccount->execute($currentUserId, $currentUserType);
83+
84+
$currentUserId = (int)$currentUserId;
8585
$this->checkCustomerPassword->execute($args['currentPassword'], $currentUserId);
8686

8787
$this->accountManagement->changePasswordById($currentUserId, $args['currentPassword'], $args['newPassword']);

app/code/Magento/CustomerGraphQl/Model/Resolver/IsSubscribed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function resolve(
5555

5656
$this->checkCustomerAccount->execute($currentUserId, $currentUserType);
5757

58-
$status = $this->subscriberFactory->create()->loadByCustomerId($currentUserId)->isSubscribed();
58+
$status = $this->subscriberFactory->create()->loadByCustomerId((int)$currentUserId)->isSubscribed();
5959
return (bool)$status;
6060
}
6161
}
Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\CustomerGraphQl\Model\Resolver\Customer\Account;
8+
namespace Magento\CustomerGraphQl\Model\Resolver;
99

10-
use Magento\Authorization\Model\UserContextInterface;
10+
use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount;
1111
use Magento\Framework\GraphQl\Config\Element\Field;
12-
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1312
use Magento\Framework\GraphQl\Query\ResolverInterface;
1413
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1514
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -20,24 +19,24 @@
2019
class RevokeCustomerToken implements ResolverInterface
2120
{
2221
/**
23-
* @var UserContextInterface
22+
* @var CheckCustomerAccount
2423
*/
25-
private $userContext;
24+
private $checkCustomerAccount;
2625

2726
/**
2827
* @var CustomerTokenServiceInterface
2928
*/
3029
private $customerTokenService;
3130

3231
/**
33-
* @param UserContextInterface $userContext
32+
* @param CheckCustomerAccount $checkCustomerAccount
3433
* @param CustomerTokenServiceInterface $customerTokenService
3534
*/
3635
public function __construct(
37-
UserContextInterface $userContext,
36+
CheckCustomerAccount $checkCustomerAccount,
3837
CustomerTokenServiceInterface $customerTokenService
3938
) {
40-
$this->userContext = $userContext;
39+
$this->checkCustomerAccount = $checkCustomerAccount;
4140
$this->customerTokenService = $customerTokenService;
4241
}
4342

@@ -51,17 +50,11 @@ public function resolve(
5150
array $value = null,
5251
array $args = null
5352
) {
54-
$customerId = (int)$this->userContext->getUserId();
53+
$currentUserId = $context->getUserId();
54+
$currentUserType = $context->getUserType();
5555

56-
if ($customerId === 0) {
57-
throw new GraphQlAuthorizationException(
58-
__(
59-
'Current customer does not have access to the resource "%1"',
60-
[\Magento\Customer\Model\Customer::ENTITY]
61-
)
62-
);
63-
}
56+
$this->checkCustomerAccount->execute($currentUserId, $currentUserType);
6457

65-
return $this->customerTokenService->revokeCustomerAccessToken($customerId);
58+
return $this->customerTokenService->revokeCustomerAccessToken((int)$currentUserId);
6659
}
6760
}

app/code/Magento/CustomerGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type Mutation {
99
generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\GenerateCustomerToken") @doc(description:"Retrieve Customer token")
1010
changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\ChangePassword") @doc(description:"Changes password for logged in customer")
1111
updateCustomer (input: UpdateCustomerInput): UpdateCustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update customer personal information")
12-
revokeCustomerToken: Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\RevokeCustomerToken") @doc(description:"Revoke Customer token")
12+
revokeCustomerToken: Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\RevokeCustomerToken") @doc(description:"Revoke Customer token")
1313
}
1414

1515
type CustomerToken {

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/RevokeCustomerTokenTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Customer;
99

10+
use Magento\Integration\Api\CustomerTokenServiceInterface;
1011
use Magento\TestFramework\ObjectManager;
1112
use Magento\TestFramework\TestCase\GraphQlAbstract;
1213

@@ -16,7 +17,6 @@
1617
class RevokeCustomerTokenTest extends GraphQlAbstract
1718
{
1819
/**
19-
* Verify customers with valid credentials
2020
* @magentoApiDataFixture Magento/Customer/_files/customer.php
2121
*/
2222
public function testRevokeCustomerTokenValidCredentials()
@@ -30,8 +30,7 @@ public function testRevokeCustomerTokenValidCredentials()
3030
$userName = '[email protected]';
3131
$password = 'password';
3232
/** @var CustomerTokenServiceInterface $customerTokenService */
33-
$customerTokenService = ObjectManager::getInstance()
34-
->get(\Magento\Integration\Api\CustomerTokenServiceInterface::class);
33+
$customerTokenService = ObjectManager::getInstance()->get(CustomerTokenServiceInterface::class);
3534
$customerToken = $customerTokenService->createCustomerAccessToken($userName, $password);
3635

3736
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
@@ -40,7 +39,8 @@ public function testRevokeCustomerTokenValidCredentials()
4039
}
4140

4241
/**
43-
* Verify guest customers
42+
* @expectedException \Exception
43+
* @expectedExceptionMessage The current customer isn't authorized.
4444
*/
4545
public function testRevokeCustomerTokenForGuestCustomer()
4646
{
@@ -49,11 +49,6 @@ public function testRevokeCustomerTokenForGuestCustomer()
4949
revokeCustomerToken
5050
}
5151
QUERY;
52-
$this->expectException(\Exception::class);
53-
$this->expectExceptionMessage(
54-
'GraphQL response contains errors: Current customer' . ' ' .
55-
'does not have access to the resource "customer"'
56-
);
5752
$this->graphQlQuery($query, [], '');
5853
}
5954
}

0 commit comments

Comments
 (0)