Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop' into MAGETWO-56012
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Kovalenko committed Aug 22, 2016
2 parents f47d494 + 5a615bb commit 5354548
Show file tree
Hide file tree
Showing 24 changed files with 241 additions and 117 deletions.
3 changes: 2 additions & 1 deletion app/code/Magento/Backend/Model/View/Result/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Backend\Model\UrlInterface;
use Magento\Framework\App;
use Magento\Framework\App\ActionFlag;
use Magento\Framework\App\Response\HttpInterface as HttpResponseInterface;

class Redirect extends \Magento\Framework\Controller\Result\Redirect
{
Expand Down Expand Up @@ -56,7 +57,7 @@ public function setRefererOrBaseUrl()
/**
* {@inheritdoc}
*/
protected function render(App\ResponseInterface $response)
protected function render(HttpResponseInterface $response)
{
$this->session->setIsUrlNotice($this->actionFlag->get('', AbstractAction::FLAG_IS_URLS_CHECKED));
return parent::render($response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ private function processRangeNumeric(FilterInterface $filter, $query, $attribute
$tableSuffix = $attribute->getBackendType() === 'decimal' ? '_decimal' : '';
$table = $this->resource->getTableName("catalog_product_index_eav{$tableSuffix}");
$select = $this->connection->select();
$linkIdField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
$entityField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getIdentifierField();

$currentStoreId = $this->scopeResolver->getScope()->getId();

$select->from(['e' => $this->resource->getTableName('catalog_product_entity')], ['entity_id'])
->join(
['main_table' => $table],
"main_table.{$linkIdField} = e.{$linkIdField}",
"main_table.{$entityField} = e.{$entityField}",
[]
)
->columns([$filter->getField() => 'main_table.value'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ public function isEverythingAllowed()
*/
public function getResourcesTreeJson()
{
$resources = $this->_resourceProvider->getAclResources();
$aclResourcesTree = $this->_integrationData->mapResources($resources[1]['children']);
$aclResourcesTree = $this->_integrationData->mapResources($this->getAclResources());

return $this->encoder->encode($aclResourcesTree);
}
Expand All @@ -166,12 +165,29 @@ public function getSelectedResourcesJson()
{
$selectedResources = $this->_selectedResources;
if ($this->isEverythingAllowed()) {
$resources = $this->_resourceProvider->getAclResources();
$selectedResources = $this->_getAllResourceIds($resources[1]['children']);
$selectedResources = $this->_getAllResourceIds($this->getAclResources());
}
return $this->encoder->encode($selectedResources);
}

/**
* Get lit of all ACL resources declared in the system.
*
* @return array
*/
private function getAclResources()
{
$resources = $this->_resourceProvider->getAclResources();
$configResource = array_filter(
$resources,
function ($node) {
return $node['id'] == 'Magento_Backend::admin';
}
);
$configResource = reset($configResource);
return isset($configResource['children']) ? $configResource['children'] : [];
}

/**
* Whether tree has any resources.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Magento\Integration\Block\Adminhtml\Integration\Edit\Tab;

use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info;
use Magento\Integration\Controller\Adminhtml\Integration as IntegrationController;
use Magento\Integration\Model\Integration as IntegrationModel;

Expand Down Expand Up @@ -174,11 +173,25 @@ public function isEverythingAllowed()
* @return array
*/
public function getTree()
{
return $this->integrationData->mapResources($this->getAclResources());
}

/**
* Get lit of all ACL resources declared in the system.
*
* @return array
*/
private function getAclResources()
{
$resources = $this->aclResourceProvider->getAclResources();
$rootArray = $this->integrationData->mapResources(
isset($resources[1]['children']) ? $resources[1]['children'] : []
$configResource = array_filter(
$resources,
function ($node) {
return $node['id'] == 'Magento_Backend::admin';
}
);
return $rootArray;
$configResource = reset($configResource);
return isset($configResource['children']) ? $configResource['children'] : [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,16 @@ public function testGetTree()
{
$this->webapiBlock = $this->getWebapiBlock();
$resources = [
1 => [ 'children' => [1, 2, 3] ]
['id' => 'Magento_Backend::admin', 'children' => ['resource1', 'resource2', 'resource3']],
['id' => 'Invalid_Node', 'children' => ['resource4', 'resource5', 'resource6']]
];
$this->aclResourceProvider->expects($this->once())
->method('getAclResources')
->will($this->returnValue($resources));
$rootArray = "rootArrayValue";
$this->integrationHelper->expects($this->once())
->method('mapResources')
->with([1, 2, 3])
->with(['resource1', 'resource2', 'resource3'])
->will($this->returnValue($rootArray));
$this->assertEquals($rootArray, $this->webapiBlock->getTree());
}
Expand Down Expand Up @@ -197,7 +198,7 @@ public function isEverythingAllowedWithSavedFromDataProvider()
return [
'root resource in array' => [
2,
['all_resources' => 0, 'resource'=>[2, 3]],
['all_resources' => 0, 'resource' => [2, 3]],
true
],
'root resource not in array' => [
Expand Down
23 changes: 17 additions & 6 deletions app/code/Magento/User/Block/Role/Tab/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Magento\User\Block\Role\Tab;

use Magento\Framework\App\ObjectManager;
use Magento\User\Controller\Adminhtml\User\Role\SaveRole;

/**
Expand Down Expand Up @@ -93,7 +92,6 @@ public function __construct(
*/
public function setCoreRegistry(\Magento\Framework\Registry $coreRegistry)
{

$this->coreRegistry = $coreRegistry;
}

Expand All @@ -105,7 +103,6 @@ public function setCoreRegistry(\Magento\Framework\Registry $coreRegistry)
*/
public function getCoreRegistry()
{

if (!($this->coreRegistry instanceof \Magento\Framework\Registry)) {
return \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Registry::class);
} else {
Expand Down Expand Up @@ -197,11 +194,25 @@ public function getSelectedResources()
* @return array
*/
public function getTree()
{
return $this->_integrationData->mapResources($this->getAclResources());
}

/**
* Get lit of all ACL resources declared in the system.
*
* @return array
*/
private function getAclResources()
{
$resources = $this->_aclResourceProvider->getAclResources();
$rootArray = $this->_integrationData->mapResources(
isset($resources[1]['children']) ? $resources[1]['children'] : []
$configResource = array_filter(
$resources,
function ($node) {
return $node['id'] == 'Magento_Backend::admin';
}
);
return $rootArray;
$configResource = reset($configResource);
return isset($configResource['children']) ? $configResource['children'] : [];
}
}
10 changes: 5 additions & 5 deletions app/code/Magento/User/Block/User/Edit/Tab/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ public function getSelectedRoles($json = false)
//checking if we have this data and we
//don't need load it through resource model
if ($user->hasData('roles')) {
$uRoles = $user->getData('roles');
$userRoles = $user->getData('roles');
} else {
$uRoles = $user->getRoles();
$userRoles = $user->getRoles();
}

if ($json) {
$jsonRoles = [];
foreach ($uRoles as $urid) {
$jsonRoles[$urid] = 0;
foreach ($userRoles as $roleId) {
$jsonRoles[$roleId] = 0;
}
return $this->_jsonEncoder->encode((object)$jsonRoles);
} else {
return $uRoles;
return $userRoles;
}
}
}
6 changes: 3 additions & 3 deletions app/code/Magento/User/Controller/Adminhtml/User/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public function execute()
return;
}
$model->setData($this->_getAdminUserData($data));
$uRoles = $this->getRequest()->getParam('roles', []);
if (count($uRoles)) {
$model->setRoleId($uRoles[0]);
$userRoles = $this->getRequest()->getParam('roles', []);
if (count($userRoles)) {
$model->setRoleId($userRoles[0]);
}

/** @var $currentUser \Magento\User\Model\User */
Expand Down
5 changes: 4 additions & 1 deletion app/code/Magento/User/Test/Unit/Block/Role/Tab/EditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ protected function setUp()

public function testGetTree()
{
$resources = ['resource1', 'resource2', 'resource3'];
$resources = [
['id' => 'Magento_Backend::admin', 'children' => ['resource1', 'resource2', 'resource3']],
['id' => 'Invalid_Node', 'children' => ['resource4', 'resource5', 'resource6']]
];
$mappedResources = ['mapped1', 'mapped2', 'mapped3'];
$this->aclResourceProviderMock->expects($this->once())->method('getAclResources')->willReturn($resources);
$this->integrationDataMock->expects($this->once())->method('mapResources')->willReturn($mappedResources);
Expand Down
8 changes: 8 additions & 0 deletions auth.json.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"http-basic": {
"repo.magento.com": {
"username": "<public-key>",
"password": "<private-key>"
}
}
}
84 changes: 84 additions & 0 deletions lib/internal/Magento/Framework/App/Response/HttpInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,88 @@ interface HttpInterface extends \Magento\Framework\App\ResponseInterface
* @return void
*/
public function setHttpResponseCode($code);

/**
* Get HTTP response code
*
* @return int
*/
public function getHttpResponseCode();

/**
* Set a header
*
* If $replace is true, replaces any headers already defined with that $name.
*
* @param string $name
* @param string $value
* @param boolean $replace
* @return self
*/
public function setHeader($name, $value, $replace = false);

/**
* Get header value by name
*
* Returns first found header by passed name.
* If header with specified name was not found returns false.
*
* @param string $name
* @return \Zend\Http\Header\HeaderInterface|bool
*/
public function getHeader($name);

/**
* Remove header by name from header stack
*
* @param string $name
* @return self
*/
public function clearHeader($name);

/**
* Allow granular setting of HTTP response status code, version and phrase
*
* For example, a HTTP response as the following:
* HTTP 200 1.1 Your response has been served
* Can be set with the arguments
* $httpCode = 200
* $version = 1.1
* $phrase = 'Your response has been served'
*
* @param int|string $httpCode
* @param null|int|string $version
* @param null|string $phrase
* @return self
*/
public function setStatusHeader($httpCode, $version = null, $phrase = null);

/**
* Append the given string to the response body
*
* @param string $value
* @return self
*/
public function appendBody($value);

/**
* Set the response body to the given value
*
* Any previously set contents will be replaced by the new content.
*
* @param string $value
* @return self
*/
public function setBody($value);

/**
* Set redirect URL
*
* Sets Location header and response code. Forces replacement of any prior redirects.
*
* @param string $url
* @param int $code
* @return self
*/
public function setRedirect($url, $code = 302);
}
13 changes: 7 additions & 6 deletions lib/internal/Magento/Framework/Controller/AbstractResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\Framework\Controller;

use Magento\Framework\App\ResponseInterface;
use Magento\Framework\App\Response\HttpInterface as HttpResponseInterface;

abstract class AbstractResult implements ResultInterface
{
Expand Down Expand Up @@ -83,10 +84,10 @@ public function setStatusHeader($httpCode, $version = null, $phrase = null)
}

/**
* @param ResponseInterface $response
* @param HttpResponseInterface $response
* @return $this
*/
protected function applyHttpHeaders(ResponseInterface $response)
protected function applyHttpHeaders(HttpResponseInterface $response)
{
if (!empty($this->httpResponseCode)) {
$response->setHttpResponseCode($this->httpResponseCode);
Expand All @@ -105,17 +106,17 @@ protected function applyHttpHeaders(ResponseInterface $response)
}
return $this;
}

/**
* @param ResponseInterface $response
* @param HttpResponseInterface $response
* @return $this
*/
abstract protected function render(ResponseInterface $response);
abstract protected function render(HttpResponseInterface $response);

/**
* Render content
*
* @param ResponseInterface $response
* @param HttpResponseInterface|ResponseInterface $response
* @return $this
*/
public function renderResult(ResponseInterface $response)
Expand Down
Loading

0 comments on commit 5354548

Please sign in to comment.