5

Magento 2.0.2 I am trying to add a new user role, but when I go to the Role Resource tab it doesn't display the Resources tree. I have no errors displaying. What is the next step to try and figure out why this isn't displaying.

Note : I loggedin as Administrator

Sreenshot : enter image description here

  • Any errors are displaying in browser console ? – Suresh Chikani Apr 20 '16 at 6:48
  • No nothing ...only screen as give screenshot above. – Manish Apr 20 '16 at 7:21
  • Are you login as administrator or other ? – Suresh Chikani Apr 20 '16 at 7:24
  • yes as Administrator – Manish Apr 20 '16 at 8:35
8

After long research, I am able to resolve this problem. A mistake was in the format of XML .

Initial code :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Acl/etc/acl.xsd">
<acl>
    <resources>
        <resource id="Magento_Adminhtml::admin">
            <resource id="Company_Module::" title="test" sortOrder="100"/>
        <!--AddMenuAcl-->
        </resource>
    </resources>
</acl>
</config>

Replace with :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <resource id="Magento_Backend::admin">
            <resource id="Company_module::test" title="test module" sortOrder="100"/>
            <!--AddMenuAcl-->
        </resource>
    </resources>
</acl>
</config>

Check for this also:

 <?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"             xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <resource id="Magento_Adminhtml::admin">
        </resource>
    </resources>
</acl>

If no resource is defined please comment:

    <?xml version="1.0"?>
     <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <!--<resource id="Magento_Adminhtml::admin">
        </resource>-->
    </resources>
</acl>

  • could you please tell how to do the same fo rmy custom module, i have posted the question here magento.stackexchange.com/questions/126315/… – Sushivam Jul 19 '16 at 12:42
  • Do i need to do it in my custom webapi.xml or include what you have shown in my existing acl.xml, for my custom role resource to be visible? – Sushivam Jul 19 '16 at 12:43
  • You need to add a acl.xml and resource should be same as defined in system.xml – Manish Jul 19 '16 at 14:36
  • Its perfect if you have a few modules but if you have something like 20 modules - its very hard to locate it. i really have no idea what file is with the bad format. i try to shut down all the modules third-party at magento 2 and still i got this error. – Goldy Oct 4 '16 at 8:45
  • i got this from the log:'[2016-10-04 08:48:55] main.INFO: Cache file with merged layout: LAYOUT_adminhtml_STORE1_354ce9a6f9f1f968098c06ca367bdfaf3 and handles default, adminhtml_user_role_editrole: Please correct the XML data and try again. [] [] ' – Goldy Oct 4 '16 at 8:49
2

I confirm what Manish reported. The problem sits in the acl.xml file. In my case (Magento 2.1) I had the following acl.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <resource id="Magento_Backend::all_elements" title="Ves ALl">
                <resource id="Ves_All::ves_all" title="Ves All" sortOrder="10">
                </resource>
        </resource>
        <resource id="Magento_Backend::admin">
            <resource id="Magento_Backend::stores">
                <resource id="Magento_Backend::stores_settings">
                    <resource id="Magento_Config::config">
                        <resource id="Ves_All::config" title="Ves All - Config Settings" />
                    </resource>
                </resource>
            </resource>
        </resource>
    </resources>
</acl>

I have removed the 1st resource like this:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <!-- <resource id="Magento_Backend::all_elements" title="Ves ALl">
                <resource id="Ves_All::ves_all" title="Ves All" sortOrder="10">
                </resource>
        </resource>  -->
        <resource id="Magento_Backend::admin">
            <resource id="Magento_Backend::stores">
                <resource id="Magento_Backend::stores_settings">
                    <resource id="Magento_Config::config">
                        <resource id="Ves_All::config" title="Ves All - Config Settings" />
                    </resource>
                </resource>
            </resource>
        </resource>
    </resources>
</acl>

and magically in the admin side the resource tree appears again (after flushing the cache)!

2

This is temporary solution worked for me. D:\xampp\htdocs\Project\vendor\magento\module-user\Block\Role\Tab\Edit.php

    <?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\User\Block\Role\Tab;

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

/**
 * Rolesedit Tab Display Block.
 *
 */
