【发布时间】:2023-03-11 17:04:01
【问题描述】:
我将 Sonata Admin Bundle 与 ACL 集成,并具有以下配置:
config.yml
sonata_admin:
security:
handler: sonata.admin.security.handler.acl
# acl security information
information:
GUEST: [VIEW, LIST]
MAINTAINER: [EDIT, LIST]
STAFF: [EDIT, LIST, CREATE]
EDITOR: [OPERATOR, EXPORT]
ADMIN: [MASTER]
# permissions not related to an object instance and also to be available when objects do not exist
# the DELETE admin permission means the user is allowed to batch delete objects
admin_permissions: [CREATE, LIST, DELETE, UNDELETE, EXPORT, OPERATOR, MASTER]
# permission related to the objects
object_permissions: [VIEW, EDIT, DELETE, UNDELETE, OPERATOR, MASTER, OWNER]
security.yml
安全性:
role_hierarchy:
ROLE_OPERATOR:
- ROLE_ADMIN_BOOKING_ADMIN
- ROLE_ADMIN_PAYMENT_ADMIN
流程是我们通过BookingAdmin 类创建一个预订对象,并在 postPersist 原则事件监听器中创建支付对象。
$payment = new Payment();
//... set here
$this->entityManager->persist($payment);
$this->entityManager->flush();
问题出在列表中,我看不到编辑按钮,但我可以删除。
当手动运行命令时:
php bin/console sonata:admin:generate-object-acl
之后我就可以看到编辑按钮了。
我在这里做错了什么?因为我是用同一个用户登录的。
编辑
经过一番研究,我发现了下一个问题https://sonata-project.org/bundles/admin/2-3/doc/reference/security.html#acl-and-friendsofsymfony-userbundle
A listener must be implemented that creates the object Access Control List with the required rules if objects are created outside the Admin
这是什么意思,以及我应该如何在侦听器中执行正确的 ACL 角色?
【问题讨论】:
标签: symfony acl sonata-admin sonata sonata-user-bundle