Skip to content

Commit 9d182c1

Browse files
Merge pull request #3572 from magento-qwerty/2.1.17-bugfixes-181218
Fixed issues: - MAGETWO-90469: Added posibility to use captcha on share wishlist page - MAGETWO-88651: Wrong swatches behavior - MAGETWO-92727: Fixed wrong admin notifications behavior - MAGETWO-95401: Fixed incorrect flow of send-friend feature - MAGETWO-95440: Fixed incorrect sitemap request flow
2 parents 84a752f + ea90f31 commit 9d182c1

File tree

26 files changed

+746
-1515
lines changed

26 files changed

+746
-1515
lines changed

app/code/Magento/AdminNotification/Block/Grid/Renderer/Actions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function __construct(
3939
*/
4040
public function render(\Magento\Framework\DataObject $row)
4141
{
42-
$readDetailsHtml = $row->getUrl() ? '<a class="action-details" target="_blank" href="' . $row->getUrl() . '">' . __(
42+
$readDetailsHtml = $row->getUrl() ? '<a class="action-details" target="_blank" href="' .
43+
$this->escapeUrl($row->getUrl()) . '">' . __(
4344
'Read Details'
4445
) . '</a> | ' : '';
4546

app/code/Magento/Checkout/view/frontend/web/template/minicart/item/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<span data-bind="html: option.value.join('<br>')"></span>
4646
<!-- /ko -->
4747
<!-- ko ifnot: Array.isArray(option.value) -->
48-
<span data-bind="html: option.value"></span>
48+
<span data-bind="text: option.value"></span>
4949
<!-- /ko -->
5050
</dd>
5151
<!-- /ko -->

app/code/Magento/Checkout/view/frontend/web/template/summary/item/details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<dd class="values" data-bind="html: full_view"></dd>
3636
<!-- /ko -->
3737
<!-- ko ifnot: ($data.full_view)-->
38-
<dd class="values" data-bind="html: value"></dd>
38+
<dd class="values" data-bind="text: value"></dd>
3939
<!-- /ko -->
4040
<!-- /ko -->
4141
</dl>

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/dynamic-rows-configurable.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
define([
77
'underscore',
88
'uiRegistry',
9-
'Magento_Ui/js/dynamic-rows/dynamic-rows'
10-
], function (_, registry, dynamicRows) {
9+
'Magento_Ui/js/dynamic-rows/dynamic-rows',
10+
'jquery'
11+
], function (_, registry, dynamicRows, $) {
1112
'use strict';
1213

1314
return dynamicRows.extend({
@@ -217,6 +218,8 @@ define([
217218

218219
_.each(tmpData, function (row, index) {
219220
path = this.dataScope + '.' + this.index + '.' + (this.startIndex + index);
221+
row.attributes = $('<i></i>').text(row.attributes).text();
222+
row.sku = $('<i></i>').text(row.sku).text();
220223
this.source.set(path, row);
221224
}, this);
222225

@@ -376,8 +379,8 @@ define([
376379
product = {
377380
'id': row.productId,
378381
'product_link': row.productUrl,
379-
'name': row.name,
380-
'sku': row.sku,
382+
'name': $('<i></i>').text(row.name).text(),
383+
'sku': $('<i></i>').text(row.sku).text(),
381384
'status': row.status,
382385
'price': row.price,
383386
'price_currency': row.priceCurrency,

app/code/Magento/SendFriend/Block/Send.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\SendFriend\Block;
77

8+
use Magento\Captcha\Block\Captcha;
89
use Magento\Customer\Model\Context;
910

1011
/**
@@ -168,6 +169,7 @@ public function setFormData($data)
168169
/**
169170
* Retrieve Current Product Id
170171
*
172+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
171173
* @return int
172174
*/
173175
public function getProductId()
@@ -178,6 +180,7 @@ public function getProductId()
178180
/**
179181
* Retrieve current category id for product
180182
*
183+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
181184
* @return int
182185
*/
183186
public function getCategoryId()
@@ -220,4 +223,24 @@ public function canSend()
220223
{
221224
return !$this->sendfriend->isExceedLimit();
222225
}
226+
227+
/**
228+
* @inheritdoc
229+
*/
230+
protected function _prepareLayout()
231+
{
232+
if (!$this->getChildBlock('captcha')) {
233+
$this->addChild(
234+
'captcha',
235+
Captcha::class,
236+
[
237+
'cacheable' => false,
238+
'after' => '-',
239+
'form_id' => 'product_sendtofriend_form',
240+
'image_width' => 230,
241+
'image_height' => 230
242+
]
243+
);
244+
}
245+
}
223246
}

app/code/Magento/SendFriend/Controller/Product/Sendmail.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\SendFriend\Controller\Product;
108

119
use Magento\Framework\Exception\NoSuchEntityException;
1210
use Magento\Framework\Controller\ResultFactory;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\SendFriend\Model\CaptchaValidator;
1313

14+
/**
15+
* Controller class Sendmail. Represents send-mail action request flow
16+
*
17+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
*/
1419
class Sendmail extends \Magento\SendFriend\Controller\Product
1520
{
1621
/** @var \Magento\Catalog\Api\CategoryRepositoryInterface */
@@ -21,6 +26,11 @@ class Sendmail extends \Magento\SendFriend\Controller\Product
2126
*/
2227
protected $catalogSession;
2328

29+
/**
30+
* @var CaptchaValidator
31+
*/
32+
private $captchaValidator;
33+
2434
/**
2535
* @param \Magento\Framework\App\Action\Context $context
2636
* @param \Magento\Framework\Registry $coreRegistry
@@ -29,6 +39,9 @@ class Sendmail extends \Magento\SendFriend\Controller\Product
2939
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
3040
* @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
3141
* @param \Magento\Catalog\Model\Session $catalogSession
42+
* @param CaptchaValidator|null $captchaValidator
43+
*
44+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3245
*/
3346
public function __construct(
3447
\Magento\Framework\App\Action\Context $context,
@@ -37,11 +50,13 @@ public function __construct(
3750
\Magento\SendFriend\Model\SendFriend $sendFriend,
3851
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
3952
\Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository,
40-
\Magento\Catalog\Model\Session $catalogSession
53+
\Magento\Catalog\Model\Session $catalogSession,
54+
CaptchaValidator $captchaValidator = null
4155
) {
4256
parent::__construct($context, $coreRegistry, $formKeyValidator, $sendFriend, $productRepository);
4357
$this->categoryRepository = $categoryRepository;
4458
$this->catalogSession = $catalogSession;
59+
$this->captchaValidator = $captchaValidator ?: ObjectManager::getInstance()->create(CaptchaValidator::class);
4560
}
4661

4762
/**
@@ -89,6 +104,7 @@ public function execute()
89104

90105
try {
91106
$validate = $this->sendFriend->validate();
107+
$this->captchaValidator->validateSending($this->getRequest());
92108
if ($validate === true) {
93109
$this->sendFriend->send();
94110
$this->messageManager->addSuccess(__('The link to a friend was sent.'));
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\SendFriend\Model;
8+
9+
use Magento\Framework\App\RequestInterface;
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Captcha\Helper\Data;
12+
use Magento\Captcha\Model\DefaultModel;
13+
use Magento\Captcha\Observer\CaptchaStringResolver;
14+
use Magento\Authorization\Model\UserContextInterface;
15+
use Magento\Customer\Api\CustomerRepositoryInterface;
16+
17+
/**
18+
* Class CaptchaValidator. Performs captcha validation
19+
*/
20+
class CaptchaValidator
21+
{
22+
/**
23+
* @var Data
24+
*/
25+
private $captchaHelper;
26+
27+
/**
28+
* @var CaptchaStringResolver
29+
*/
30+
private $captchaStringResolver;
31+
32+
/**
33+
* @var UserContextInterface
34+
*/
35+
private $currentUser;
36+
37+
/**
38+
* @var CustomerRepositoryInterface
39+
*/
40+
private $customerRepository;
41+
42+
/**
43+
* CaptchaValidator constructor.
44+
*
45+
* @param Data $captchaHelper
46+
* @param CaptchaStringResolver $captchaStringResolver
47+
* @param UserContextInterface $currentUser
48+
* @param CustomerRepositoryInterface $customerRepository
49+
*/
50+
public function __construct(
51+
Data $captchaHelper,
52+
CaptchaStringResolver $captchaStringResolver,
53+
UserContextInterface $currentUser,
54+
CustomerRepositoryInterface $customerRepository
55+
) {
56+
$this->captchaHelper = $captchaHelper;
57+
$this->captchaStringResolver = $captchaStringResolver;
58+
$this->currentUser = $currentUser;
59+
$this->customerRepository = $customerRepository;
60+
}
61+
62+
/**
63+
* Entry point for captcha validation
64+
*
65+
* @param RequestInterface $request
66+
* @throws LocalizedException
67+
* @throws \Magento\Framework\Exception\NoSuchEntityException
68+
* @return void
69+
*/
70+
public function validateSending(RequestInterface $request)
71+
{
72+
$this->validateCaptcha($request);
73+
}
74+
75+
/**
76+
* Validates captcha and triggers log attempt
77+
*
78+
* @param RequestInterface $request
79+
* @throws LocalizedException
80+
* @throws \Magento\Framework\Exception\NoSuchEntityException
81+
* @return void
82+
*/
83+
private function validateCaptcha(RequestInterface $request)
84+
{
85+
$captchaTargetFormName = 'product_sendtofriend_form';
86+
/** @var DefaultModel $captchaModel */
87+
$captchaModel = $this->captchaHelper->getCaptcha($captchaTargetFormName);
88+
89+
if ($captchaModel->isRequired()) {
90+
$word = $this->captchaStringResolver->resolve(
91+
$request,
92+
$captchaTargetFormName
93+
);
94+
95+
$isCorrectCaptcha = $captchaModel->isCorrect($word);
96+
97+
if (!$isCorrectCaptcha) {
98+
$this->logCaptchaAttempt($captchaModel);
99+
throw new LocalizedException(__('Incorrect CAPTCHA'));
100+
}
101+
}
102+
103+
$this->logCaptchaAttempt($captchaModel);
104+
}
105+
106+
/**
107+
* Log captcha attempts
108+
*
109+
* @param DefaultModel $captchaModel
110+
* @throws LocalizedException
111+
* @throws \Magento\Framework\Exception\NoSuchEntityException
112+
* @return void
113+
*/
114+
private function logCaptchaAttempt(DefaultModel $captchaModel)
115+
{
116+
$email = '';
117+
118+
if ($this->currentUser->getUserType() == UserContextInterface::USER_TYPE_CUSTOMER) {
119+
$email = $this->customerRepository->getById($this->currentUser->getUserId())->getEmail();
120+
}
121+
122+
$captchaModel->logAttempt($email);
123+
}
124+
}

0 commit comments

Comments
 (0)