i wanted to add custom module actions like create, edit and delete need to be added in ACL permissions, can anyone help me how we do that, thanks in advance
1 Answer
Take the sales module as inspiration.
In the adminhtml.xml
of the module you will find this:
<order translate="title">
<title>Orders</title>
<children>
<actions translate="title">
<title>Actions</title>
<children>
<create translate="title"><title>Create</title></create>
<view translate="title"><title>View</title></view>
<email translate="title"><title>Send Order Email</title></email>
<reorder translate="title"><title>Reorder</title></reorder>
<edit translate="title"><title>Edit</title></edit>
<cancel translate="title"><title>Cancel</title></cancel>
<review_payment translate="title"><title>Accept or Deny Payment</title></review_payment>
<capture translate="title"><title>Capture</title></capture>
<invoice translate="title"><title>Invoice</title></invoice>
<creditmemo translate="title"><title>Credit Memos</title></creditmemo>
<hold translate="title"><title>Hold</title></hold>
<unhold translate="title"><title>Unhold</title></unhold>
<ship translate="title"><title>Ship</title></ship>
<comment translate="title"><title>Comment</title></comment>
<reorder translate="title"><title>Reorder</title></reorder>
<emails translate="title"><title>Send Sales Emails</title></emails>
</children>
</actions>
</children>
<sort_order>10</sort_order>
</order>
Every action you can do is listed in there.
Then, in the controller you need to check if you have access depending on the action. Similar to this code here:
protected function _isAllowed()
{
$action = strtolower($this->getRequest()->getActionName());
switch ($action) {
case 'hold':
$aclResource = 'sales/order/actions/hold';
break;
case 'unhold':
$aclResource = 'sales/order/actions/unhold';
break;
case 'email':
$aclResource = 'sales/order/actions/email';
break;
case 'cancel':
$aclResource = 'sales/order/actions/cancel';
break;
case 'view':
$aclResource = 'sales/order/actions/view';
break;
case 'addcomment':
$aclResource = 'sales/order/actions/comment';
break;
case 'creditmemos':
$aclResource = 'sales/order/actions/creditmemo';
break;
case 'reviewpayment':
$aclResource = 'sales/order/actions/review_payment';
break;
default:
$aclResource = 'sales/order';
break;
}
return Mage::getSingleton('admin/session')->isAllowed($aclResource);
}
and you can check if you can add a button or not similar to this
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
$this->getMassactionBlock()->addItem('cancel_order', array(
'label'=> Mage::helper('sales')->__('Cancel'),
'url' => $this->getUrl('*/sales_order/massCancel'),
));
}