Skip to content

Commit a67e6bf

Browse files
[Magento Community Engineering] Community Contributions - 2.4-develop
- merged latest code from mainline branch
2 parents 5fad0cd + ba89f12 commit a67e6bf

File tree

13 files changed

+232
-50
lines changed

13 files changed

+232
-50
lines changed

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ sub vcl_recv {
108108
#unset req.http.Cookie;
109109
}
110110

111+
# Authenticated GraphQL requests should not be cached by default
112+
if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
113+
return (pass);
114+
}
115+
111116
return (hash);
112117
}
113118

app/code/Magento/PageCache/etc/varnish5.vcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ sub vcl_recv {
109109
#unset req.http.Cookie;
110110
}
111111

112+
# Authenticated GraphQL requests should not be cached by default
113+
if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
114+
return (pass);
115+
}
116+
112117
return (hash);
113118
}
114119

app/code/Magento/PageCache/etc/varnish6.vcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ sub vcl_recv {
109109
#unset req.http.Cookie;
110110
}
111111

112+
# Authenticated GraphQL requests should not be cached by default
113+
if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
114+
return (pass);
115+
}
116+
112117
return (hash);
113118
}
114119

app/code/Magento/Quote/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Subtotal,Subtotal
3131
"Cart %1 does not contain item %2","Cart %1 does not contain item %2"
3232
"Could not save quote","Could not save quote"
3333
"Cart %1 doesn't contain item %2","Cart %1 doesn't contain item %2"
34+
"The cart doesn't contain the item","The cart doesn't contain the item"
3435
"Could not remove item from quote","Could not remove item from quote"
3536
"The qty value is required to update quote item.","The qty value is required to update quote item."
3637
"Minimum order amount is %1","Minimum order amount is %1"

