behappy/rights-management-plugin

Sylius 的权限管理插件。

1.1.2 2018-10-08 09:17 UTC

This package is not auto-updated.

Last update: 2024-09-17 14:42:27 UTC


README

Sylius 的权限管理插件。

安装

  1. 运行
$ composer require behappy/rights-management-plugin
  1. 在app/AppKernel.php中启用插件
public function registerBundles(): array
{
    $bundles = [
        // ...
        new \BeHappy\SyliusRightsManagementPlugin\BeHappySyliusRightsManagementPlugin()
    ];
    
    // ...
}
  1. 将以下导入添加到config.yml
imports:
    # ...
    - { resource: '@BeHappySyliusRightsManagementPlugin/Resources/config/app/config.yml' }
  1. 将以下路由添加到routing.yml
be_happy_rights_management:
    resource: '@BeHappySyliusRightsManagementPlugin/Resources/config/routing.yaml'
    prefix: /admin
  1. 更新您的数据库模式
$ php bin/console doctrine:schema:update --force
  1. 覆盖AdminUser模板以添加组选择
    1. 创建文件:app/Resources/SyliusAdminBundle/views/AdminUser/_form.html.twig

    2. 在刚刚创建的文件中,放入_form.html.twig的内容

    3. 然后添加以下片段

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

使用方法

组只能授予或拒绝访问列表中的路由。要列出路由,请将其添加到您的config.yml中。

示例

be_happy_sylius_rights_management:
    rights:
        product:
            all:
                name: 'be_happy_rights_management.rights.product.all'
                routes: ['sylius_admin_product_*']
                exclude: ['sylius_admin_product_review_*']
                redirect_to: sylius_admin_dashboard
                redirect_message: "be_happy_rights_management.message.access_denied"
        customer:
            list:
                name: 'be_happy_rights_management.rights.customer.list'
                routes: ['sylius_admin_customer_index']
                redirect_to: sylius_admin_dashboard
                redirect_message: "be_happy_rights_management.message.access_denied"

架构如下

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.'
                routes: 'An array of routes. This syntax is preferred to "route"'
                exclude: 'An array of excluded routes (useful if you define routes with a *).'
                redirect_to: 'The route to redirect if not granted.'
                redirect_message: 'A message if not granted.'

家族和动作可以设置为所需的任何内容,它们仅用于获得美观的架构。

允许使用“*”的语法,使防火墙接受给定字符串开头的所有内容。"*"只能位于字符串的末尾。

注意

我们建议您创建一个具有完全权限的Admin Group,否则当您编辑用户时,它将采用列表中的第一个组。并且您需要直接在MySQL中解锁用户。如果config.yml中添加了新的路由,您需要手动更新和保存组。

请自由贡献

您也可以通过在composer.json中提及此包的邮件地址提出您的问题。

其他

您还可以在我们的其他包(包括Sylius插件)中查看https://github.com/BeHappyCommunication