Skip to content

Commit

Permalink
magento/graphql-ce#732: Guest User can SendFriend products ignoring r…
Browse files Browse the repository at this point in the history
…estrictions
  • Loading branch information
naydav committed Jun 21, 2019
1 parent 0e59bcf commit 2dded7c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

namespace Magento\SendFriendGraphQl\Model\Resolver;

use Magento\Authorization\Model\UserContextInterface;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\GraphQl\Model\Query\ContextInterface;
use Magento\SendFriend\Helper\Data as SendFriendHelper;
use Magento\SendFriendGraphQl\Model\SendFriend\SendEmail;

Expand Down Expand Up @@ -48,10 +48,10 @@ public function __construct(
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
$userId = $context->getUserId();
$userType = $context->getUserType();

if (!$this->sendFriendHelper->isAllowForGuest() && $this->isUserGuest($userId, $userType)) {
/** @var ContextInterface $context */
if (!$this->sendFriendHelper->isAllowForGuest()
&& false === $context->getExtensionAttributes()->getIsCustomer()
) {
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
}

Expand All @@ -63,7 +63,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
$senderData,
$recipientsData
);

return array_merge($senderData, $recipientsData);
}

Expand Down Expand Up @@ -123,19 +122,4 @@ private function extractSenderData(array $args): array
],
];
}

/**
* Checking if current customer is guest
*
* @param int|null $customerId
* @param int|null $customerType
* @return bool
*/
private function isUserGuest(?int $customerId, ?int $customerType): bool
{
if (null === $customerId || null === $customerType) {
return true;
}
return 0 === (int)$customerId || (int)$customerType === UserContextInterface::USER_TYPE_GUEST;
}
}
3 changes: 0 additions & 3 deletions app/code/Magento/SendFriendGraphQl/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
"magento/framework": "*",
"magento/module-catalog": "*",
"magento/module-send-friend": "*",
"magento/module-authorization": "*"
},
"suggest": {
"magento/module-graph-ql": "*"
},
"license": [
Expand Down

0 comments on commit 2dded7c

Please sign in to comment.