2

I have this ACL in my module:

<acl>
    <resources>
        <admin>
            <children>
                <report>
                    <children>
                        <modulename translate="title">
                            <title>Reports (SQL)</title>
                            <children>
                                <edit translate="title">
                                    <title>Add/Edit Reports</title>
                                    <sort_order>10</sort_order>
                                </edit>
                            </children>
                        </modulename>
                    </children>
                </report>
            </children>
        </admin>
    </resources>
</acl>

I have some reports where my url is like:

adminhtml_customreport/viewtable/report_id/30/

or

adminhtml_customreport/viewtable/report_id/31/

is there a way to assign them to a specific role ? if Yes , how ? All idea is welcomed .

1

The way I'd do this is to create ACL paths for each one that won't specifically match a controller path. To use your example:

<acl>
    <resources>
        <admin>
            <children>
                <report>
                    <children>
                        <modulename translate="title">
                            <title>Reports (SQL)</title>
                            <children>
                                <edit translate="title">
                                    <title>Add/Edit Reports</title>
                                    <sort_order>10</sort_order>
                                </edit>
                                <report_30 translate="title">
                                    <title>Report name</title>
                                    <sort_order>10</sort_order>
                                </report_30>
                                <report_31 translate="title">
                                    <title>Report name</title>
                                    <sort_order>10</sort_order>
                                </report_31>
                                <report_32 translate="title">
                                    <title>Report name</title>
                                    <sort_order>10</sort_order>
                                </report_32>
                                <!-- And so on, for each report -->
                            </children>
                        </modulename>
                    </children>
                </report>
            </children>
        </admin>
    </resources>
</acl>

Then, in the controller _isAllowed() method, you can check for the requested report id vs. the path for each report, like this:

protected function _isAllowed()
{
    $reportId = $this->getRequest()->getParam('report_id');

    switch ($reportId) {
        case '30':
            return Mage::getSingleton('admin/session')->isAllowed('report/modulename/report_30');
        case '31':
            ...
    }
}

Remember that ACL routes don't have to exactly correspond to controller routes.

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.