roshyo / rights-management-plugin
Sylius 的权限管理插件。
1.1.3
2021-01-27 12:55 UTC
Requires
- php: ^7.4
- sylius/sylius: ^1.7
- symfony/dotenv: ^4.4
- symfony/flex: ^1.2
Requires (Dev)
- behat/behat: ^3.6.1
- behat/mink-selenium2-driver: ^1.3
- friends-of-behat/mink: ^1.7
- friends-of-behat/mink-browserkit-driver: ^1.3
- friends-of-behat/mink-extension: ^2.2
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.0
- friends-of-behat/variadic-extension: ^1.1
- lakion/mink-debug-extension: ^1.2.3
- lchrusciel/api-test-case: ^3.0
- phpspec/phpspec: ^6.0
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: 0.12.3
- phpstan/phpstan-doctrine: 0.12.3
- phpstan/phpstan-webmozart-assert: 0.12.0
- phpunit/phpunit: ^7.0
- sensiolabs/security-checker: ^6.0
- stripe/stripe-php: ^6.28
- sylius-labs/coding-standard: ^3.0
- symfony/browser-kit: ^4.4
- symfony/debug-bundle: ^4.4
- symfony/intl: ^4.4
- symfony/web-profiler-bundle: ^4.4
README
Sylius 的权限管理插件。
安装
- 运行
$ composer require behappy/rights-management-plugin
- 在 config/bundles.php 中启用插件
public function registerBundles(): array { $bundles = [ // ... new \BeHappy\SyliusRightsManagementPlugin\BeHappySyliusRightsManagementPlugin() ]; // ... }
- 将以下导入添加到 _sylius.yaml
imports: # ... - { resource: '@BeHappySyliusRightsManagementPlugin/Resources/config/app/config.yml' }
- 将以下路由添加到 routes.yaml
be_happy_rights_management: resource: '@BeHappySyliusRightsManagementPlugin/Resources/config/routing.yaml' prefix: /admin
- 更新您的数据库模式
$ php bin/console doctrine:schema:update --force
- 覆盖 AdminUser 模板以添加分组选择
-
创建一个文件:app/Resources/SyliusAdminBundle/views/AdminUser/_form.html.twig
-
在新建的文件中,放入_form.html.twig的内容
-
然后添加以下代码片段
<div class="ui segment"> <h4 class="ui dividing header">{{ 'be_happy_rights_management.ui.group'|trans }}</h4> {{ form_widget(form.group) }} </div>
-
- 清除缓存以正确加载翻译
$ 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