class Edit extends \Magento\Backend\Block\Widget\Form implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
    /**
     * @var string
     */
    protected $_template = 'role/edit.phtml';

    /**
     * Root ACL Resource
     *
     * @var \Magento\Framework\Acl\RootResource
     */
    protected $_rootResource;

    /**
     * Rules collection factory
     *
     * @var \Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory
     */
    protected $_rulesCollectionFactory;

    /**
     * Acl builder
     *
     * @var \Magento\Authorization\Model\Acl\AclRetriever
     */
    protected $_aclRetriever;

    /**
     * Acl resource provider
     *
     * @var \Magento\Framework\Acl\AclResource\ProviderInterface
     */
    protected $_aclResourceProvider;

    /** @var \Magento\Integration\Helper\Data */
    protected $_integrationData;

    /**
     * Core registry
     *
     * @var \Magento\Framework\Registry
     */
    protected $coreRegistry = null;

    /**
     * @param \Magento\Backend\Block\Template\Context $context
     * @param \Magento\Framework\Acl\RootResource $rootResource
     * @param \Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory $rulesCollectionFactory
     * @param \Magento\Authorization\Model\Acl\AclRetriever $aclRetriever
     * @param \Magento\Framework\Acl\AclResource\ProviderInterface $aclResourceProvider
     * @param \Magento\Integration\Helper\Data $integrationData
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Authorization\Model\Acl\AclRetriever $aclRetriever,
        \Magento\Framework\Acl\RootResource $rootResource,
        \Magento\Authorization\Model\ResourceModel\Rules\CollectionFactory $rulesCollectionFactory,
        \Magento\Framework\Acl\AclResource\ProviderInterface $aclResourceProvider,
        \Magento\Integration\Helper\Data $integrationData,
        array $data = []
    ) {
        $this->_aclRetriever = $aclRetriever;
        $this->_rootResource = $rootResource;
        $this->_rulesCollectionFactory = $rulesCollectionFactory;
        $this->_aclResourceProvider = $aclResourceProvider;
        $this->_integrationData = $integrationData;
        parent::__construct($context, $data);
    }

    /**
     * Set core registry
     *
     * @param \Magento\Framework\Registry $coreRegistry
     * @return void
     * @deprecated
     */
    public function setCoreRegistry(\Magento\Framework\Registry $coreRegistry)
    {

        $this->coreRegistry = $coreRegistry;
    }

    /**
     * Get core registry
     *
     * @return \Magento\Framework\Registry
     * @deprecated
     */
    public function getCoreRegistry()
    {

        if (!($this->coreRegistry instanceof \Magento\Framework\Registry)) {
            return \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\Registry');
        } else {
            return $this->coreRegistry;
        }
    }

    /**
     * Get tab label
     *
     * @return \Magento\Framework\Phrase
     */
    public function getTabLabel()
    {
        return __('Role Resources');
    }

    /**
     * Get tab title
     *
     * @return string
     */
    public function getTabTitle()
    {
        return $this->getTabLabel();
    }

    /**
     * Whether tab is available
     *
     * @return bool
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * Whether tab is visible
     *
     * @return bool
     */
    public function isHidden()
    {
        return false;
    }

    /**
     * Check if everything is allowed
     *
     * @return bool
     */
    public function isEverythingAllowed()
    {
        $selectedResources = $this->getSelectedResources();
        $id = $this->_rootResource->getId();
        return in_array($id, $selectedResources);
    }

    /**
     * Get selected resources
     *
     * @return array|mixed|\string[]
     */
    public function getSelectedResources()
    {
        $selectedResources = $this->getData('selected_resources');
        if (empty($selectedResources)) {
            $allResource = $this->getCoreRegistry()->registry(SaveRole::RESOURCE_ALL_FORM_DATA_SESSION_KEY);
            if ($allResource) {
                $selectedResources = [$this->_rootResource->getId()];
            } else {
                $selectedResources = $this->getCoreRegistry()->registry(SaveRole::RESOURCE_FORM_DATA_SESSION_KEY);
            }

            if (null === $selectedResources) {
                $rid = $this->_request->getParam('rid', false);
                $selectedResources = $this->_aclRetriever->getAllowedResourcesByRole($rid);
            }

            $this->setData('selected_resources', $selectedResources);
        }
        //var_dump($selectedResources); die();
        return $selectedResources;
    }

    /**
     * Get Json Representation of Resource Tree
     *
     * @return array
     */
    public function getTree()
    {
        $resources = $this->_aclResourceProvider->getAclResources();
        $rootArray = $this->_integrationData->mapResources(
            //isset($resources[1]['children']) ? $resources[1]['children'] : []; //comment this line
            isset($resources[2]['children']) ? $resources[2]['children'] : []
        ); //use this line
        return $rootArray;
    }
}

Please refer last method with comment.

  • 1
    awesome @pramod it's working for me thanks a lot and gud job – NIPPU Oct 28 '17 at 9:30
  • Thank you for providing this. This helped to debug and find the real cause. It seems that if you face similar issue then the $resources[0] have incorrect data attached and you can track to the module what causes this. In my case there was incorrect resource id defined : <resource id="Magento_Adminhtml::admin"> which had to be as <resource id="Magento_Backend::admin"> – Elvin Risti Nov 26 '17 at 13:05
  • It is pleasure to me that my ans helped you some extend . Please upvote if it is worthable @Elvin Risti – Pramod Kharade Nov 29 '17 at 2:54
0

Code to displace your module in role resouce:

 <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
    <resources>
        <resource id="Magento_Backend::admin">
            <resource id="Ipragmatech_Bannerblock::ipragmatech_indexindex"
                title="Banner Block" sortOrder="40">
                <resource id="Ipragmatech_Bannerblock::slider" title="Slider"
                    sortOrder="10" />
            </resource>
            <!--AddMenuAcl -->
            <resource id="Magento_Backend::stores">
                <resource id="Magento_Backend::stores_settings">
                    <resource id="Magento_Config::config">
                        <resource id="Ipragmatech_Bannerblock::config_bannerblock"
                            title="Banner Block" sortOrder="50" />
                    </resource>
                </resource>
                <!-- <resource id="Magento_Backend::stores_other_settings"> <resource 
                    id="Magento_Customer::group" title="Customer Groups" sortOrder="10" /> </resource> -->
            </resource>
        </resource>
    </resources>
</acl>

 <resource id="Ipragmatech_Bannerblock::config_bannerblock"
                        title="Banner Block" sortOrder="50" />
                </resource>

should be same as system.xml.

-1

Go to vendor/magento/module-user/Block/Role/Tab/edit.php

Go directly to line 205

replace it with

isset($resources[2]['children']) ? $resources[2]['children'] : []

problem solved.

  • I don't see how directly modifying a Magento module solves anything, it's a fix at best. I'd advise for a module upgrade. – Julien Lachal Mar 3 '17 at 7:57
  • We have to avoid modification on Magento core files. – Manish Mar 3 '17 at 8:08
  • It good to use simple but it's not a Magento standard way to edit core file..if there are a lot of solution available there. If you have tried a lot but finally you need to edit core file then it better to use a create an issue on Magento git hub repository. Is if Magento core error then they will add a patch on next Magento version. github.com/magento/magento2 – Manish Mar 3 '17 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.