Skip to content

Commit 7a6e341

Browse files
authored
Merge pull request #1301 from magento-troll/pr_six_jul
[Troll] BugFix
2 parents d15daf2 + 037f959 commit 7a6e341

File tree

10 files changed

+144
-20
lines changed

10 files changed

+144
-20
lines changed

app/code/Magento/Catalog/view/adminhtml/templates/catalog/wysiwyg/js.phtml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,21 @@ var catalogWysiwygEditor = {
6969
$(elementId + '_editor').value = $(elementId).value;
7070
},
7171
okDialogWindow : function(dialogWindow) {
72-
if (dialogWindow.options.firedElementId) {
73-
wysiwygObj = eval('wysiwyg'+dialogWindow.options.firedElementId+'_editor');
72+
var $firedElement = jQuery('#' + dialogWindow.options.firedElementId),
73+
$editorElement = jQuery('#' + dialogWindow.options.firedElementId + '_editor'),
74+
firedElementId = $firedElement.attr('id'),
75+
wysiwygObj = window['wysiwyg' + firedElementId + '_editor'];
76+
77+
if ($firedElement.length) {
7478
wysiwygObj.turnOff();
7579
if (tinyMCE.get(wysiwygObj.id)) {
76-
$(dialogWindow.options.firedElementId).value = tinyMCE.get(wysiwygObj.id).getContent();
80+
$firedElement.val(tinyMCE.get(wysiwygObj.id).getContent()).change();
7781
} else {
78-
if ($(dialogWindow.options.firedElementId+'_editor')) {
79-
$(dialogWindow.options.firedElementId).value = $(dialogWindow.options.firedElementId+'_editor').value;
80-
}
82+
$firedElement.val($editorElement.val()).change();
83+
}
84+
if (tinyMCE.get(firedElementId)) {
85+
tinyMCE.get(firedElementId).load();
8186
}
82-
tinyMCE.editors[dialogWindow.options.firedElementId].load();
8387
if (typeof varienGlobalEvents != undefined) {
8488
varienGlobalEvents.fireEvent('tinymceChange');
8589
}

app/code/Magento/Config/Controller/Adminhtml/System/AbstractConfig.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Magento\Config\Controller\Adminhtml\System;
88

9-
use Magento\Config\Controller\Adminhtml\System\ConfigSectionChecker;
9+
use Magento\Framework\Exception\LocalizedException;
1010

1111
/**
1212
* System Configuration Abstract Controller
@@ -27,19 +27,19 @@ abstract class AbstractConfig extends \Magento\Backend\App\AbstractAction
2727
protected $_configStructure;
2828

2929
/**
30-
* @var ConfigSectionChecker
30+
* @deprecated
3131
*/
3232
protected $_sectionChecker;
3333

3434
/**
3535
* @param \Magento\Backend\App\Action\Context $context
3636
* @param \Magento\Config\Model\Config\Structure $configStructure
37-
* @param ConfigSectionChecker $sectionChecker
37+
* @param $sectionChecker - deprecated
3838
*/
3939
public function __construct(
4040
\Magento\Backend\App\Action\Context $context,
4141
\Magento\Config\Model\Config\Structure $configStructure,
42-
ConfigSectionChecker $sectionChecker
42+
$sectionChecker
4343
) {
4444
parent::__construct($context);
4545
$this->_configStructure = $configStructure;
@@ -55,7 +55,12 @@ public function __construct(
5555
public function dispatch(\Magento\Framework\App\RequestInterface $request)
5656
{
5757
if (!$request->getParam('section')) {
58-
$request->setParam('section', $this->_configStructure->getFirstSection()->getId());
58+
try {
59+
$request->setParam('section', $this->_configStructure->getFirstSection()->getId());
60+
} catch (LocalizedException $e) {
61+
/** If visible section not found need to show only config index page without sections if it allow. */
62+
$this->messageManager->addWarningMessage($e->getMessage());
63+
}
5964
}
6065
return parent::dispatch($request);
6166
}

app/code/Magento/Config/Controller/Adminhtml/System/ConfigSectionChecker.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use Magento\Framework\Exception\NotFoundException;
1010

1111
/**
12-
* @api
12+
* @deprecated - unused class.
13+
* @see \Magento\Config\Model\Config\Structure\Element\Section::isAllowed()
1314
*/
1415
class ConfigSectionChecker
1516
{

app/code/Magento/Config/Model/Config/Structure.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Config\Model\Config;
77

8+
use Magento\Framework\Exception\LocalizedException;
9+
810
/**
911
* System configuration structure.
1012
*
@@ -195,7 +197,8 @@ public function getElementByConfigPath($path)
195197
/**
196198
* Retrieve first available section in config structure
197199
*
198-
* @return \Magento\Config\Model\Config\Structure\ElementInterface
200+
* @return Structure\ElementInterface
201+
* @throws LocalizedException
199202
*/
200203
public function getFirstSection()
201204
{
@@ -204,6 +207,10 @@ public function getFirstSection()
204207
/** @var $tab \Magento\Config\Model\Config\Structure\Element\Tab */
205208
$tab = $tabs->current();
206209
$tab->getChildren()->rewind();
210+
if (!$tab->getChildren()->current()->isVisible()) {
211+
throw new LocalizedException(__('Visible section not found.'));
212+
}
213+
207214
return $tab->getChildren()->current();
208215
}
209216

app/code/Magento/Config/Test/Unit/Model/Config/StructureTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,26 @@ public function testGetFirstSectionReturnsFirstAllowedSection()
317317
->willReturnSelf();
318318
$tabMock->expects($this->once())
319319
->method('rewind');
320-
$tabMock->expects($this->once())
321-
->method('current')
320+
$section = $this->getMockBuilder(Structure\Element\Section::class)
321+
->disableOriginalConstructor()
322+
->setMethods(['isVisible', 'getData'])
323+
->getMock();
324+
$section->expects($this->any())
325+
->method('isVisible')
326+
->willReturn(true);
327+
$section->expects($this->any())
328+
->method('getData')
322329
->willReturn('currentSection');
330+
$tabMock->expects($this->any())
331+
->method('current')
332+
->willReturn($section);
323333
$this->_tabIteratorMock->expects($this->once())
324334
->method('rewind');
325335
$this->_tabIteratorMock->expects($this->once())
326336
->method('current')
327337
->willReturn($tabMock);
328338

329-
$this->assertEquals('currentSection', $this->_model->getFirstSection());
339+
$this->assertEquals('currentSection', $this->_model->getFirstSection()->getData());
330340
}
331341

332342
public function testGetElementReturnsProperElementByPathCachesObject()

dev/tests/functional/tests/app/Magento/Config/Test/Block/System/Config/AdminForm.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ public function adminAccountSharingAvailability()
2121
{
2222
return $this->_rootElement->find($this->adminAccountSharingField, Locator::SELECTOR_CSS)->isVisible();
2323
}
24+
25+
/**
26+
* Check if form is empty.
27+
*
28+
* @return bool
29+
*/
30+
public function isEmpty()
31+
{
32+
return $this->isVisible() && $this->_rootElement->getText() == '';
33+
}
2434
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
28
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd">
39
<page name="AdminAccountSharing" area="Adminhtml" mca="admin/system_config/edit/section/admin/" module="Magento_Config">
4-
<block name="adminForm" class="Magento\Config\Test\Block\System\Config\AdminForm" locator="[id='page:main-container']" strategy="css selector" />
5-
</page>
6-
</config>
10+
<block name="adminForm" class="Magento\Config\Test\Block\System\Config\AdminForm" locator="[id='page:main-container']" strategy="css selector" />
11+
</page>
12+
<page name="ConfigIndex" area="Adminhtml" mca="admin/system_config/" module="Magento_Config">
13+
<block name="adminForm" class="Magento\Config\Test\Block\System\Config\AdminForm" locator="[id='page:main-container']" strategy="css selector" />
14+
</page>
15+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\User\Test\Constraint;
8+
9+
use Magento\Backend\Test\Page\AdminAuthLogin;
10+
use Magento\Backend\Test\Page\Adminhtml\Dashboard;
11+
use Magento\Config\Test\Page\Adminhtml\ConfigIndex;
12+
use Magento\Mtf\Constraint\AbstractConstraint;
13+
use Magento\User\Test\Fixture\User;
14+
15+
/**
16+
* Assert for check permission for admin user that has access only to Configuration index page
17+
* (without access to any sections).
18+
*/
19+
class AssertUserPermissionsOnlyConfigurationIndexPage extends AbstractConstraint
20+
{
21+
/**
22+
* Check if form is empty.
23+
*
24+
* @param ConfigIndex $configIndex
25+
* @param Dashboard $dashboard
26+
* @param AdminAuthLogin $adminAuth
27+
* @param User $customAdmin
28+
*/
29+
public function processAssert(
30+
ConfigIndex $configIndex,
31+
Dashboard $dashboard,
32+
AdminAuthLogin $adminAuth,
33+
User $customAdmin
34+
) {
35+
$dashboard->getAdminPanelHeader()->logOut();
36+
$adminAuth->open();
37+
$adminAuth->getLoginBlock()->fill($customAdmin);
38+
$adminAuth->getLoginBlock()->submit();
39+
$configIndex->open();
40+
\PHPUnit_Framework_Assert::assertTrue(
41+
$configIndex->getAdminForm()->isEmpty(),
42+
"Form isn't empty."
43+
);
44+
}
45+
46+
/**
47+
* Return string representation of object
48+
*
49+
* @return string
50+
*/
51+
public function toString()
52+
{
53+
return 'Form is empty.';
54+
}
55+
}

dev/tests/functional/tests/app/Magento/User/Test/Repository/Role.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,15 @@
7777
<item name="Sitemap" xsi:type="string">Magento_Sitemap::sitemap</item>
7878
</field>
7979
</dataset>
80+
81+
<dataset name="role_empty_config">
82+
<field name="rolename" xsi:type="string">RoleName%isolation%</field>
83+
<field name="resource_access" xsi:type="string">Custom</field>
84+
<field name="current_password" xsi:type="string">%current_password%</field>
85+
<field name="roles_resources" xsi:type="array">
86+
<item name="Dashboard" xsi:type="string">Magento_Backend::dashboard</item>
87+
<item name="Configuration" xsi:type="string">Magento_Config::config</item>
88+
</field>
89+
</dataset>
8090
</repository>
8191
</config>

dev/tests/functional/tests/app/Magento/User/Test/TestCase/CreateAdminUserEntityTest.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,18 @@
9797
<data name="user/data/current_password" xsi:type="string">incorrect-password</data>
9898
<constraint name="Magento\User\Test\Constraint\AssertIncorrectUserPassword" />
9999
</variation>
100+
<variation name="CreateAdminUserWithPermissionsToEmptyConfiguration" summary="Create Custom Admin with permissions only for empty Configuration" ticketId="MAGETWO-70133">
101+
<data name="user/data/username" xsi:type="string">AdminUser%isolation%</data>
102+
<data name="user/data/firstname" xsi:type="string">FirstName%isolation%</data>
103+
<data name="user/data/lastname" xsi:type="string">LastName%isolation%</data>
104+
<data name="user/data/email" xsi:type="string">email%isolation%@example.com</data>
105+
<data name="user/data/password" xsi:type="string">123123q</data>
106+
<data name="user/data/password_confirmation" xsi:type="string">123123q</data>
107+
<data name="user/data/is_active" xsi:type="string">Active</data>
108+
<data name="user/data/role_id/dataset" xsi:type="string">role::role_empty_config</data>
109+
<data name="user/data/current_password" xsi:type="string">%current_password%</data>
110+
<constraint name="Magento\User\Test\Constraint\AssertUserSuccessSaveMessage" />
111+
<constraint name="Magento\User\Test\Constraint\AssertUserPermissionsOnlyConfigurationIndexPage" />
112+
</variation>
100113
</testCase>
101114
</config>

0 commit comments

Comments
 (0)