Skip to content

Commit

Permalink
Merge pull request #96 from magento-south/MAGETWO-30789
Browse files Browse the repository at this point in the history
[South] Sprint 30
  • Loading branch information
slavvka committed Feb 17, 2015
2 parents f2361bd + cd69470 commit 3941c63
Show file tree
Hide file tree
Showing 263 changed files with 5,121 additions and 1,258 deletions.
63 changes: 0 additions & 63 deletions app/code/Magento/Backend/Model/View.php

This file was deleted.

30 changes: 0 additions & 30 deletions app/code/Magento/Backend/Model/View/Layout/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,6 @@

class Builder extends \Magento\Framework\View\Layout\Builder
{
/**
* @var Filter\Acl
*/
protected $aclFilter;

/**
* @param View\LayoutInterface $layout
* @param App\Request\Http $request
* @param Event\ManagerInterface $eventManager
* @param Filter\Acl $aclFilter
*/
public function __construct(
View\LayoutInterface $layout,
App\Request\Http $request,
Event\ManagerInterface $eventManager,
Filter\Acl $aclFilter
) {
parent::__construct($layout, $request, $eventManager);
$this->aclFilter = $aclFilter;
}

/**
* @return $this
*/
protected function beforeGenerateBlock()
{
$this->aclFilter->filterAclNodes($this->layout->getNode());
return $this;
}

/**
* @return $this
*/
Expand Down
53 changes: 41 additions & 12 deletions app/code/Magento/Backend/Model/View/Layout/Filter/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,68 @@
*/
namespace Magento\Backend\Model\View\Layout\Filter;

use Magento\Framework\View\Layout\ScheduledStructure;
use Magento\Framework\View\Layout\Data\Structure;

class Acl
{
/**
* Authorization
*
* @var \Magento\Framework\AuthorizationInterface
*/
protected $_authorization;
protected $authorization;

/**
* @param \Magento\Framework\AuthorizationInterface $authorization
*/
public function __construct(\Magento\Framework\AuthorizationInterface $authorization)
{
$this->_authorization = $authorization;
$this->authorization = $authorization;
}

/**
* Delete nodes that have "acl" attribute but value is "not allowed"
* Delete elements that have "acl" attribute but value is "not allowed"
* In any case, the "acl" attribute will be unset
*
* @param \Magento\Framework\Simplexml\Element $xml
* @return void
* @param ScheduledStructure $scheduledStructure
* @param Structure $structure
*/
public function filterAclNodes(\Magento\Framework\Simplexml\Element $xml)
public function filterAclElements(ScheduledStructure $scheduledStructure, Structure $structure)
{
$limitations = $xml->xpath('//*[@acl]') ?: [];
foreach ($limitations as $node) {
if (!$this->_authorization->isAllowed($node['acl'])) {
$node->unsetSelf();
} else {
unset($node['acl']);
foreach ($scheduledStructure->getElements() as $name => $data) {
list(, $data) = $data;
if (isset($data['attributes']['acl']) && $data['attributes']['acl']) {
if (!$this->authorization->isAllowed($data['attributes']['acl'])) {
$this->removeElement($scheduledStructure, $structure, $name);
}
}
}
}

/**
* Remove scheduled element
*
* @param ScheduledStructure $scheduledStructure
* @param Structure $structure
* @param string $elementName
* @param bool $isChild
* @return $this
*/
protected function removeElement(
ScheduledStructure $scheduledStructure,
Structure $structure,
$elementName,
$isChild = false
) {
$elementsToRemove = array_keys($structure->getChildren($elementName));
$scheduledStructure->unsetElement($elementName);
foreach ($elementsToRemove as $element) {
$this->removeElement($scheduledStructure, $structure, $element, true);
}
if (!$isChild) {
$structure->unsetElement($elementName);
}
return $this;
}
}
57 changes: 57 additions & 0 deletions app/code/Magento/Backend/Model/View/Layout/GeneratorPool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Model\View\Layout;

use Magento\Framework\View\Layout\ScheduledStructure;
use Magento\Framework\View\Layout\Data\Structure;

/**
* Pool of generators for structural elements
*/
class GeneratorPool extends \Magento\Framework\View\Layout\GeneratorPool
{
/**
* @var Filter\Acl
*/
protected $aclFilter;

/**
* @param ScheduledStructure\Helper $helper
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver
* @param Filter\Acl $aclFilter
* @param array $generators
*/
public function __construct(
ScheduledStructure\Helper $helper,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\App\ScopeResolverInterface $scopeResolver,
Filter\Acl $aclFilter,
array $generators = null
) {
$this->aclFilter = $aclFilter;
parent::__construct(
$helper,
$scopeConfig,
$scopeResolver,
$generators
);
}

/**
* Build structure that is based on scheduled structure
*
* @param ScheduledStructure $scheduledStructure
* @param Structure $structure
* @return $this
*/
protected function buildStructure(ScheduledStructure $scheduledStructure, Structure $structure)
{
parent::buildStructure($scheduledStructure, $structure);
$this->aclFilter->filterAclElements($scheduledStructure, $structure);
return $this;
}
}
32 changes: 32 additions & 0 deletions app/code/Magento/Backend/Model/View/Layout/Reader/Block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Model\View\Layout\Reader;

use Magento\Framework\View\Layout;
use Magento\Framework\Data\Argument\InterpreterInterface;

/**
* Backend block structure reader with ACL support
*/
class Block extends Layout\Reader\Block
{
public function __construct(
Layout\ScheduledStructure\Helper $helper,
Layout\Argument\Parser $argumentParser,
Layout\ReaderPool $readerPool,
InterpreterInterface $argumentInterpreter,
$scopeType = null
) {
$this->attributes[] = 'acl';
parent::__construct(
$helper,
$argumentParser,
$readerPool,
$argumentInterpreter,
$scopeType
);
}
}
34 changes: 0 additions & 34 deletions app/code/Magento/Backend/Model/View/Page/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,6 @@

class Builder extends View\Page\Builder
{
/**
* @var Layout\Filter\Acl $aclFilter
*/
protected $aclFilter;

/**
* @param View\LayoutInterface $layout
* @param App\Request\Http $request
* @param Event\ManagerInterface $eventManager
* @param View\Page\Config $pageConfig
* @param View\Page\Layout\Reader $pageLayoutReader
* @param Layout\Filter\Acl $aclFilter
*/
public function __construct(
View\LayoutInterface $layout,
App\Request\Http $request,
Event\ManagerInterface $eventManager,
View\Page\Config $pageConfig,
View\Page\Layout\Reader $pageLayoutReader,
Layout\Filter\Acl $aclFilter
) {
parent::__construct($layout, $request, $eventManager, $pageConfig, $pageLayoutReader);
$this->aclFilter = $aclFilter;
}

/**
* @return $this
*/
protected function beforeGenerateBlock()
{
$this->aclFilter->filterAclNodes($this->layout->getNode());
return $this;
}

/**
* @return $this
*/
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<preference for="Magento\Framework\App\DefaultPathInterface" type="Magento\Backend\App\DefaultPath" />
<preference for="Magento\Backend\App\ConfigInterface" type="Magento\Backend\App\Config" />
<preference for="Magento\Framework\App\Response\Http\FileFactory" type="Magento\Backend\App\Response\Http\FileFactory" />
<preference for="Magento\Framework\App\View" type="Magento\Backend\Model\View" />
<preference for="Magento\Framework\View\Layout\GeneratorPool" type="Magento\Backend\Model\View\Layout\GeneratorPool" />
<preference for="pageLayoutGeneratorPool" type="Magento\Backend\Model\View\Layout\GeneratorPool" />
<preference for="Magento\Framework\View\Layout\Reader\Block" type="Magento\Backend\Model\View\Layout\Reader\Block" />
<preference for="Magento\Framework\Model\ActionValidator\RemoveAction" type="Magento\Framework\Model\ActionValidator\RemoveAction\Allowed" />
<preference for="Magento\Framework\Session\Config\ConfigInterface" type="Magento\Backend\Model\Session\AdminConfig" />
<type name="Magento\Backend\App\Action\Context">
Expand Down
9 changes: 4 additions & 5 deletions app/code/Magento/Theme/Model/CopyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,10 @@ protected function _copyFilesRecursively($baseDir, $sourceDir, $targetDir)
*/
protected function _deleteFilesRecursively($targetDir)
{
if (!$this->_directory->isExist($targetDir)) {
return;
}
foreach ($this->_directory->read($targetDir) as $path) {
$this->_directory->delete($path);
if ($this->_directory->isExist($targetDir)) {
foreach ($this->_directory->read($targetDir) as $path) {
$this->_directory->delete($path);
}
}
}
}
Loading

0 comments on commit 3941c63

Please sign in to comment.