Skip to content

Commit 6cd3655

Browse files
Merge branch '2.4.3-develop' into 2.4.3-develop-2.4-develop-sync-032621
2 parents 12ebc0e + c1a5532 commit 6cd3655

File tree

35 files changed

+1535
-128
lines changed

35 files changed

+1535
-128
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Gallery/Upload.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public function execute()
108108

109109
$result['url'] = $this->productMediaConfig->getTmpMediaUrl($result['file']);
110110
$result['file'] = $result['file'] . '.tmp';
111-
} catch (\Exception $e) {
111+
} catch (LocalizedException $e) {
112112
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
113+
} catch (\Throwable $e) {
114+
$result = ['error' => 'Something went wrong while saving the file(s).', 'errorcode' => 0];
113115
}
114116

115117
/** @var \Magento\Framework\Controller\Result\Raw $response */

app/code/Magento/Catalog/Test/Mftf/Section/AdminAddProductsToOptionPanelSection.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* See COPYING.txt for license details.
66
*/
77
-->
8-
98
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
109
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1110
<section name="AdminAddProductsToOptionPanel">
@@ -16,4 +15,4 @@
1615
<element name="firstCheckbox" type="input" selector="//tr[1]//input[@data-action='select-row']"/>
1716
<element name="nthCheckbox" type="input" selector="//tr[{{var}}]//input[@data-action='select-row']" parameterized="true"/>
1817
</section>
19-
</sections>
18+
</sections>

app/code/Magento/ConfigurableProduct/Plugin/Model/Attribute/Backend/AttributeValidation.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend;
78

9+
use Closure;
810
use Magento\Catalog\Api\Data\ProductInterface;
911
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
12+
use Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend;
13+
use Magento\Framework\DataObject;
1014

