contextualcode/ezplatform-role-inheritance-bundle

提供用户角色继承的eZ Platform组件包。

v1.0.3 2019-04-14 04:46 UTC

This package is not auto-updated.

Last update: 2024-09-24 06:46:45 UTC


README

这是一个提供用户角色继承的eZ Platform组件包。

这与内置的用户组继承不同,因为它允许进行细粒度、易于管理的用户角色管理,而不依赖于组。

(这是从permissions-inheritance-bundle迁移到eZ Platform的。)

安装

  • 运行composer require
$ composer require contextualcode/ezplatform-role-inheritance-bundle
  • app/AppKernel.php文件中启用此组件包,在registerBundles方法中添加以下行
    public function registerBundles()
    {
        $bundles = array(
            ...
            new ContextualCode\EzPlatformRoleInheritanceBundle\ContextualCodeEzPlatformRoleInheritanceBundle(),
        );
  • 将路由添加到你的app/config/routing.yml
    contextual_code_ez_platform_role_inheritance:
      resource: "@ContextualCodeEzPlatformRoleInheritanceBundle/Resources/config/routing.yml"
      prefix:   /
    
  • 创建新的自定义数据库表
$ cat vendor/contextualcode/ezplatform-role-inheritance-bundle/src/ContextualCode/EzPlatformRoleInheritanceBundle/SQL/MySQL/schema.sql | mysql -u <username -p<password> <database_name>

注意:如果你是从使用contextualcode/permissions-inheritance-bundle的eZ 5.x安装升级,请运行升级SQL以保留你的旧角色继承

$ cat vendor/contextualcode/ezplatform-role-inheritance-bundle/src/ContextualCode/EzPlatformRoleInheritanceBundle/SQL/MySQL/upgrade.sql | mysql -u <username -p<password> <database_name>
  • 完成。

使用方法

  1. 只需在管理UI中打开角色视图页面。在“角色继承”标签页中会有添加父/子角色的新功能。
  2. 还需要执行额外的代码来分配继承的角色:你必须调用RoleInheritanceServicehandleUserChildRoles($userId)函数。你可以使用自定义登录处理器/事件监听器或其他任何方式调用该代码。例如,你可以创建一个扩展eZ\Publish\Core\MVC\Symfony\Security\User\ProviderAppBundle\Security\User\Provider.php。在构造函数中添加RoleInheritanceService,并覆盖refreshUser函数以添加这些行来加载继承的角色
    $userId = $user->getAPIUser()->contentInfo->id;
    $this->roleInheritanceService->handleUserChildRoles($userId);
    

    然后你必须将security.providers.ezpublish.id设置为使用此新提供者的ID。现在用户将继承在管理UI中设置的角色。