Skip to content

Commit

Permalink
Merge branch '2.3-qwerty' of github.com:magento/magento2ce into MC-13900
Browse files Browse the repository at this point in the history
  • Loading branch information
anthoula committed May 2, 2019
2 parents 07fa87a + ad2d25c commit a3b03ed
Show file tree
Hide file tree
Showing 363 changed files with 7,511 additions and 2,959 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<block class="Magento\Backend\Block\Widget\Grid" name="adminhtml.notification.container.grid" as="grid">
<arguments>
<argument name="id" xsi:type="string">notificationGrid</argument>
<argument name="dataSource" xsi:type="object">Magento\AdminNotification\Model\ResourceModel\Grid\Collection</argument>
<argument name="dataSource" xsi:type="object" shared="false">Magento\AdminNotification\Model\ResourceModel\Grid\Collection</argument>
<argument name="default_dir" xsi:type="string">DESC</argument>
<argument name="default_sort" xsi:type="string">date_added</argument>
<argument name="save_parameters_in_session" xsi:type="string">1</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<block class="Magento\AdvancedSearch\Block\Adminhtml\Search\Grid" name="search.edit.grid" as="grid">
<arguments>
<argument name="id" xsi:type="string">catalog_search_grid</argument>
<argument name="dataSource" xsi:type="object">Magento\AdvancedSearch\Model\ResourceModel\Search\Grid\Collection</argument>
<argument name="dataSource" xsi:type="object" shared="false">Magento\AdvancedSearch\Model\ResourceModel\Search\Grid\Collection</argument>
<argument name="default_sort" xsi:type="string">name</argument>
<argument name="default_dir" xsi:type="string">ASC</argument>
<argument name="save_parameters_in_session" xsi:type="string">1</argument>
Expand Down
14 changes: 12 additions & 2 deletions app/code/Magento/Authorization/Model/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,29 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritDoc
*
* @SuppressWarnings(PHPMD.SerializationAware)
* @deprecated Do not use PHP serialization.
*/
public function __sleep()
{
trigger_error('Using PHP serialization is deprecated', E_USER_DEPRECATED);

$properties = parent::__sleep();
return array_diff($properties, ['_resource', '_resourceCollection']);
}

