0

Is it possible to set ACL permission for delete button on customer view Page in admin panel

enter image description here

Is it possible ?

0

There 3 things to do.

  1. Add new ACL
  2. Disable the Delete Customer Button
  3. Disable the Action if someone call the url admin/customer/delete/id/1 manuelly

1. Add new ACL

Create a new adminhtml.xml in your Module in the etc/ Folder or extend your existing adminhtml.xml with this code:

<acl>
    <resources>
        <admin>
            <children>
                <customer translate="title" module="customer">
                    <children>
                        <delete translate="title">
                            <title>Delete Customer</title>
                            <sort_order>110</sort_order>
                        </delete>
                    </children>
                </customer>
            </children>
        </admin>
    </resources>
</acl>

We extended the existing <customer> node with our <delete> node.
If you flush your cache, you already see a new entry in the Role Resources.

2. Disable the Button

We have to rewrite the core Block and delete the Button. Add the rewrite in your config.xml in your <block> node:

<adminhtml>
    <rewrite>
        <customer_edit>Company_Module_Block_Adminhtml_Customer_Edit</customer_edit>
    </rewrite>
</adminhtml>

Create a new File in the Block/ Folder: adminhtml/Cutomer/Edit.php

<?php

class Company_Module_Block_Adminhtml_Customer_Edit
    extends Mage_Adminhtml_Block_Customer_Edit
{
    public function __construct()
    {
        parent::__construct();

        if (!Mage::getSingleton('admin/session')->isAllowed('admin/customer/delete')) {
            $this->_removeButton('delete');
        }

    }

}

We check if the Permission is set for the User. If not, we remove the Button.

3. Disable the Action

In your config.xml you have to add a new adminhtml event:

<adminhtml>
    <events>
        <controller_action_predispatch_adminhtml_customer_delete>
            <observers>
                <delete_customer>
                    <type>singleton</type>
                    <method>checkCustomerDelete</method>
                    <class>company_name/observer</class>
                </delete_customer>
            </observers>
        </controller_action_predispatch_adminhtml_customer_delete>
    </events>
</adminhtml>

The Event is called if before the code inside the Action is executed.
Create or extend Model/Observer.php

<?php

class Company_Name_Model_Observer
{
    public function checkCustomerDelete(Varien_Event_Observer $observer)
    {
        if (!Mage::getSingleton('admin/session')->isAllowed('admin/customer/delete')) {
            exit;
        }
    }
}

If someone call the URL manually, the script just stops the request. It would be better if you show the User a Message and redirect them to the previous site.

The last thing you have to do is, delete the cache :)

|improve this answer|||||

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.