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">
2
  • 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? Feb 15, 2016 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, 2016 at 14:01

2 Answers 2

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.

5
  • 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 Feb 16, 2016 at 15:01
  • how would you override existing third party plugin(LandofCoder) having acl.xml and menu.xml in order to give permission to access that module to other user roles?. Admin is able to access that module but I also want that module to be accessible by other userroles. i have put up my work over here magento.stackexchange.com/questions/326318/…. this concept is really interesting it would be great if someone can guide me through this.
    – J. Doe
    Nov 16, 2020 at 21:36
  • Hello @Marius it is not working for vendor/magento/module-company/etc/company_acl.xml please help Aug 23, 2021 at 5:58
  • What is company_acl.xml? The file should be names acl.xml
    – Marius
    Aug 23, 2021 at 7:47
  • Hello @Marius it is Magento b2b . Aug 23, 2021 at 9:58
-2

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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