Skip to content

Commit 2dded7c

Browse files
committed
magento/graphql-ce#732: Guest User can SendFriend products ignoring restrictions
1 parent 0e59bcf commit 2dded7c

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

app/code/Magento/SendFriendGraphQl/Model/Resolver/SendEmailToFriend.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
namespace Magento\SendFriendGraphQl\Model\Resolver;
99

10-
use Magento\Authorization\Model\UserContextInterface;
1110
use Magento\Framework\GraphQl\Config\Element\Field;
1211
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1312
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1413
use Magento\Framework\GraphQl\Query\ResolverInterface;
1514
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\GraphQl\Model\Query\ContextInterface;
1616
use Magento\SendFriend\Helper\Data as SendFriendHelper;
1717
use Magento\SendFriendGraphQl\Model\SendFriend\SendEmail;
1818

@@ -48,10 +48,10 @@ public function __construct(
4848
*/
4949
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
5050
{
51-
$userId = $context->getUserId();
52-
$userType = $context->getUserType();
53-
54-
if (!$this->sendFriendHelper->isAllowForGuest() && $this->isUserGuest($userId, $userType)) {
51+
/** @var ContextInterface $context */
52+
if (!$this->sendFriendHelper->isAllowForGuest()
53+
&& false === $context->getExtensionAttributes()->getIsCustomer()
54+
) {
5555
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
5656
}
5757

@@ -63,7 +63,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6363
$senderData,
6464
$recipientsData
6565
);
66-
6766
return array_merge($senderData, $recipientsData);
6867
}
6968

@@ -123,19 +122,4 @@ private function extractSenderData(array $args): array
123122
],
124123
];
125124
}
126-
127-
/**
128-
* Checking if current customer is guest
129-
*
130-
* @param int|null $customerId
131-
* @param int|null $customerType
132-
* @return bool
133-
*/
134-
private function isUserGuest(?int $customerId, ?int $customerType): bool
135-
{
136-
if (null === $customerId || null === $customerType) {
137-
return true;
138-
}
139-
return 0 === (int)$customerId || (int)$customerType === UserContextInterface::USER_TYPE_GUEST;
140-
}
141125
}

app/code/Magento/SendFriendGraphQl/composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"magento/framework": "*",
88
"magento/module-catalog": "*",
99
"magento/module-send-friend": "*",
10-
"magento/module-authorization": "*"
11-
},
12-
"suggest": {
1310
"magento/module-graph-ql": "*"
1411
},
1512
"license": [

0 commit comments

Comments
 (0)