Skip to content

Commit ad2d25c

Browse files
Merge branch '2.3-develop' into 2.3-qwerty
# Conflicts: # app/code/Magento/Email/Model/Template.php
2 parents eb2d36a + 3ccf676 commit ad2d25c

File tree

332 files changed

+6793
-2896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

332 files changed

+6793
-2896
lines changed

app/code/Magento/AdminNotification/view/adminhtml/layout/adminhtml_notification_block.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<block class="Magento\Backend\Block\Widget\Grid" name="adminhtml.notification.container.grid" as="grid">
1212
<arguments>
1313
<argument name="id" xsi:type="string">notificationGrid</argument>
14-
<argument name="dataSource" xsi:type="object">Magento\AdminNotification\Model\ResourceModel\Grid\Collection</argument>
14+
<argument name="dataSource" xsi:type="object" shared="false">Magento\AdminNotification\Model\ResourceModel\Grid\Collection</argument>
1515
<argument name="default_dir" xsi:type="string">DESC</argument>
1616
<argument name="default_sort" xsi:type="string">date_added</argument>
1717
<argument name="save_parameters_in_session" xsi:type="string">1</argument>

app/code/Magento/AdvancedSearch/view/adminhtml/layout/catalog_search_block.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<block class="Magento\AdvancedSearch\Block\Adminhtml\Search\Grid" name="search.edit.grid" as="grid">
1212
<arguments>
1313
<argument name="id" xsi:type="string">catalog_search_grid</argument>
14-
<argument name="dataSource" xsi:type="object">Magento\AdvancedSearch\Model\ResourceModel\Search\Grid\Collection</argument>
14+
<argument name="dataSource" xsi:type="object" shared="false">Magento\AdvancedSearch\Model\ResourceModel\Search\Grid\Collection</argument>
1515
<argument name="default_sort" xsi:type="string">name</argument>
1616
<argument name="default_dir" xsi:type="string">ASC</argument>
1717
<argument name="save_parameters_in_session" xsi:type="string">1</argument>

app/code/Magento/Authorization/Model/Role.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,29 @@ public function __construct(
5151
}
5252

5353
/**
54-
* {@inheritdoc}
54+
* @inheritDoc
55+
*
56+
* @SuppressWarnings(PHPMD.SerializationAware)
57+
* @deprecated Do not use PHP serialization.
5558
*/
5659
public function __sleep()
5760
{
61+
trigger_error('Using PHP serialization is deprecated', E_USER_DEPRECATED);
62+
5863
$properties = parent::__sleep();
5964
return array_diff($properties, ['_resource', '_resourceCollection']);
6065
}
6166

