mrgreenstuff / acl-sonata-admin-extension-bundle
为 SonataAdmin 提供带有主 ACL 的 ACL 列表过滤
dev-master / 2.3.x-dev
2014-01-26 19:34 UTC
Requires
- sonata-project/admin-bundle: ~2.2,>=2.2.2
- symfony/symfony: ~2.2
This package is not auto-updated.
Last update: 2024-09-24 00:17:24 UTC
README
此扩展是从 CoopTilleulsAclSonataAdminExtensionBundle 衍生而来。
此扩展为 SonataAdminBundle 提供ACL列表过滤。启用后,列表屏幕仅显示登录用户有权查看的数据。
此扩展是 SonataAdminBundle 的良好补充 ACL 编辑器。
安装
请确保 SonataAdminBundle 已正常工作并已启用 ACL。
使用 composer 安装此扩展
composer require mrgreenstuff/acl-sonata-admin-extension-bundle
在您的 AppKernel 中注册此扩展
// app/AppKernel.php public function registerBundles() { return array( // ... new MrGreenStuff\Bundle\AclSonataAdminExtensionBundle\MrGreenStuffAclSonataAdminExtensionBundle(), // ... ); }
启用
此扩展对所有管理员自动启用。
特殊情况(主 ACL 实体)
增强者:JUILLARD YOANN
应用示例
3 张表:商店、产品和国家
- 在这些表之间关系为 ManyToOne(1 个国家有 N 个商店)(1 个商店有 N 个产品)。它应该在所有关系类型上工作,但尚未经过测试。
4 个用户
- 管理员(SUPER_ADMIN)
- 主管理员(非 SUPER_ADMIN!)
- 英格兰管理员
- 法国管理员
预期行为
- 主管理员对所有国家拥有操作员 ACL,因此他可以访问匹配国家的所有商店和产品(即使为他创建的 ACL 记录不存在,但因为他们有对父级或祖父级的 ACL 访问,在这种情况下所有国家)
- 英格兰管理员或法国管理员可以访问匹配国家的所有商店和产品(即使产品或商店是由主管理员或 SUPER_ADMIN 创建的,并且没有为这些用户创建 ACL,但因为他们有对父级或祖父级的 ACL 访问,在这种情况下只有一个国家)
- 管理员保持 SUPER_ADMIN 角色(正常行为)
配置
- 在您的 SonataAdmin 类中创建方法:getMasterAclClass()(仅在您想启用该行为的情况下)。此方法必须返回一个主实体 ACL 的字符串,如
/*In Shop and Product admin classes*/ public function getMasterAclClass(){ return 'Acme\DemoBundle\Entity\Country'; }
- 在您的 SonataAdmin 类中创建方法:getMasterAclPath()(仅在您想启用该行为的情况下)。此方法必须返回一个数组,如
/*In Shop admin class*/ public function getMasterAclPath(){ return array( array('coutry','c') ); } //Where 'country' is the property name of the Shop entity who made the relation with Country Entity and 'c' a unique identifier (IMPORTANT the unique shortcut identifier CANNOT BE 'o' because 'o' is the default identifier of Sonata Admin) /*In Product admin class*/ public function getMasterAclPath(){ return array( array('shop','s'), array('coutry','c') ); }
请注意数组的顺序,它必须是 parent->grandParent->grandGrandParent... 直到上面定义的 Master ACL 类
禁用严格模式(默认启用)
当主 ACL 的子对象由用户创建时,ACL 仍然像没有此扩展一样添加。当您删除主类的一个记录的 ACL 访问权限时,用户仍然无法访问在 ACL 主更新之前创建的记录(即使 ACL 记录将其定义为所有者)。如果您想允许用户继续访问在 ACL 主更新之前由他们创建的子记录,您必须禁用严格模式。
为此,在管理员类中编写方法 getMasterAclStrict()。
public function getMasterAclStrict(){ return false; }
致谢
由 Kévin Dunglas 为 La Coopérative des Tilleuls 创建。
增强者:JUILLARD Yoann