0

I can see below code in file

use Magento\Backend\App\Action;

/**
 * Abstract assignment controller
 */
abstract class Assignment extends Action
{
    /**
     * Authorization level of a basic admin session
     *
     * @see _isAllowed()
     */
    const ADMIN_RESOURCE = 'Vendor_Catalog::import_product_category_assignment';
}

This class is extended by controller

class Index extends Assignment

I am not sure what's the use of "const ADMIN_RESOURCE = 'Vendor_Catalog::import_product_category_assignment';" there

1
  • Any thoughts would be greatly appreciated ?
    – devhs
    Apr 14, 2021 at 4:56

1 Answer 1

1

Function _isAllowed() was implemented on every action to defined the permission to run the action.

In _isAllowed() it's gonna use the const ADMIN_RESOURCE which be defined on your controller.

To understand the tag Vendor_Catalog::import_product_category_assignment. This is a resource which be defined on etc/acl.xml current module

See https://devdocs.magento.com/guides/v2.4/ext-best-practices/tutorials/create-access-control-list-rule.html

For multiple resources you could add

/**
 * @return bool
 */
protected function _isAllowed()
{
    return $this->_authorization->isAllowed('Foo_Bar::foo_bar') && $this->_authorization->isAllowed('Bar_Foo::bar_foo');
} 
3
  • Hello, thanks for the answer i have extended this class in my multiple controllers should i add "const ADMIN_RESOURCE =" for that too in same file ? i mean multiple admin_resource in same file?
    – devhs
    Apr 14, 2021 at 5:12
  • @devhs I've updated the answer related to multiple resources Apr 14, 2021 at 6:46
  • Thankyou for the answer
    – devhs
    Apr 14, 2021 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.