Skip to content

Commit d57d43a

Browse files
committed
MC-18719: private cookie version increments each post request
1 parent dd925fd commit d57d43a

File tree

8 files changed

+74
-46
lines changed

8 files changed

+74
-46
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Magento\Customer\Block;
4+
5+
use Magento\Framework\Config\DataInterface;
6+
use Magento\Framework\View\Element\Block\ArgumentInterface;
7+
8+
/**
9+
* ViewModel to get sections names array.
10+
*/
11+
class SectionNamesProvider implements ArgumentInterface
12+
{
13+
/**
14+
* @var \Magento\Framework\Config\DataInterface
15+
*/
16+
protected $sectionConfig;
17+
18+
/**
19+
* @param \Magento\Framework\Config\DataInterface $sectionConfig
20+
*/
21+
public function __construct(
22+
DataInterface $sectionConfig
23+
) {
24+
$this->sectionConfig = $sectionConfig->get('sections');
25+
}
26+
27+
/**
28+
* Return array of section names based on config.
29+
*
30+
* @return array
31+
*/
32+
public function getSectionNames()
33+
{
34+
$resultSectionNames = [];
35+
foreach ($this->sectionConfig as $sectionRule => $sectionNames) {
36+
if (is_array($sectionNames)) {
37+
$resultSectionNames = array_merge($resultSectionNames, $sectionNames);
38+
}
39+
}
40+
41+
if ($allNameIndex = array_search('*', $resultSectionNames, true)) {
42+
unset($resultSectionNames[$allNameIndex]);
43+
}
44+
45+
return array_values(array_unique($resultSectionNames));
46+
}
47+
}

app/code/Magento/Customer/Block/SectionsNameProvider.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@
157157
<argument name="sectionConfig" xsi:type="object">SectionInvalidationConfigData</argument>
158158
</arguments>
159159
</type>
160+
<type name="Magento\Customer\Block\SectionNamesProvider">
161+
<arguments>
162+
<argument name="sectionConfig" xsi:type="object">SectionInvalidationConfigData</argument>
163+
</arguments>
164+
</type>
160165
<preference for="Magento\Customer\CustomerData\JsLayoutDataProviderPoolInterface"
161166
type="Magento\Customer\CustomerData\JsLayoutDataProviderPool"/>
162167
<type name="Magento\Framework\Webapi\ServiceTypeToEntityTypeMap">

app/code/Magento/Customer/view/frontend/layout/default.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@
4141
</arguments>
4242
</block>
4343
<block name="customer.section.config" class="Magento\Customer\Block\SectionConfig"
44-
template="Magento_Customer::js/section-config.phtml"/>
45-
<block name="customer.customer.data"
46-
class="Magento\Customer\Block\CustomerData"
47-
template="Magento_Customer::js/customer-data.phtml">
44+
template="Magento_Customer::js/section-config.phtml">
4845
<arguments>
49-
<argument name="sectionsNameProvider" xsi:type="object">Magento\Customer\Block\SectionsNameProvider</argument>
46+
<argument name="sectionNamesProvider" xsi:type="object">Magento\Customer\Block\SectionNamesProvider</argument>
5047
</arguments>
5148
</block>
49+
<block name="customer.customer.data" class="Magento\Customer\Block\CustomerData"
50+
template="Magento_Customer::js/customer-data.phtml"/>
5251
<block name="customer.data.invalidation.rules" class="Magento\Customer\Block\CustomerScopeData"
5352
template="Magento_Customer::js/customer-data/invalidation-rules.phtml"/>
5453
</referenceContainer>

app/code/Magento/Customer/view/frontend/templates/js/customer-data.phtml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"expirableSectionLifetime": <?= (int)$block->getExpirableSectionLifetime() ?>,
1515
"expirableSectionNames": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getExpirableSectionNames()) ?>,
1616
"cookieLifeTime": "<?= $block->escapeJs($block->getCookieLifeTime()) ?>",
17-
"updateSessionUrl": "<?= $block->escapeJs($block->escapeUrl($block->getCustomerDataUrl('customer/account/updateSession'))) ?>",
18-
"sectionsName": <?= $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getData('sectionsNameProvider')->getSectionsName()) ?>
17+
"updateSessionUrl": "<?= $block->escapeJs($block->escapeUrl($block->getCustomerDataUrl('customer/account/updateSession'))) ?>"
1918
}
2019
}
2120
}

app/code/Magento/Customer/view/frontend/templates/js/section-config.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"baseUrls": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode(array_unique([
1616
$block->getUrl(null, ['_secure' => true]),
1717
$block->getUrl(null, ['_secure' => false]),
18-
])) ?>
18+
])) ?>,
19+
"sectionNames": <?= $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($block->getData('sectionNamesProvider')->getSectionNames()) ?>
1920
}
2021
}
2122
}

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,10 @@ define([
320320
var sectionDataIds,
321321
sectionsNamesForInvalidation;
322322

323-
sectionsNamesForInvalidation = _.contains(sectionNames, '*') ? options.sectionsName : sectionNames;
323+
sectionsNamesForInvalidation = _.contains(sectionNames, '*')
324+
? sectionConfig.getSectionNames()
325+
: sectionNames;
326+
324327
$(document).trigger('customer-data-invalidate', [sectionsNamesForInvalidation]);
325328
buffer.remove(sectionsNamesForInvalidation);
326329
sectionDataIds = $.cookieStorage.get('section_data_ids') || {};

app/code/Magento/Customer/view/frontend/web/js/section-config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
define(['underscore'], function (_) {
77
'use strict';
88

9-
var baseUrls, sections, clientSideSections, canonize;
9+
var baseUrls, sections, clientSideSections, sectionNames, canonize;
1010

1111
/**
1212
* @param {String} url
@@ -70,6 +70,15 @@ define(['underscore'], function (_) {
7070
return _.contains(clientSideSections, sectionName);
7171
},
7272

73+
/**
74+
* Returns array of section names.
75+
*
76+
* @returns {Array}
77+
*/
78+
getSectionNames: function () {
79+
return sectionNames;
80+
},
81+
7382
/**
7483
* @param {Object} options
7584
* @constructor
@@ -78,6 +87,7 @@ define(['underscore'], function (_) {
7887
baseUrls = options.baseUrls;
7988
sections = options.sections;
8089
clientSideSections = options.clientSideSections;
90+
sectionNames = options.sectionNames;
8191
}
8292
};
8393
});

0 commit comments

Comments
 (0)