1115
/**
12-
* Skip validate attributes used for create configurable product
16+
* Skip validate attributes used for create configurable product.
1317
*/
1418
class AttributeValidation
1519
{
@@ -19,29 +23,36 @@ class AttributeValidation
1923
private $configurableProductType;
2024

2125
/**
22-
* AttributeValidation constructor.
26+
* @var array
27+
*/
28+
private $unskippableAttributes;
29+
30+
/**
2331
* @param Configurable $configurableProductType
32+
* @param array|null $unskippableAttributes
2433
*/
2534
public function __construct(
26-
Configurable $configurableProductType
35+
Configurable $configurableProductType,
36+
array $unskippableAttributes = []
2737
) {
2838
$this->configurableProductType = $configurableProductType;
39+
$this->unskippableAttributes = $unskippableAttributes;
2940
}
3041

3142
/**
32-
* @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject
43+
* Around plugin to skip attribute validation used for create configurable product.
44+
*
45+
* @param AbstractBackend $subject
3346
* @param \Closure $proceed
34-
* @param \Magento\Framework\DataObject $entity
47+
* @param DataObject $entity
3548
* @return bool
3649
*/
37-
public function aroundValidate(
38-
\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject,
39-
\Closure $proceed,
40-
\Magento\Framework\DataObject $entity
41-
) {
50+
public function aroundValidate(AbstractBackend $subject, Closure $proceed, DataObject $entity)
51+
{
4252
$attribute = $subject->getAttribute();
4353
if ($entity instanceof ProductInterface
4454
&& $entity->getTypeId() == Configurable::TYPE_CODE
55+
&& !in_array($attribute->getAttributeCode(), $this->unskippableAttributes)
4556
&& in_array(
4657
$attribute->getAttributeId(),
4758
$this->configurableProductType->getUsedProductAttributeIds($entity),
@@ -50,6 +61,7 @@ public function aroundValidate(
5061
) {
5162
return true;
5263
}
64+
5365
return $proceed($entity);
5466
}
5567
}

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
<type name="Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend">
3434
<plugin name="ConfigurableProduct::skipValidation" type="Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend\AttributeValidation"/>
3535
</type>
36+
<type name="Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend\AttributeValidation">
37+
<arguments>
38+
<argument name="unskippableAttributes" xsi:type="array">
39+
<item name="custom_layout_update" xsi:type="string">custom_layout_update</item>
40+
</argument>
41+
</arguments>
42+
</type>
3643
<type name="Magento\Catalog\Model\Entity\Product\Attribute\Group\AttributeMapperInterface">
3744
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Model\Entity\Product\Attribute\Group\AttributeMapper\Plugin" sortOrder="50" />
3845
</type>

app/code/Magento/Csp/Helper/InlineUtil.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Magento\Csp\Helper;
1010

1111
use Magento\Csp\Api\InlineUtilInterface;
12+
use Magento\Csp\Model\Collector\ConfigCollector;
1213
use Magento\Csp\Model\Collector\DynamicCollector;
1314
use Magento\Csp\Model\Policy\FetchPolicy;
1415
use Magento\Framework\App\ObjectManager;
@@ -39,6 +40,11 @@ class InlineUtil implements InlineUtilInterface, SecurityProcessorInterface
3940
*/
4041
private $htmlRenderer;
4142

43+
/**
44+
* @var ConfigCollector
45+
*/
46+
private $configCollector;
47+
4248
private static $tagMeta = [
4349
'script' => ['id' => 'script-src', 'remote' => ['src'], 'hash' => true],
4450
'style' => ['id' => 'style-src', 'remote' => [], 'hash' => true],
@@ -60,15 +66,18 @@ class InlineUtil implements InlineUtilInterface, SecurityProcessorInterface
6066
* @param DynamicCollector $dynamicCollector
6167
* @param bool $useUnsafeHashes Use 'unsafe-hashes' policy (not supported by CSP v2).
6268
* @param HtmlRenderer|null $htmlRenderer
69+
* @param ConfigCollector|null $configCollector
6370
*/
6471
public function __construct(
6572
DynamicCollector $dynamicCollector,
6673
bool $useUnsafeHashes = false,
67-
?HtmlRenderer $htmlRenderer = null
74+
?HtmlRenderer $htmlRenderer = null,
75+
?ConfigCollector $configCollector = null
6876
) {
6977
$this->dynamicCollector = $dynamicCollector;
7078
$this->useUnsafeHashes = $useUnsafeHashes;
7179
$this->htmlRenderer = $htmlRenderer ?? ObjectManager::getInstance()->get(HtmlRenderer::class);
80+
$this->configCollector = $configCollector ?? ObjectManager::getInstance()->get(ConfigCollector::class);
7281
}
7382

7483
/**
@@ -187,7 +196,10 @@ public function processTag(TagData $tagData): TagData
187196
new FetchPolicy($policyId, false, $remotes)
188197
);
189198
}
190-
if ($tagData->getContent() && !empty(self::$tagMeta[$tagData->getTag()]['hash'])) {
199+
if ($tagData->getContent()
200+
&& !empty(self::$tagMeta[$tagData->getTag()]['hash'])
201+
&& $this->isInlineDisabled(self::$tagMeta[$tagData->getTag()]['id'])
202+
) {
191203
$this->dynamicCollector->add(
192204
new FetchPolicy(
193205
$policyId,
@@ -233,4 +245,21 @@ public function processEventHandler(EventHandlerData $eventHandlerData): EventHa
233245

234246
return $eventHandlerData;
235247
}
248+
249+
/**
250+
* Check if inline sources are prohibited.
251+
*
252+
* @param string $policyId
253+
* @return bool
254+
*/
255+
private function isInlineDisabled(string $policyId): bool
256+
{
257+
foreach ($this->configCollector->collect() as $policy) {
258+
if ($policy->getId() === $policyId && $policy instanceof FetchPolicy) {
259+
return !$policy->isInlineAllowed();
260+
}
261+
}
262+
263+
return false;
264+
}
236265
}

0 commit comments

Comments
 (0)