roshyo/rights-management-plugin

Sylius 的权限管理插件。

安装: 233

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 0

分支: 10

类型:sylius-plugin

This package is auto-updated.

Last update: 2024-09-27 20:48:08 UTC


README

Sylius 的权限管理插件。

安装

  1. 运行
$ composer require behappy/rights-management-plugin
  1. 在 config/bundles.php 中启用插件
public function registerBundles(): array
{
    $bundles = [
        // ...
        new \BeHappy\SyliusRightsManagementPlugin\BeHappySyliusRightsManagementPlugin()
    ];
    
    // ...
}
  1. 将以下导入添加到 _sylius.yaml
imports:
    # ...
    - { resource: '@BeHappySyliusRightsManagementPlugin/Resources/config/app/config.yml' }
  1. 将以下路由添加到 routes.yaml
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>
  2. 清除缓存以正确加载翻译
$ php bin/console cache:clear

用法

组只能授予或拒绝对列出的路由的访问权限。要列出路由,请将其添加到您的 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