0

I have a module 'BlogMate' which is only accesible for users that have access to everything. Even when I change the role so the user can't access a completely unrelated part, the module gives an access denied page.

Why is that?

I don't want to give users 100% access just so they can acccess this module.

Maybe the following XML is relevant, I've seen similair questions post it.

path: app/code/community/Magik/BlogMate/etc/config.xml :

<?xml version="1.0"?>
<config>
    <modules>
        <Magik_BlogMate>
            <version>0.1.0</version>
        </Magik_BlogMate>
    </modules>
    <frontend>
        <routers>
            <blogmate>
                <use>standard</use>
                <args>
                    <module>Magik_BlogMate</module>
                    <frontName>blog</frontName>
                </args>
            </blogmate>
        </routers>
        <layout>
            <updates>
                <blogmate>
                    <file>blogmate.xml</file>
                </blogmate>
            </updates>
        </layout>
    </frontend>
    <global>
        <helpers>
            <blogmate>
                <class>Magik_BlogMate_Helper</class>
            </blogmate>
        </helpers>
        <blocks>
            <blogmate>
                <class>Magik_BlogMate_Block</class>
            </blogmate>
        </blocks>
        <models>
            <blogmate>
                <class>Magik_BlogMate_Model</class>
                <resourceModel>blogmate_mysql4</resourceModel>
            </blogmate>
            <blogmate_mysql4>
                <class>Magik_BlogMate_Model_Mysql4</class>
                <entities>        
                    <blog>
                        <table>magik_blog</table>
                    </blog>       
                    <category>
                        <table>magik_blog_category</table>
                    </category>       
                    <comment>
                        <table>magik_blog_comment</table>
                    </comment>
                </entities>
            </blogmate_mysql4>
        </models>
        <resources>
            <blogmate_setup>
                <setup>
                    <module>Magik_BlogMate</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </blogmate_setup>
            <blogmate_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </blogmate_write>
            <blogmate_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </blogmate_read>
        </resources>
    </global>
    <admin>
        <routers>
            <adminhtml>
                                <args>
                                        <modules>
                                                <blogmate before="Mage_Adminhtml">Magik_BlogMate_Adminhtml</blogmate>
                                        </modules>
                                </args>
                        </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <menu>
            <blogmate module="blogmate">
                <title>BlogMate</title>
                <sort_order>100</sort_order>
                <children>
                    <blogmatebackend module="blogmate">
                        <title>Blog Settings</title>
                        <sort_order>0</sort_order>
                        <action>adminhtml/system_config/edit/section/blogmate</action>
                    </blogmatebackend>
                    <blog module="blogmate">
                        <title>Manage Blog</title>
                        <sort_order>30</sort_order>
                        <action>adminhtml/blogmate_blog</action>
                    </blog>
                    <category module="blogmate">
                        <title>Manage Category</title>
                        <sort_order>40</sort_order>
                        <action>adminhtml/blogmate_category</action>
                    </category>
                    <comment module="blogmate">
                        <title>Manage Comment</title>
                        <sort_order>50</sort_order>
                        <action>adminhtml/blogmate_comment</action>
                    </comment>
                </children>
            </blogmate>
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <blogmate translate="title" module="blogmate">
                            <title>BlogMate</title>
                            <sort_order>1000</sort_order>
                            <children>
                                <blogmatebackend translate="title">
                                    <title>Blog Settings</title>
                                </blogmatebackend>
                                <blog translate="title">
                                    <title>Manage Blog</title>
                                    <sort_order>30</sort_order>
                                </blog>
                                <category translate="title">
                                    <title>Manage Category</title>
                                    <sort_order>40</sort_order>
                                </category>
                                <comment translate="title">
                                    <title>Manage Comment</title>
                                    <sort_order>50</sort_order>
                                </comment>
                            </children>
                        </blogmate>
                    </children>
                </admin>
            </resources>
        </acl>
        <layout>
            <updates>
                <blogmate>
                    <file>blogmate.xml</file>
                </blogmate>
            </updates>
        </layout>
    </adminhtml>
</config> 
  • add this code in admin controllers and try once : protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('ENTER RESOURCE IDENTIFIER HERE'); } – Baby in Magento Jun 27 '17 at 10:30
4

Add this function in controller file.

/**
     * Check for is allowed
     *
     * @return boolean
     */
     protected function _isAllowed() {
        return true;
    }
  • welcome to Stackexchange @sumilsanghavi – Rakesh Jesadiya Jun 27 '17 at 12:05
  • Where can I find this file? – twan Jun 27 '17 at 12:10
  • @Sumil sanghavi there are multiple controllers, what controller file do I need? – twan Jun 27 '17 at 12:32
  • Every separate controller has define separate RESOURCE IDENTIFIER in the ACL Example : For this controller <blogmatebackend translate="title"> <title>Blog Settings</title> </blogmatebackend> ADD this below funciton in the contoller file of the aobve code /** * Check for is allowed * * @return boolean */ protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('blogmate/blogmatebackend'); //return Mage::getSingleton('admin/session')->isAllowed('Children KEY/RESOURCE IDENTIFIER'); } – Sumil sanghavi Jun 27 '17 at 12:44
  • 1
    @twan Access Control List – sv3n Jun 30 '17 at 6:38
0

Add Below code in admin controller :

protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('ENTER RESOURCE IDENTIFIER HERE');
}
0

I had this exact problem with this exact module. Hopefully this full breakdown helps save anyone else some time.

Please Note: Some other answers in this thread are correct but more generic, I am expanding on these with a full breakdown for this specific Magento Extension.

Understanding The Problem

After creating a custom User Role in System>Permissions>Roles with permission to view only the BlogMate section of the admin as the image shows below:

enter image description here

Any Users assigned this Role will see the following Access Denied message when they try access any of the sections in the Admin (even though the links show in the admin menu):

enter image description here

Solution

As other answers point out you must add to following code to the module controllers:

protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('ENTER RESOURCE IDENTIFIER HERE');
}

Here is a full breakdown of the exact code needed:

Add the following code to app/code/community/Magik/BlogMate/controllers/ Adminhtml/BlogmatebackendController.php:

protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('blogmate/blogmatebackend');
}

Add the following code to app/code/community/Magik/BlogMate/controllers/ Adminhtml/BlogController.php:

protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('blogmate/blog');
}

Add the following code to app/code/community/Magik/BlogMate/controllers/ Adminhtml/CategoryController.php:

protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('blogmate/category');
}

Add the following code to app/code/community/Magik/BlogMate/controllers/ Adminhtml/CommentController.php:

protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('blogmate/comment');
}

I added these functions just below the opening of the class, e.g:

class Magik_BlogMate_Adminhtml_CommentController extends Mage_Adminhtml_Controller_Action
{
    protected function _isAllowed()
    {
        return Mage::getSingleton('admin/session')->isAllowed('blogmate/comment');
    }
...

Lastly, if you are still having trouble providing access to the BlogMate Blog Settings, this is because they are a section within System>Config, so make sure you add this permission to your role!

enter image description here

I hope this helps :)

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.