/**
* {@inheritdoc}
* @inheritDoc
*
* @SuppressWarnings(PHPMD.SerializationAware)
* @deprecated Do not use PHP serialization.
*/
public function __wakeup()
{
trigger_error('Using PHP serialization is deprecated', E_USER_DEPRECATED);

parent::__wakeup();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$this->_resource = $objectManager->get(\Magento\Authorization\Model\ResourceModel\Role::class);
Expand Down
198 changes: 193 additions & 5 deletions app/code/Magento/Backend/Model/Auth/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
*/
namespace Magento\Backend\Model\Auth;

use Magento\Framework\Acl;
use Magento\Framework\AclFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Backend\Spi\SessionUserHydratorInterface;
use Magento\Backend\Spi\SessionAclHydratorInterface;
use Magento\User\Model\User;
use Magento\User\Model\UserFactory;

/**
* Backend Auth session model
*
* @api
* @method \Magento\User\Model\User|null getUser()
* @method \Magento\Backend\Model\Auth\Session setUser(\Magento\User\Model\User $value)
* @method \Magento\Framework\Acl|null getAcl()
* @method \Magento\Backend\Model\Auth\Session setAcl(\Magento\Framework\Acl $value)
* @method int getUpdatedAt()
* @method \Magento\Backend\Model\Auth\Session setUpdatedAt(int $value)
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
* @todo implement solution that keeps is_first_visit flag in session during redirects
* @api
* @since 100.0.2
Expand Down Expand Up @@ -55,6 +59,36 @@ class Session extends \Magento\Framework\Session\SessionManager implements \Mage
*/
protected $_config;

/**
* @var SessionUserHydratorInterface
*/
private $userHydrator;

/**
* @var SessionAclHydratorInterface
*/
private $aclHydrator;

/**
* @var UserFactory
*/
private $userFactory;

/**
* @var AclFactory
*/
private $aclFactory;

/**
* @var User|null
*/
private $user;

/**
* @var Acl|null
*/
private $acl;

/**
* @param \Magento\Framework\App\Request\Http $request
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
Expand All @@ -69,6 +103,10 @@ class Session extends \Magento\Framework\Session\SessionManager implements \Mage
* @param \Magento\Backend\Model\UrlInterface $backendUrl
* @param \Magento\Backend\App\ConfigInterface $config
* @throws \Magento\Framework\Exception\SessionException
* @param SessionUserHydratorInterface|null $userHydrator
* @param SessionAclHydratorInterface|null $aclHydrator
* @param UserFactory|null $userFactory
* @param AclFactory|null $aclFactory
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -83,11 +121,19 @@ public function __construct(
\Magento\Framework\App\State $appState,
\Magento\Framework\Acl\Builder $aclBuilder,
\Magento\Backend\Model\UrlInterface $backendUrl,
\Magento\Backend\App\ConfigInterface $config
\Magento\Backend\App\ConfigInterface $config,
?SessionUserHydratorInterface $userHydrator = null,
?SessionAclHydratorInterface $aclHydrator = null,
?UserFactory $userFactory = null,
?AclFactory $aclFactory = null
) {
$this->_config = $config;
$this->_aclBuilder = $aclBuilder;
$this->_backendUrl = $backendUrl;
$this->userHydrator = $userHydrator ?? ObjectManager::getInstance()->get(SessionUserHydratorInterface::class);
$this->aclHydrator = $aclHydrator ?? ObjectManager::getInstance()->get(SessionAclHydratorInterface::class);
$this->userFactory = $userFactory ?? ObjectManager::getInstance()->get(UserFactory::class);
$this->aclFactory = $aclFactory ?? ObjectManager::getInstance()->get(AclFactory::class);
parent::__construct(
$request,
$sidResolver,
Expand Down Expand Up @@ -230,6 +276,16 @@ public function processLogin()
return $this;
}

/**
* @inheritDoc
*/
public function destroy(array $options = null)
{
$this->user = null;
$this->acl = null;
parent::destroy($options);
}

/**
* Process of configuring of current auth storage when logout was performed
*
Expand All @@ -253,4 +309,136 @@ public function isValidForPath($path)
{
return true;
}

/**
* Logged-in user.
*
* @return User|null
*/
public function getUser()
{
if (!$this->user) {
$userData = $this->getUserData();
if ($userData) {
/** @var User $user */
$user = $this->userFactory->create();
$this->userHydrator->hydrate($user, $userData);
$this->user = $user;
}
}

return $this->user;
}

/**
* Set logged-in user instance.
*
* @param User|null $user
* @return Session
*/
public function setUser($user)
{
$this->setUserData(null);
if ($user) {
$this->setUserData($this->userHydrator->extract($user));
}
$this->user = $user;

return $this;
}

/**
* Is user logged in?
*
* @return bool
*/
public function hasUser()
{
return $this->user || $this->hasUserData();
}

/**
* Remove logged-in user.
*
* @return Session
*/
public function unsUser()
{
$this->user = null;
return $this->unsUserData();
}

/**
* Logged-in user's ACL data.
*
* @return Acl|null
*/
public function getAcl()
{
if (!$this->acl) {
$aclData = $this->getUserAclData();
if ($aclData) {
/** @var Acl $acl */
$acl = $this->aclFactory->create();
$this->aclHydrator->hydrate($acl, $aclData);
$this->acl = $acl;
}
}

return $this->acl;
}

/**
* Set logged-in user's ACL data instance.
*
* @param Acl|null $acl
* @return Session
*/
public function setAcl($acl)
{
$this->setUserAclData(null);
if ($acl) {
$this->setUserAclData($this->aclHydrator->extract($acl));
}
$this->acl = $acl;

return $this;
}

/**
* Whether ACL data is present.
*
* @return bool
*/
public function hasAcl()
{
return $this->acl || $this->hasUserAclData();
}

/**
* Remove ACL data.
*
* @return Session
*/
public function unsAcl()
{
$this->acl = null;
return $this->unsUserAclData();
}

/**
* @inheritDoc
*/
public function writeClose()
{
//Updating data in session in case these objects has been changed.
if ($this->user) {
$this->setUser($this->user);
}
if ($this->acl) {
$this->setAcl($this->acl);
}

parent::writeClose();
}
}
36 changes: 36 additions & 0 deletions app/code/Magento/Backend/Model/Auth/SessionAclHydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Backend\Model\Auth;

use Magento\Backend\Spi\SessionAclHydratorInterface;
use Magento\Framework\Acl;

/**
* @inheritDoc
*/
class SessionAclHydrator extends Acl implements SessionAclHydratorInterface
{
/**
* @inheritDoc
*/
public function extract(Acl $acl): array
{
return ['rules' => $acl->_rules, 'resources' => $acl->_resources, 'roles' => $acl->_roleRegistry];
}

/**
* @inheritDoc
*/
public function hydrate(Acl $target, array $data): void
{
$target->_rules = $data['rules'];
$target->_resources = $data['resources'];
$target->_roleRegistry = $data['roles'];
}
}
54 changes: 54 additions & 0 deletions app/code/Magento/Backend/Model/Auth/SessionUserHydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Backend\Model\Auth;

use Magento\Backend\Spi\SessionUserHydratorInterface;
use Magento\User\Model\User;
use Magento\Authorization\Model\Role;
use Magento\Authorization\Model\RoleFactory;

/**
* @inheritDoc
*/
class SessionUserHydrator implements SessionUserHydratorInterface
{
/**
* @var RoleFactory
*/
private $roleFactory;

/**
* @param RoleFactory $roleFactory
*/
public function __construct(RoleFactory $roleFactory)
{
$this->roleFactory = $roleFactory;
}

/**
* @inheritDoc
*/
public function extract(User $user): array
{
return ['data' => $user->getData(), 'role_data' => $user->getRole()->getData()];
}

/**
* @inheritDoc
*/
public function hydrate(User $target, array $data): void
{
$target->setData($data['data']);
/** @var Role $role */
$role = $this->roleFactory->create();
$role->setData($data['role_data']);
$target->setData('extracted_role', $role);
$target->getRole();
}
}
Loading

0 comments on commit a3b03ed

Please sign in to comment.