app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6565
try {
6666
$this->cartItemRepository->deleteById((int)$cart->getId(), $itemId);
6767
} catch (NoSuchEntityException $e) {
68-
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
68+
throw new GraphQlNoSuchEntityException(__('The cart doesn\'t contain the item'));
6969
} catch (LocalizedException $e) {
7070
throw new GraphQlInputException(__($e->getMessage()), $e);
7171
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ public function __construct(
4848
*/
4949
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
5050
{
51+
$storeId = $context->getExtensionAttributes()->getStore()->getId();
52+
53+
if (!$this->sendFriendHelper->isEnabled($storeId)) {
54+
throw new GraphQlInputException(__('"Email to a Friend" is not enabled.'));
55+
}
56+
5157
/** @var ContextInterface $context */
52-
if (!$this->sendFriendHelper->isAllowForGuest()
58+
if (!$this->sendFriendHelper->isAllowForGuest($storeId)
5359
&& false === $context->getExtensionAttributes()->getIsCustomer()
5460
) {
5561
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SendFriendGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Query\ResolverInterface;
12+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13+
use Magento\SendFriend\Helper\Data as SendFriendHelper;
14+
15+
/**
16+
* Resolve Store Config information for SendFriend
17+
*/
18+
class SendFriendConfiguration implements ResolverInterface
19+
{
20+
/**
21+
* @var SendFriendHelper
22+
*/
23+
private $sendFriendHelper;
24+
25+
/**
26+
* @param SendFriendHelper $sendFriendHelper
27+
*/
28+
public function __construct(SendFriendHelper $sendFriendHelper)
29+
{
30+
$this->sendFriendHelper = $sendFriendHelper;
31+
}
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
37+
{
38+
$store = $context->getExtensionAttributes()->getStore();
39+
$storeId = $store->getId();
40+
41+
return [
42+
'enabled_for_customers' => $this->sendFriendHelper->isEnabled($storeId),
43+
'enabled_for_guests' => $this->sendFriendHelper->isAllowForGuest($storeId)
44+
];
45+
}
46+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ type SendEmailToFriendRecipient {
3737
name: String!
3838
email: String!
3939
}
40+
41+
type StoreConfig {
42+
send_friend: SendFriendConfiguration @resolver(class: "\\Magento\\SendFriendGraphQl\\Model\\Resolver\\SendFriendConfiguration") @doc(description: "Email to a Friend configuration.")
43+
}
44+
45+
type SendFriendConfiguration {
46+
enabled_for_customers: Boolean! @doc(description: "Indicates whether the Email to a Friend feature is enabled.")
47+
enabled_for_guests: Boolean! @doc(description: "Indicates whether the Email to a Friend feature is enabled for guests.")
48+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testRemoveNonExistentItem()
8484
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
8585
$notExistentItemId = 999;
8686

87-
$this->expectExceptionMessage("Cart doesn't contain the {$notExistentItemId} item.");
87+
$this->expectExceptionMessage("The cart doesn't contain the item");
8888

8989
$query = $this->getQuery($maskedQuoteId, $notExistentItemId);
9090
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
@@ -106,7 +106,7 @@ public function testRemoveItemIfItemIsNotBelongToCart()
106106
'virtual-product'
107107
);
108108

109-
$this->expectExceptionMessage("Cart doesn't contain the {$secondQuoteItemId} item.");
109+
$this->expectExceptionMessage("The cart doesn't contain the item");
110110

111111
$query = $this->getQuery($firstQuoteMaskedId, $secondQuoteItemId);
112112
$this->graphQlMutation($query, [], '', $this->getHeaderMap());

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/RemoveItemFromCartTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testRemoveNonExistentItem()
7474
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
7575
$notExistentItemId = 999;
7676

77-
$this->expectExceptionMessage("Cart doesn't contain the {$notExistentItemId} item.");
77+
$this->expectExceptionMessage("The cart doesn't contain the item");
7878

7979
$query = $this->getQuery($maskedQuoteId, $notExistentItemId);
8080
$this->graphQlMutation($query);
@@ -95,7 +95,7 @@ public function testRemoveItemIfItemIsNotBelongToCart()
9595
'virtual-product'
9696
);
9797

98-
$this->expectExceptionMessage("Cart doesn't contain the {$secondQuoteItemId} item.");
98+
$this->expectExceptionMessage("The cart doesn't contain the item");
9999

100100
$query = $this->getQuery($firstQuoteMaskedId, $secondQuoteItemId);
101101
$this->graphQlMutation($query);

dev/tests/api-functional/testsuite/Magento/GraphQl/SendFriend/SendFriendTest.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected function setUp()
4545

4646
/**
4747
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
48+
* @magentoConfigFixture default_store sendfriend/email/enabled 1
4849
* @magentoConfigFixture default_store sendfriend/email/allow_guest 1
4950
*/
5051
public function testSendFriendGuestEnable()
@@ -66,6 +67,7 @@ public function testSendFriendGuestEnable()
6667

6768
/**
6869
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
70+
* @magentoConfigFixture default_store sendfriend/email/enabled 1
6971
* @magentoConfigFixture default_store sendfriend/email/allow_guest 0
7072
* @expectedException \Exception
7173
* @expectedExceptionMessage The current customer isn't authorized.
@@ -90,9 +92,11 @@ public function testSendFriendGuestDisableAsGuest()
9092
/**
9193
* @magentoApiDataFixture Magento/Customer/_files/customer.php
9294
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
93-
* @magentoConfigFixture default_store sendfriend/email/allow_guest 0
95+
* @magentoConfigFixture default_store sendfriend/email/enabled 0
96+
* @expectedException \Exception
97+
* @expectedExceptionMessage "Email to a Friend" is not enabled.
9498
*/
95-
public function testSendFriendGuestDisableAsCustomer()
99+
public function testSendFriendDisableAsCustomer()
96100
{
97101
$productId = (int)$this->productRepository->get('simple_product')->getId();
98102
$recipients = '{
@@ -111,6 +115,9 @@ public function testSendFriendGuestDisableAsCustomer()
111115

112116
/**
113117
* @magentoApiDataFixture Magento/Customer/_files/customer.php
118+
* @magentoConfigFixture default_store sendfriend/email/enabled 1
119+
* @expectedException \Exception
120+
* @expectedExceptionMessage The product that was requested doesn't exist. Verify the product and try again.
114121
*/
115122
public function testSendWithoutExistProduct()
116123
{
@@ -125,15 +132,13 @@ public function testSendWithoutExistProduct()
125132
}';
126133
$query = $this->getQuery($productId, $recipients);
127134

128-
$this->expectExceptionMessage(
129-
'The product that was requested doesn\'t exist. Verify the product and try again.'
130-
);
131135
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
132136
}
133137

134138
/**
135139
* @magentoApiDataFixture Magento/Customer/_files/customer.php
136140
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
141+
* @magentoConfigFixture default_store sendfriend/email/enabled 1
137142
*/
138143
public function testMaxSendEmailToFriend()
139144
{
@@ -176,6 +181,7 @@ public function testMaxSendEmailToFriend()
176181
/**
177182
* @magentoApiDataFixture Magento/Customer/_files/customer.php
178183
* @magentoApiDataFixture Magento/Catalog/_files/product_simple.php
184+
* @magentoConfigFixture default_store sendfriend/email/enabled 1
179185
* @dataProvider sendFriendsErrorsDataProvider
180186
* @param string $input
181187
* @param string $errorMessage
@@ -188,7 +194,7 @@ public function testErrors(string $input, string $errorMessage)
188194
sendEmailToFriend(
189195
input: {
190196
$input
191-
}
197+
}
192198
) {
193199
sender {
194200
name
@@ -210,6 +216,7 @@ public function testErrors(string $input, string $errorMessage)
210216
/**
211217
* @magentoApiDataFixture Magento/Customer/_files/customer.php
212218
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
219+
* @magentoConfigFixture default_store sendfriend/email/enabled 1
213220
* @magentoConfigFixture default_store sendfriend/email/max_per_hour 1
214221
* @magentoApiDataFixture Magento/SendFriend/Fixtures/sendfriend_configuration.php
215222
*/
@@ -238,6 +245,7 @@ public function testLimitMessagesPerHour()
238245
/**
239246
* @magentoApiDataFixture Magento/Customer/_files/customer.php
240247
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
248+
* @magentoConfigFixture default_store sendfriend/email/enabled 1
241249
*/
242250
public function testSendProductWithoutSenderEmail()
243251
{
@@ -256,6 +264,7 @@ public function testSendProductWithoutSenderEmail()
256264
/**
257265
* @magentoApiDataFixture Magento/Customer/_files/customer.php
258266
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product_without_visibility.php
267+
* @magentoConfigFixture default_store sendfriend/email/enabled 1
259268
*/
260269
public function testSendProductWithoutVisibility()
261270
{
@@ -282,12 +291,12 @@ public function sendFriendsErrorsDataProvider()
282291
{
283292
return [
284293
[
285-
'product_id: 1
294+
'product_id: 1
286295
sender: {
287296
name: "Name"
288297
email: "e@mail.com"
289298
message: "Lorem Ipsum"
290-
}
299+
}
291300
recipients: [
292301
{
293302
name: ""
@@ -300,12 +309,12 @@ public function sendFriendsErrorsDataProvider()
300309
]', 'Please provide Name for all of recipients.'
301310
],
302311
[
303-
'product_id: 1
312+
'product_id: 1
304313
sender: {
305314
name: "Name"
306315
email: "e@mail.com"
307316
message: "Lorem Ipsum"
308-
}
317+
}
309318
recipients: [
310319
{
311320
name: "Recipient Name 1"
@@ -318,12 +327,12 @@ public function sendFriendsErrorsDataProvider()
318327
]', 'Please provide Email for all of recipients.'
319328
],
320329
[
321-
'product_id: 1
330+
'product_id: 1
322331
sender: {
323332
name: ""
324333
email: "e@mail.com"
325334
message: "Lorem Ipsum"
326-
}
335+
}
327336
recipients: [
328337
{
329338
name: "Recipient Name 1"
@@ -336,12 +345,12 @@ public function sendFriendsErrorsDataProvider()
336345
]', 'Please provide Name of sender.'
337346
],
338347
[
339-
'product_id: 1
348+
'product_id: 1
340349
sender: {
341350
name: "Name"
342351
email: "e@mail.com"
343352
message: ""
344-
}
353+
}
345354
recipients: [
346355
{
347356
name: "Recipient Name 1"
@@ -403,9 +412,9 @@ private function getQuery(int $productId, string $recipients): string
403412
name: "Name"
404413
email: "e@mail.com"
405414
message: "Lorem Ipsum"
406-
}
415+
}
407416
recipients: [{$recipients}]
408-
}
417+
}
409418
) {
410419
sender {
411420
name

0 commit comments

Comments
 (0)