arobases / sylius-rights-management-plugin
This plugin allows you to manage the rights and roles of administrator users
Installs: 185
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 4
Open Issues: 5
Type:sylius-plugin
Requires
- php: ^7.4 || ^8.0
- sylius/sylius: v1.10.14
Requires (Dev)
- behat/behat: ^3.6.1
- behat/mink-selenium2-driver: ^1.4
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.8
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0.0
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- friendsofsymfony/oauth-server-bundle: ^1.6 || >2.0.0-alpha.0 ^2.0@dev
- phpspec/phpspec: ^7.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: 0.12.99
- phpstan/phpstan-doctrine: 0.12.33
- phpstan/phpstan-strict-rules: ^0.12.0
- phpstan/phpstan-webmozart-assert: 0.12.12
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- sensiolabs/security-checker: ^6.0
- sylius-labs/coding-standard: ^4.0
- symfony/browser-kit: ^4.4 || ^5.2
- symfony/debug-bundle: ^4.4 || ^5.2
- symfony/dotenv: ^4.4 || ^5.2
- symfony/intl: ^4.4 || ^5.2
- symfony/web-profiler-bundle: ^4.4 || ^5.2
- vimeo/psalm: 4.7.1
- dev-main
- 1.4.0
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/composer/vimeo/psalm-5.8.0
- dev-dependabot/composer/phpstan/phpstan-0.12.100
- dev-dependabot/composer/phpstan/phpstan-doctrine-0.12.44
- dev-dependabot/composer/phpstan/phpstan-webmozart-assert-0.12.16
This package is auto-updated.
Last update: 2024-10-31 14:49:17 UTC
README
This plugin allows you to manage the rights and roles of administrator users
Installation
Step 1: Download the plugin
- Install the plugin with
composer require arobases/sylius-rights-management-plugin
Step 2: Enable the plugin
- Register the bundle in your
bundles.php
:
# config/bundles.php <?php return [ ... Arobases\SyliusRightsManagementPlugin\ArobasesSyliusRightsManagementPlugin::class => ['all' => true], ... ];
Step 3: Import configuration
Create file config/packages/arobases_sylius_rights_management_plugin.yaml
with this content
imports:
- { resource: "@ArobasesSyliusRightsManagementPlugin/Resources/config/config.yaml" }
Step 4: Import routing
Create file config/routes/arobases_sylius_rights_management_plugin.yaml
with this content
arobases_sylius_rights_management_plugin_admin:
resource: "@ArobasesSyliusRightsManagementPlugin/Resources/config/admin_routing.yml"
prefix: /admin
Step 5: Use AdminUserTrait and implement AdminUserInterface
//src/Entity/AdminUser.php <?php declare(strict_types=1); namespace App\Entity\User; use Arobases\SyliusRightsManagementPlugin\Entity\AdminUserInterface; use Doctrine\ORM\Mapping as ORM; use Arobases\SyliusRightsManagementPlugin\Entity\AdminUserTrait; use Sylius\Component\Core\Model\AdminUser as BaseAdminUser; /** * @ORM\Entity * @ORM\Table(name="sylius_admin_user") */ class AdminUser extends BaseAdminUser implements AdminUserInterface { use AdminUserTrait; }
Step 6: Modify template SyliusAdminBundle/AdminUser/Form/_generalInfoExtended.html.twig
{# templates/bundles/SyliusAdminBundle/AdminUser/Form/_generalInfoExtended.html.twig #} ... <div class="ui segment"> <h4 class="ui dividing header">{{ 'arobases_sylius_rights_management_plugin.ui.choice_role'|trans }}</h4> {{ form_row(form.role) }} </div> ...
Step 7: Update your database:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
Step 8: Install assets
php bin/console asset:install
php bin/console cache:clear
Step 9: Define your default role (for example "administrator") and the username of the admin account which will have this role by default
#.env ###> arobases/sylius-rights-management ### DEFAULT_ADMIN_USER=EDITME DEFAULT_ADMIN_ROLE_CODE=EDITME DEFAULT_ADMIN_ROLE_NAME=EDITME ###> arobases/sylius-rights-management ###
if you don't change this lines, when you will create the rights with the command, you will no longer have access to anything in the back office because you will not have the rights.
Step 10: Use the command line to create roles, rights group and rights :
php bin/console arobases:right:create-admin-right
Screenshots
Index
Edit/create role
Error if the user does not have the rights
Usage
There is a pre-configured list of default rights :
#vendor/arobases/sylius-rights-management-plugin/src/Resources/config/right_management.yaml arobases_sylius_rights_management: groups: arobases_sylius_rights_management_plugin.group.taxon: #here it's the name of the group of the right rights: all: name: 'arobases_sylius_rights_management_plugin.rights.taxon' #here it's the name of the right routes: ['sylius_admin_taxon_*', 'sylius_admin_ajax_generate_taxon_slug'] arobases_sylius_rights_management_plugin.group.product: rights: product: name: 'arobases_sylius_rights_management_plugin.rights.product' routes: ['sylius_admin_product_*', 'sylius_admin_get_product_attributes_*', 'sylius_admin_get_attribute_types', 'sylius_admin_ajax_generate_product_slug', 'sylius_admin_ajax_taxon_*', 'sylius_admin_ajax_product_*' ] stock: name: 'arobases_sylius_rights_management_plugin.rights.inventory' routes: ['sylius_admin_inventory_*'] arobases_sylius_rights_management_plugin.group.order: rights: all: name: 'arobases_sylius_rights_management_plugin.rights.order' routes: ['sylius_admin_order_*', 'sylius_admin_payment_*', 'sylius_admin_shipment_*','sylius_invoicing_plugin_admin_invoice_*', 'sylius_refund_*', 'sylius_admin_ajax_render_province_*'] excludes: ['sylius_admin_payment_method_*'] arobases_sylius_rights_management_plugin.group.promotion: rights: all: name: 'arobases_sylius_rights_management_plugin.rights.promotion' routes: ['sylius_admin_promotion_*'] arobases_sylius_rights_management_plugin.group.user: rights: user: name: 'arobases_sylius_rights_management_plugin.rights.customer' routes: ['sylius_admin_customer_*', 'sylius_admin_impersonate_*'] excludes: ['sylius_admin_customer_group_*'] group: name: 'sylius.ui.customer_groups' routes: ['sylius_admin_customer_group_*',] arobases_sylius_rights_management_plugin.group.configuration: rights: channel: name: 'arobases_sylius_rights_management_plugin.rights.channel' routes: ['sylius_admin_channel_*'] country: name: 'arobases_sylius_rights_management_plugin.rights.country' routes: ['sylius_admin_country_*'] zone: name: 'arobases_sylius_rights_management_plugin.rights.zone' routes: ['sylius_admin_zone_*'] currency: name: 'arobases_sylius_rights_management_plugin.rights.currency' routes: ['sylius_admin_currency_*'] exchange_rate: name: 'arobases_sylius_rights_management_plugin.rights.exchange_rate' routes: ['sylius_admin_exchange_rate_*'] locale: name: 'arobases_sylius_rights_management_plugin.rights.locale' routes: ['sylius_admin_locale_*'] payment_method: name: 'arobases_sylius_rights_management_plugin.rights.payment_method' routes: ['sylius_admin_payment_method_*', 'sylius_admin_get_payment_gateways'] shipping_method: name: 'arobases_sylius_rights_management_plugin.rights.shipping_method' routes: ['sylius_admin_shipping_method_*', 'webgriffe_admin_shipping_table_rate_*'] shipping_category: name: 'arobases_sylius_rights_management_plugin.rights.shipping_category' routes: ['sylius_admin_shipping_category_*'] tax_category: name: 'arobases_sylius_rights_management_plugin.rights.tax_category' routes: ['sylius_admin_tax_category_*'] tax_rate: name: 'arobases_sylius_rights_management_plugin.rights.tax_rate' routes: ['sylius_admin_tax_rate_*'] arobases_sylius_rights_management_plugin.group.administration: rights: admin_user: name: 'arobases_sylius_rights_management_plugin.rights.admin_user' routes: ['sylius_admin_admin_user_*'] admin_role: name: 'arobases_sylius_rights_management_plugin.rights.admin_role' routes: ['arobases_sylius_rights_management_plugin_admin_role_*']
However you can modify or add some rights or rights group in your file config/packages/arobases_sylius_rights_management_plugin.yaml :
#config/packages/arobases_sylius_rights_management_plugin.yaml imports: - { resource: "@ArobasesSyliusRightsManagementPlugin/Resources/config/resources.yaml" } arobases_sylius_rights_management: groups: arobases_sylius_rights_management_plugin.group.product: rights: #here you will update "arobases_sylius_rights_management_plugin.group.product" app.group.my_new_group: rights: all: name: 'app.rights.my_new_right' routes: ['app_my_custom_route_*'] #here you will create a new group and a new right