Skip to content

Commit b8490f9

Browse files
author
Alex Paliarush
committed
MAGETWO-69015: Cannot login as admin user with limited user role
- Ported MAGETWO-62648 from 2.1
1 parent 00f964d commit b8490f9

File tree

4 files changed

+114
-5
lines changed

4 files changed

+114
-5
lines changed

app/code/Magento/Store/Model/Config/Processor/Fallback.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,17 @@ private function prepareStoresConfig(
161161
}
162162

163163
/**
164-
* Retrieve Website Config
164+
* Find information about website by its ID.
165165
*
166-
* @param array $websites
166+
* @param array $websites Has next format: (website_code => [website_data])
167167
* @param int $id
168168
* @return array
169169
*/
170170
private function getWebsiteConfig(array $websites, $id)
171171
{
172172
foreach ((array)$this->websiteData as $website) {
173173
if ($website['website_id'] == $id) {
174-
$code = $website['website_id'];
174+
$code = $website['code'];
175175
return isset($websites[$code]) ? $websites[$code] : [];
176176
}
177177
}

app/code/Magento/Store/Model/ResourceModel/Website.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,25 @@ protected function _initUniqueFields()
3737
}
3838

3939
/**
40-
* Read information about all websites
40+
* Read all information about websites.
41+
*
42+
* Convert information to next format:
43+
* [website_code => [website_data (website_id, code, name, etc...)]]
4144
*
4245
* @return array
4346
*/
4447
public function readAllWebsites()
4548
{
49+
$websites = [];
4650
$select = $this->getConnection()
4751
->select()
4852
->from($this->getTable('store_website'));
4953

50-
return $this->getConnection()->fetchAll($select);
54+
foreach($this->getConnection()->fetchAll($select) as $websiteData) {
55+
$websites[$websiteData['code']] = $websiteData;
56+
}
57+
58+
return $websites;
5159
}
5260

5361
/**
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Review\Block;
8+
9+
use Magento\Framework\App\Area;
10+
use Magento\Framework\App\Config\Value;
11+
use Magento\Framework\App\ReinitableConfig;
12+
use Magento\Framework\App\State;
13+
use Magento\TestFramework\ObjectManager;
14+
15+
class FormTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var ObjectManager;
19+
*/
20+
private $objectManager;
21+
22+
protected function setUp()
23+
{
24+
$this->objectManager = $this->getObjectManager();
25+
26+
parent::setUp();
27+
}
28+
29+
/**
30+
* @magentoDbIsolation enabled
31+
* @magentoDataFixture Magento/Review/_files/config.php
32+
* @dataProvider getCorrectFlagDataProvider
33+
*/
34+
public function testGetCorrectFlag(
35+
$path,
36+
$scope,
37+
$scopeId,
38+
$value,
39+
$expectedResult
40+
) {
41+
/** @var State $appState */
42+
$appState = $this->objectManager->get(State::class);
43+
$appState->setAreaCode(Area::AREA_FRONTEND);
44+
45+
/** @var Value $config */
46+
$config = $this->objectManager->create(Value::class);
47+
$config->setPath($path);
48+
$config->setScope($scope);
49+
$config->setScopeId($scopeId);
50+
$config->setValue($value);
51+
$config->save();
52+
/** @var ReinitableConfig $reinitableConfig */
53+
$reinitableConfig = $this->objectManager->create(ReinitableConfig::class);
54+
$reinitableConfig->reinit();
55+
56+
/** @var \Magento\Review\Block\Form $form */
57+
$form = $this->objectManager->create(\Magento\Review\Block\Form::class);
58+
$result = $form->getAllowWriteReviewFlag();
59+
$this->assertEquals($result, $expectedResult);
60+
}
61+
62+
public function getCorrectFlagDataProvider()
63+
{
64+
return [
65+
[
66+
'path' => 'catalog/review/allow_guest',
67+
'scope' => 'websites',
68+
'scopeId' => '1',
69+
'value' => 0,
70+
'expectedResult' => false,
71+
],
72+
[
73+
'path' => 'catalog/review/allow_guest',
74+
'scope' => 'websites',
75+
'scopeId' => '1',
76+
'value' => 1,
77+
'expectedResult' => true
78+
]
79+
];
80+
}
81+
82+
private function getObjectManager()
83+
{
84+
return \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
85+
}
86+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var Value $config */
8+
use Magento\Framework\App\Config\Value;
9+
10+
$config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(Value::class);
11+
$config->setPath('catalog/review/allow_guest');
12+
$config->setScope('default');
13+
$config->setScopeId(0);
14+
$config->setValue(1);
15+
$config->save();

0 commit comments

Comments
 (0)