PHPackages                             dized/module-front-acl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. dized/module-front-acl

ActiveMagento2-module[Authentication &amp; Authorization](/categories/authentication)

dized/module-front-acl
======================

ACL System for the Front Part of the Magento 2 project

1.0.3(2y ago)23221[1 issues](https://github.com/di-zed/m2-front-acl/issues)1MITPHP

Since Mar 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/di-zed/m2-front-acl)[ Packagist](https://packagist.org/packages/dized/module-front-acl)[ Docs](https://github.com/di-zed/m2-front-acl)[ RSS](/packages/dized-module-front-acl/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (5)Used By (1)

DiZed Magento 2 Front ACL Module
================================

[](#dized-magento-2-front-acl-module)

ACL System for the Front Part of the Magento 2 project.
-------------------------------------------------------

[](#acl-system-for-the-front-part-of-the-magento-2-project)

A module that will allow you to take full advantage of the front-end ACL capabilities in the modules you develop.

###### Developed and tested on Magento 2.4 version and PHP 7.4 version.

[](#developed-and-tested-on-magento-24-version-and-php-74-version)

##### Key Features:

[](#key-features)

- Ability to create your own roles and permissions via XML file.
- Ability to set default permissions for each of the roles.
- Ability to set the necessary roles and permissions for each customer in the admin panel.
- Ability to automatically set the default role and permissions for a newly created customer (using a plugin).
- Ability to easily use this functionality for controllers/actions and blocks.

### Installation.

[](#installation)

```
composer require dized/module-front-acl

bin/magento setup:upgrade --keep-generated
bin/magento setup:di:compile
bin/magento cache:clean

```

**IMPORTANT** to enable the module in Magento Admin: **Admin Panel -&gt; Stores -&gt; Settings -&gt; Configuration -&gt; DiZed Team Extensions -&gt; Front ACL**.

[![Module Configuration](https://raw.githubusercontent.com/di-zed/internal-storage/main/readme/images/m2-front-acl/config_front_acl.png)](https://raw.githubusercontent.com/di-zed/internal-storage/main/readme/images/m2-front-acl/config_front_acl.png)

### Adding Roles and Permissions.

[](#adding-roles-and-permissions)

To add new roles or permissions, create the **etc/acl\_front.xml** file in your own project module. You can see an example of a file in this module.

Roles are inserted into the **FrontAcl\_Role::index** resource, permissions are inserted into the **FrontAcl\_Permission::index** resource.

If you want to set the default permissions for some roles, use the **FrontAcl\_Defaults::index** resource. Pay attention to the syntax - *Relation\_ {RoleCamelCase}::permission\_snake\_case*.

```

```

### Set customer roles and permissions in admin panel.

[](#set-customer-roles-and-permissions-in-admin-panel)

To set a role or permissions for a customer through the admin panel, just log in as an administrator and follow the following path: **Customers -&gt; All Customers -&gt; Click to "Edit" for a customer in the grid -&gt; Tab Front ACL**. Select the required data here and save the customer.

[![Customer Settings](https://raw.githubusercontent.com/di-zed/internal-storage/main/readme/images/m2-front-acl/customer_front_acl.png)](https://raw.githubusercontent.com/di-zed/internal-storage/main/readme/images/m2-front-acl/customer_front_acl.png)

**IMPORTANT** If the permissions tree is not displayed, it is very likely that you are using a version of Magento with an older version of the jQuery jsTree library. In this case, try using the [previous script "view/adminhtml/web/js/customer/permissions-tree.js" version](https://raw.githubusercontent.com/di-zed/m2-front-acl/21ceaa62f3a93cacce0a76ef2ef33ebf9a773430/view/adminhtml/web/js/customer/permissions-tree.js).

### Set the default role and permissions for a newly created customer automatically.

[](#set-the-default-role-and-permissions-for-a-newly-created-customer-automatically)

If you need to set roles and permissions for a new customer automatically, you can create a plugin for the function: *\\DiZed\\FrontAcl\\Plugin\\Customer\\Api\\AccountManagement::getDetectedRole(CustomerInterface $customer)*. In the body of the function, you need to implement the necessary logic based on the customer object and return the required role as a string. Further, based on this role, default permissions will be automatically taken and applied to the customer.

```
    /**
     * Add custom logic to identify customer role.
     *
     * @param \DiZed\FrontAcl\Plugin\Customer\Api\AccountManagement $subject
     * @param string $result
     * @param \Magento\Customer\Api\Data\CustomerInterface $customer
     * @return string
     * @see \DiZed\FrontAcl\Plugin\Customer\Api\AccountManagement::getDetectedRole
     */
    public function afterGetDetectedRole(
        \DiZed\FrontAcl\Plugin\Customer\Api\AccountManagement $subject,
        string $result,
        CustomerInterface $customer
    ): string {
        // @todo Need to add custom logic here...
        return $result;
    }
```

### Use this functionality for controllers/actions and blocks.

[](#use-this-functionality-for-controllersactions-and-blocks)

To check the role or permissions of a customer in a controller/action you need to implement the **\\DiZed\\FrontAcl\\Controller\\App\\HttpAclActionInterface** interface and use the **FRONT\_ACL\_ROLE** or **FRONT\_ACL\_PERMISSION** constants. You can also use the **isFrontClassAllowed()** public function to specify more precise conditions.

```
