Skip to content

pogorivan/SyliusRightsManagementPlugin

 
 

Repository files navigation

Sylius Rights Management Plugin

A rights management plugin for Sylius.

Installation

  1. Run
$ composer require behappy/rights-management-plugin
  1. Enable the plugin in app/AppKernel.php:
public function registerBundles(): array
{
    $bundles = [
        // ...
        new \BeHappy\SyliusRightsManagementPlugin\BeHappySyliusRightsManagementPlugin()
    ];
    
    // ...
}
  1. Add the following import to config.yml:
imports:
    # ...
    - { resource: '@BeHappySyliusRightsManagementPlugin/Resources/config/app/config.yml' }
  1. Add the following route to routing.yml:
be_happy_rights_management:
    resource: '@BeHappySyliusRightsManagementPlugin/Resources/config/routing.yaml'
  1. Update your database schema:
$ php bin/console doctrine:schema:update --force
  1. Override AdminUser template to add group select:
    1. Create a file: app/Resources/SyliusAdminBundle/views/AdminUser/_form.html.twig

    2. In the freshly created file, put the content of _form.html.twig

    3. Then add the following snippet:

    <div class="ui segment">
        <h4 class="ui dividing header">{{ 'be_happy_rights_management.ui.group'|trans }}</h4>
        {{ form_widget(form.group) }}
    </div>

Usage

Group can only grant or deny access to listed routes. To list route, add to your config.yml.

Example:

be_happy_sylius_rights_management:
    rights:
        product:
            list:
                name: 'be_happy_rights_management.rights.product.read'
                route: 'sylius_admin_product_index'
            update:
                name: 'be_happy_rights_management.rights.product.update'
                route: 'sylius_admin_product_update'

Architecture is:

be_happy_sylius_rights_management:
    rights:
        <family>:
            <action>:
                name: 'Feel free to set what you want. This string is translated by Symfony.'
                route: 'The name of the route in the routing.yml.'

Family and Action can be set to what you want, they are only used to get a nice and beautiful architecture.

Caution

We advice you to create an Admin Group with full right, otherwise when you will edit an user, it will take the first group in the list. And you will need to unlock the user directly in MySQL. You manually need to update and save groups if new routes are added in config.yml.

Feel free to contribute

You can also ask your questions at the mail address in the composer.json mentioning this package.

Other

You can also check our other packages (including Sylius plugins) at https://github.com/BeHappyCommunication

About

A rights management plugin for Sylius.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 91.2%
  • HTML 6.0%
  • JavaScript 2.8%