3

How to disable or hide the core module ACL resources in magento 2 with the custom module. I have tried the following syntax and it does not work:

<resource id="Magento_Backend::content" remove="true">
  • How is this module expected to work after its ACL being hidden? Admin will have access to its functionality only when is assigned to role, which has "All" resources allowed. What is your business use case for this? – Alex Paliarush Feb 15 '16 at 9:05
  • @AlexPaliarush. I had the first reaction at first, but there is a use case for this (not sure if it's the one that the OP has). You may want to allow some users access to create other users, but you don't want them to give other users access to some of the magento sections. Sounds strange, but it could be. – Marius Feb 15 '16 at 14:01
4

You can create a custom module for that and use a before plugin for \Magento\Integration\Helper\Data::mapResources().
Let's name the module StackExchange_Acl.
You will need these files:

app/code/StackExchange/Acl/registration.php - the registration file

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'StackExchange_Acl',
    __DIR__
);

app/code/StackExchange/Acl/etc/module.xml - module file

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="StackExchange_Acl" setup_version="1.0.0" />
</config>

app/code/StackExchange/acl/etc/di.xml - di admin file to declare your plugin

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Integration\Helper\Data">
        <plugin name="acl-intergration-data" type="StackExchange\Acl\Plugin\Integration\Data" sortOrder="100" />
    </type>
</config>

app/code/StackExchange/Acl/Plugin/Integration/Data.php - the plugin

<?php
namespace StackExchange\Acl\Plugin\Integration;

class Data
{
    public function beforeMapResources(\Magento\Integration\Helper\Data $helper, array $resources)
    {
        $restricted = $this->getRestrictedIds();
        foreach ($resources as $key => $resource) {
            if (in_array($resource['id'], $restricted)) {
                unset($resources[$key]);
            }
        }
        return [$resources];
    }
    //list in this method all the ids of the acl's you don't want to show
    //if you don't want to had-code them you can read them from a config file - but you have to build that yourself.
    protected function getRestrictedIds()
    {
        return ['Magento_Sales::sales', 'Magento_Backend::dashboard'];
    }
}

run php bin/magento setup:upgrade and you are done.

  • Please pay attention to the fact, that there are 2 identical permission trees in the admin, which should be processed separately. This answer covers one for Integration and the other is rendered for the Admin user using \Magento\User\Block\Role\Tab\Edit::getTree – Alex Paliarush Feb 16 '16 at 15:01
0

u can set value 0 in app/etc/config.php

  • ,i need only to hide the resources in acl – user3040610 Feb 15 '16 at 5:23
  • @user3040610 did u got an answer for your query, please share it as even i am looking for the same :( – insoftservice Jun 24 at 23:54

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.