Skip to content

Commit

Permalink
GraphQL-55: [Mutations] My Account > Change account information
Browse files Browse the repository at this point in the history
-- fixes after merge with mainline
  • Loading branch information
Valeriy Nayda committed Oct 9, 2018
1 parent 706af91 commit a1c4d33
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public function resolve(

$currentUserId = $context->getUserId();
$currentUserType = $context->getUserType();
$currentUserId = (int)$currentUserId;

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

$currentUserId = (int)$currentUserId;
$this->checkCustomerPassword->execute($args['currentPassword'], $currentUserId);

$this->accountManagement->changePasswordById($currentUserId, $args['currentPassword'], $args['newPassword']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function resolve(

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

$status = $this->subscriberFactory->create()->loadByCustomerId($currentUserId)->isSubscribed();
$status = $this->subscriberFactory->create()->loadByCustomerId((int)$currentUserId)->isSubscribed();
return (bool)$status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
*/
declare(strict_types=1);

namespace Magento\CustomerGraphQl\Model\Resolver\Customer\Account;
namespace Magento\CustomerGraphQl\Model\Resolver;

use Magento\Authorization\Model\UserContextInterface;
use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccount;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Integration\Api\CustomerTokenServiceInterface;
Expand All @@ -20,24 +19,24 @@
class RevokeCustomerToken implements ResolverInterface
{
/**
* @var UserContextInterface
* @var CheckCustomerAccount
*/
private $userContext;
private $checkCustomerAccount;

/**
* @var CustomerTokenServiceInterface
*/
private $customerTokenService;

/**
* @param UserContextInterface $userContext
* @param CheckCustomerAccount $checkCustomerAccount
* @param CustomerTokenServiceInterface $customerTokenService
*/
public function __construct(
UserContextInterface $userContext,
CheckCustomerAccount $checkCustomerAccount,
CustomerTokenServiceInterface $customerTokenService
) {
$this->userContext = $userContext;
$this->checkCustomerAccount = $checkCustomerAccount;
$this->customerTokenService = $customerTokenService;
}

Expand All @@ -51,17 +50,11 @@ public function resolve(
array $value = null,
array $args = null
) {
$customerId = (int)$this->userContext->getUserId();
$currentUserId = $context->getUserId();
$currentUserType = $context->getUserType();

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

return $this->customerTokenService->revokeCustomerAccessToken($customerId);
return $this->customerTokenService->revokeCustomerAccessToken((int)$currentUserId);
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/CustomerGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Mutation {
generateCustomerToken(email: String!, password: String!): CustomerToken @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\GenerateCustomerToken") @doc(description:"Retrieve Customer token")
changeCustomerPassword(currentPassword: String!, newPassword: String!): Customer @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\ChangePassword") @doc(description:"Changes password for logged in customer")
updateCustomer (input: UpdateCustomerInput): UpdateCustomerOutput @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\UpdateCustomer") @doc(description:"Update customer personal information")
revokeCustomerToken: Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\Customer\\Account\\RevokeCustomerToken") @doc(description:"Revoke Customer token")
revokeCustomerToken: Boolean @resolver(class: "\\Magento\\CustomerGraphQl\\Model\\Resolver\\RevokeCustomerToken") @doc(description:"Revoke Customer token")
}

type CustomerToken {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\GraphQl\Customer;

use Magento\Integration\Api\CustomerTokenServiceInterface;
use Magento\TestFramework\ObjectManager;
use Magento\TestFramework\TestCase\GraphQlAbstract;

Expand All @@ -16,7 +17,6 @@
class RevokeCustomerTokenTest extends GraphQlAbstract
{
/**
* Verify customers with valid credentials
* @magentoApiDataFixture Magento/Customer/_files/customer.php
*/
public function testRevokeCustomerTokenValidCredentials()
Expand All @@ -30,8 +30,7 @@ public function testRevokeCustomerTokenValidCredentials()
$userName = 'customer@example.com';
$password = 'password';
/** @var CustomerTokenServiceInterface $customerTokenService */
$customerTokenService = ObjectManager::getInstance()
->get(\Magento\Integration\Api\CustomerTokenServiceInterface::class);
$customerTokenService = ObjectManager::getInstance()->get(CustomerTokenServiceInterface::class);
$customerToken = $customerTokenService->createCustomerAccessToken($userName, $password);

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

/**
* Verify guest customers
* @expectedException \Exception
* @expectedExceptionMessage The current customer isn't authorized.
*/
public function testRevokeCustomerTokenForGuestCustomer()
{
Expand All @@ -49,11 +49,6 @@ public function testRevokeCustomerTokenForGuestCustomer()
revokeCustomerToken
}
QUERY;
$this->expectException(\Exception::class);
$this->expectExceptionMessage(
'GraphQL response contains errors: Current customer' . ' ' .
'does not have access to the resource "customer"'
);
$this->graphQlQuery($query, [], '');
}
}

0 comments on commit a1c4d33

Please sign in to comment.