1
votes

Is it possible to disable a custom backend module in Magento based on the active user's role? If I create a login listener, and get the user role inside that listener, is there any event that I can dispatch to disable a specific module?

2
A module can be disabled globally only. It can't be a condition based - Dushyant Joshi

2 Answers

2
votes

You don't need to edit your code at all. Just create your module as per you want, and you can control the module output from admin by creating user role. Just go to Admin -> System -> Permission -> Roles -> Create New Role-> Role Resources -> Select Resource Access to Custom ( Here you can see all modules enabled in your system with all pages) then uncheck your module for that user role. Save it. Finished . That's all.

0
votes

Yes. Your custom module needs to have acl resource definitions so you can then enable and disable the module or some of its actions based upon the users role. This is actually relatively simple and can be done by creating a file called adminhtml.xml in your modules etc folder. This file will contain definitions for your modules menu system within the admin and it will also contain the definitions for the access control lists.

Once you create the file with the definitions for your modules actions, clear your cache and then you should see the config options when editing a user role.

<config>
    <menu>
        <your_module_name module="your_module_name">
            <title>Your Module Name</title>
            <sort_order>100</sort_order>
            <children>
                <new module="your_module_name" translate="title">
                    <title>Add New Article</title>
                    <sort_order>0</sort_order>
                    <action>your_module_name_admin/manage/new</action>
                </new>
                <list module="your_module_name" translate="title">
                    <title>Articles</title>
                    <sort_order>10</sort_order>
                    <action>your_module_name_admin/manage/index</action>
                </list>
                <settings translate="title" module="your_module_name">
                    <title>Settings</title>
                    <action>adminhtml/system_config/edit/section/your_module_name</action>
                    <sort_order>40</sort_order>
                </settings>
            </children>
        </your_module_name>
    </menu>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <your_module_name>
                        <title>Your Module Name</title>
                        <sort_order>70</sort_order>
                        <children>
                            <new>
                                <title>Create New Article</title>
                                <sort_order>0</sort_order>
                            </new>
                            <list>
                                <title>View &amp; Edit Articles</title>
                                <sort_order>1</sort_order>
                            </list>
                        </children>
                    </your_module_name>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <your_module_name>
                                        <title>Config Section Under System --> Configuration If Your Module Has One</title>
                                    </your_module_name>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</config>