6267
/**
63-
* {@inheritdoc}
68+
* @inheritDoc
69+
*
70+
* @SuppressWarnings(PHPMD.SerializationAware)
71+
* @deprecated Do not use PHP serialization.
6472
*/
6573
public function __wakeup()
6674
{
75+
trigger_error('Using PHP serialization is deprecated', E_USER_DEPRECATED);
76+
6777
parent::__wakeup();
6878
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
6979
$this->_resource = $objectManager->get(\Magento\Authorization\Model\ResourceModel\Role::class);

app/code/Magento/Backend/Model/Auth/Session.php

Lines changed: 193 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55
*/
66
namespace Magento\Backend\Model\Auth;
77

8+
use Magento\Framework\Acl;
9+
use Magento\Framework\AclFactory;
10+
use Magento\Framework\App\ObjectManager;
811
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
912
use Magento\Framework\Stdlib\CookieManagerInterface;
13+
use Magento\Backend\Spi\SessionUserHydratorInterface;
14+
use Magento\Backend\Spi\SessionAclHydratorInterface;
15+
use Magento\User\Model\User;
16+
use Magento\User\Model\UserFactory;
1017

1118
/**
1219
* Backend Auth session model
1320
*
1421
* @api
15-
* @method \Magento\User\Model\User|null getUser()
16-
* @method \Magento\Backend\Model\Auth\Session setUser(\Magento\User\Model\User $value)
17-
* @method \Magento\Framework\Acl|null getAcl()
18-
* @method \Magento\Backend\Model\Auth\Session setAcl(\Magento\Framework\Acl $value)
1922
* @method int getUpdatedAt()
2023
* @method \Magento\Backend\Model\Auth\Session setUpdatedAt(int $value)
2124
*
2225
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2327
* @todo implement solution that keeps is_first_visit flag in session during redirects
2428
* @api
2529
* @since 100.0.2
@@ -55,6 +59,36 @@ class Session extends \Magento\Framework\Session\SessionManager implements \Mage
5559
*/
5660
protected $_config;
5761

62+
/**
63+
* @var SessionUserHydratorInterface
64+
*/
65+
private $userHydrator;
66+
67+
/**
68+
* @var SessionAclHydratorInterface
69+
*/
70+
private $aclHydrator;
71+
72+
/**
73+
* @var UserFactory
74+
*/
75+
private $userFactory;
76+
77+
/**
78+
* @var AclFactory
79+
*/
80+
private $aclFactory;
81+
82+
/**
83+
* @var User|null
84+
*/
85+
private $user;
86+
87+
/**
88+
* @var Acl|null
89+
*/
90+
private $acl;
91+
5892
/**
5993
* @param \Magento\Framework\App\Request\Http $request
6094
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
@@ -69,6 +103,10 @@ class Session extends \Magento\Framework\Session\SessionManager implements \Mage
69103
* @param \Magento\Backend\Model\UrlInterface $backendUrl
70104
* @param \Magento\Backend\App\ConfigInterface $config
71105
* @throws \Magento\Framework\Exception\SessionException
106+
* @param SessionUserHydratorInterface|null $userHydrator
107+
* @param SessionAclHydratorInterface|null $aclHydrator
108+
* @param UserFactory|null $userFactory
109+
* @param AclFactory|null $aclFactory
72110
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
73111
*/
74112
public function __construct(
@@ -83,11 +121,19 @@ public function __construct(
83121
\Magento\Framework\App\State $appState,
84122
\Magento\Framework\Acl\Builder $aclBuilder,
85123
\Magento\Backend\Model\UrlInterface $backendUrl,
86-
\Magento\Backend\App\ConfigInterface $config
124+
\Magento\Backend\App\ConfigInterface $config,
125+
?SessionUserHydratorInterface $userHydrator = null,
126+
?SessionAclHydratorInterface $aclHydrator = null,
127+
?UserFactory $userFactory = null,
128+
?AclFactory $aclFactory = null
87129
) {
88130
$this->_config = $config;
89131
$this->_aclBuilder = $aclBuilder;
90132
$this->_backendUrl = $backendUrl;
133+
$this->userHydrator = $userHydrator ?? ObjectManager::getInstance()->get(SessionUserHydratorInterface::class);
134+
$this->aclHydrator = $aclHydrator ?? ObjectManager::getInstance()->get(SessionAclHydratorInterface::class);
135+
$this->userFactory = $userFactory ?? ObjectManager::getInstance()->get(UserFactory::class);
136+
$this->aclFactory = $aclFactory ?? ObjectManager::getInstance()->get(AclFactory::class);
91137
parent::__construct(
92138
$request,
93139
$sidResolver,
@@ -230,6 +276,16 @@ public function processLogin()
230276
return $this;
231277
}
232278

279+
/**
280+
* @inheritDoc
281+
*/
282+
public function destroy(array $options = null)
283+
{
284+
$this->user = null;
285+
$this->acl = null;
286+
parent::destroy($options);
287+
}
288+
233289
/**
234290
* Process of configuring of current auth storage when logout was performed
235291
*
@@ -253,4 +309,136 @@ public function isValidForPath($path)
253309
{
254310
return true;
255311
}
312+
313+
/**
314+
* Logged-in user.
315+
*
316+
* @return User|null
317+
*/
318+
public function getUser()
319+
{
320+
if (!$this->user) {
321+
$userData = $this->getUserData();
322+
if ($userData) {
323+
/** @var User $user */
324+
$user = $this->userFactory->create();
325+
$this->userHydrator->hydrate($user, $userData);
326+
$this->user = $user;
327+
}
328+
}
329+
330+
return $this->user;
331+
}
332+
333+
/**
334+
* Set logged-in user instance.
335+
*
336+
* @param User|null $user
337+
* @return Session
338+
*/
339+
public function setUser($user)
340+
{
341+
$this->setUserData(null);
342+
if ($user) {
343+
$this->setUserData($this->userHydrator->extract($user));
344+
}
345+
$this->user = $user;
346+
347+
return $this;
348+
}
349+
350+
/**
351+
* Is user logged in?
352+
*
353+
* @return bool
354+
*/
355+
public function hasUser()
356+
{
357+
return $this->user || $this->hasUserData();
358+
}
359+
360+
/**
361+
* Remove logged-in user.
362+
*
363+
* @return Session
364+
*/
365+
public function unsUser()
366+
{
367+
$this->user = null;
368+
return $this->unsUserData();
369+
}
370+
371+
/**
372+
* Logged-in user's ACL data.
373+
*
374+
* @return Acl|null
375+
*/
376+
public function getAcl()
377+
{
378+
if (!$this->acl) {
379+
$aclData = $this->getUserAclData();
380+
if ($aclData) {
381+
/** @var Acl $acl */
382+
$acl = $this->aclFactory->create();
383+
$this->aclHydrator->hydrate($acl, $aclData);
384+
$this->acl = $acl;
385+
}
386+
}
387+
388+
return $this->acl;
389+
}
390+
391+
/**
392+
* Set logged-in user's ACL data instance.
393+
*
394+
* @param Acl|null $acl
395+
* @return Session
396+
*/
397+
public function setAcl($acl)
398+
{
399+
$this->setUserAclData(null);
400+
if ($acl) {
401+
$this->setUserAclData($this->aclHydrator->extract($acl));
402+
}
403+
$this->acl = $acl;
404+
405+
return $this;
406+
}
407+
408+
/**
409+
* Whether ACL data is present.
410+
*
411+
* @return bool
412+
*/
413+
public function hasAcl()
414+
{
415+
return $this->acl || $this->hasUserAclData();
416+
}
417+
418+
/**
419+
* Remove ACL data.
420+
*
421+
* @return Session
422+
*/
423+
public function unsAcl()
424+
{
425+
$this->acl = null;
426+
return $this->unsUserAclData();
427+
}
428+
429+
/**
430+
* @inheritDoc
431+
*/
432+
public function writeClose()
433+
{
434+
//Updating data in session in case these objects has been changed.
435+
if ($this->user) {
436+
$this->setUser($this->user);
437+
}
438+
if ($this->acl) {
439+
$this->setAcl($this->acl);
440+
}
441+
442+
parent::writeClose();
443+
}
256444
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Backend\Model\Auth;
10+
11+
use Magento\Backend\Spi\SessionAclHydratorInterface;
12+
use Magento\Framework\Acl;
13+
14+
/**
15+
* @inheritDoc
16+
*/
17+
class SessionAclHydrator extends Acl implements SessionAclHydratorInterface
18+
{
19+
/**
20+
* @inheritDoc
21+
*/
22+
public function extract(Acl $acl): array
23+
{
24+
return ['rules' => $acl->_rules, 'resources' => $acl->_resources, 'roles' => $acl->_roleRegistry];
25+
}
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public function hydrate(Acl $target, array $data): void
31+
{
32+
$target->_rules = $data['rules'];
33+
$target->_resources = $data['resources'];
34+
$target->_roleRegistry = $data['roles'];
35+
}
36+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Backend\Model\Auth;
10+
11+
use Magento\Backend\Spi\SessionUserHydratorInterface;
12+
use Magento\User\Model\User;
13+
use Magento\Authorization\Model\Role;
14+
use Magento\Authorization\Model\RoleFactory;
15+
16+
/**
17+
* @inheritDoc
18+
*/
19+
class SessionUserHydrator implements SessionUserHydratorInterface
20+
{
21+
/**
22+
* @var RoleFactory
23+
*/
24+
private $roleFactory;
25+
26+
/**
27+
* @param RoleFactory $roleFactory
28+
*/
29+
public function __construct(RoleFactory $roleFactory)
30+
{
31+
$this->roleFactory = $roleFactory;
32+
}
33+
34+
/**
35+
* @inheritDoc
36+
*/
37+
public function extract(User $user): array
38+
{
39+
return ['data' => $user->getData(), 'role_data' => $user->getRole()->getData()];
40+
}
41+
42+
/**
43+
* @inheritDoc
44+
*/
45+
public function hydrate(User $target, array $data): void
46+
{
47+
$target->setData($data['data']);
48+
/** @var Role $role */
49+
$role = $this->roleFactory->create();
50+
$role->setData($data['role_data']);
51+
$target->setData('extracted_role', $role);
52+
$target->getRole();
53+
}
54+
}

0 commit comments

Comments
 (0)