Skip to content

Commit

Permalink
Merge branch 'magento-commerce:2.4-develop' into MC-39920
Browse files Browse the repository at this point in the history
  • Loading branch information
bubasuma authored Dec 23, 2021
2 parents 5e6376c + d0dccd8 commit 4ef1718
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/etc/acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<resource id="Magento_Catalog::catalog" title="Catalog" translate="title" sortOrder="30">
<resource id="Magento_Catalog::catalog_inventory" title="Inventory" translate="title" sortOrder="10">
<resource id="Magento_Catalog::products" title="Products" translate="title" sortOrder="10">
<resource id="Magento_Catalog::update_attributes" title="Update Attributes" translate="title" sortOrder="10" />
<resource id="Magento_Catalog::update_attributes" title="Mass Update Attributes" translate="title" sortOrder="10" />
<resource id="Magento_Catalog::edit_product_design" title="Edit Product Design" translate="title" sortOrder="20" />
</resource>
<resource id="Magento_Catalog::categories" title="Categories" translate="title" sortOrder="20">
Expand All @@ -27,7 +27,7 @@
</resource>
</resource>
<resource id="Magento_Backend::stores_attributes">
<resource id="Magento_Catalog::attributes_attributes" title="Product" translate="title" sortOrder="30" />
<resource id="Magento_Catalog::attributes_attributes" title="Product" translate="title" sortOrder="30"/>
<resource id="Magento_Catalog::sets" title="Attribute Set" translate="title" sortOrder="40"/>
</resource>
</resource>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Quantity,Quantity
Edit,Edit
"Are you sure?","Are you sure?"
"Change Status","Change Status"
"Update Attributes","Update Attributes"
"Mass Update Attributes","Mass Update Attributes"
"start typing to search category","start typing to search category"
"New Category","New Category"
"Images (.gif, .jpg, .png)","Images (.gif, .jpg, .png)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<div class="action-dropdown-menu-item-edit" visible="customVisible">
<input class="admin__control-text" type="text"
data-bind="
attr: {'aria-label': $t('New View')},
value: customLabel,
hasFocus: isCustomVisible(),
keyboard: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function testTopologyInstallation(array $expectedConfig, array $bindingCo
$this->assertArrayHasKey($name, $this->declaredExchanges);
unset(
$this->declaredExchanges[$name]['message_stats'],
$this->declaredExchanges[$name]['user_who_performed_action']
$this->declaredExchanges[$name]['user_who_performed_action'],
$this->declaredExchanges[$name]['policy']
);

$this->assertEquals(
Expand Down
43 changes: 38 additions & 5 deletions lib/internal/Magento/Framework/Session/SaveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@

namespace Magento\Framework\Session;

use Magento\Framework\App\Area;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\State;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\SessionException;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Session\Config\ConfigInterface;
use Psr\Log\LoggerInterface;

/**
* Magento session save handler.
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SaveHandler implements SaveHandlerInterface
{
Expand Down Expand Up @@ -48,25 +53,41 @@ class SaveHandler implements SaveHandlerInterface
*/
private $sessionMaxSizeConfig;

/**
* @var ManagerInterface
*/
private $messageManager;

/**
* @var State|mixed
*/
private $appState;

/**
* @param SaveHandlerFactory $saveHandlerFactory
* @param ConfigInterface $sessionConfig
* @param LoggerInterface $logger
* @param SessionMaxSizeConfig $sessionMaxSizeConfigs
* @param string $default
* @param ManagerInterface|null $messageManager
* @param State|null $appState
*/
public function __construct(
SaveHandlerFactory $saveHandlerFactory,
ConfigInterface $sessionConfig,
LoggerInterface $logger,
SessionMaxSizeConfig $sessionMaxSizeConfigs,
$default = self::DEFAULT_HANDLER
$default = self::DEFAULT_HANDLER,
ManagerInterface $messageManager = null,
State $appState = null
) {
$this->saveHandlerFactory = $saveHandlerFactory;
$this->sessionConfig = $sessionConfig;
$this->logger = $logger;
$this->defaultHandler = $default;
$this->sessionMaxSizeConfig = $sessionMaxSizeConfigs;
$this->messageManager = $messageManager ?: ObjectManager::getInstance()->get(ManagerInterface::class);
$this->appState = $appState ?: ObjectManager::getInstance()->get(State::class);
}

/**
Expand Down Expand Up @@ -99,10 +120,22 @@ public function close()
* @param string $sessionId
* @return string
*/
#[\ReturnTypeWillChange]
public function read($sessionId)
public function read($sessionId): string
{
return $this->callSafely('read', $sessionId);
$sessionData = $this->callSafely('read', $sessionId);
$sessionMaxSize = $this->sessionMaxSizeConfig->getSessionMaxSize();
$sessionSize = strlen($sessionData);

if ($sessionSize !== null && $sessionMaxSize < $sessionSize) {
$sessionData = '';
if ($this->appState->getAreaCode() === Area::AREA_FRONTEND) {
$this->messageManager->addErrorMessage(
__('There is an error. Please Contact store administrator.')
);
}
}

return $sessionData;
}

/**
Expand Down Expand Up @@ -131,7 +164,7 @@ public function write($sessionId, $data)
)
);

return $this->callSafely('write', $sessionId, $this->read($sessionId));
return $this->callSafely('write', $sessionId, $data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,33 @@ public function testWriteSessionMaxSizeNull()
$this->assertTrue($this->saveHandler->write("test_session_id", "testdata"));
}

public function testWriteMoreThanSessionMaxSize()
public function testWriteMoreThanSessionMaxSize(): void
{
$this->sessionMaxSizeConfigMock->expects($this->once())
$this->sessionMaxSizeConfigMock
->expects($this->once())
->method('getSessionMaxSize')
->willReturn(1);

$this->saveHandlerAdapterMock
->expects($this->never())
->method('read');

$this->assertTrue($this->saveHandler->write("test_session_id", "testdata"));
}

public function testReadMoreThanSessionMaxSize(): void
{
$this->sessionMaxSizeConfigMock
->expects($this->once())
->method('getSessionMaxSize')
->willReturn(1);

$this->saveHandlerAdapterMock->expects($this->once())
$this->saveHandlerAdapterMock
->expects($this->once())
->method('read')
->with('test_session_id')
->willReturn('test_session_data');

$this->assertTrue($this->saveHandler->write("test_session_id", "testdata"));
$this->assertEquals(null, $this->saveHandler->read("test_session_id"));
}
}

0 comments on commit 4ef1718

Please sign in to comment.