如何修复 "Access Denied to the action list and role LIST" 消息?

How to fix "Access Denied to the action list and role LIST" message?

我正在使用 Sonata Admin Bundle 来管理一些实体。我的实体之一称为等效。它有两个简单的字段。

我 运行 sonata:admin:generate 为这个新实体创建管理员 class。 I/O如下:

The fully qualified model class: AppBundle\Entity\Equivalent
The bundle name [AppBundle]:
The admin class basename [EquivalentAdmin]:
Do you want to generate a controller [no]? yes
The controller class basename [EquivalentAdminController]:
Do you want to update the services YAML configuration file [yes]?
The services YAML configuration file [admin.yml]:
The admin service ID [app.admin.equivalent]:

The admin class "AppBundle\Admin\EquivalentAdmin" has been generated under the file "/usr/src/app/src/AppBundle/Admin/EquivalentAdmin.php".

The controller class "AppBundle\Controller\EquivalentAdminController" has been generated under the file "/usr/src/app/src/AppBundle/Controller/EquivalentAdminController.php".

The service "app.admin.equivalent" has been appended to the file "/usr/src/app/src/AppBundle/Resources/config/admin.yml".

... 问题是,现在当我转到 /admin/app/equivalent/list 时——即使是作为超级用户——我也收到了这个错误:

Access Denied to the action list and role LIST

所以我的问题是:如何避免此错误并允许我的超级用户访问列表?

(如果您还包括允许其他操作的方法,则将其视为业力奖励。)

糟糕!查看数据库确认我的超级用户实际上不是超级用户。实际上,用户的 "roles" 字段非常稀疏。

查看 security.yml(以及数据库中的 users table),然后使用 fos:user:promote "fixed" 修复角色缺失问题暂时。

======

编辑 #1:

但几天后尝试相同的步骤并没有解决问题,所以问题仍然悬而未决。

======

编辑#2:

在同事的帮助和浏览 https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/security.html 后,很明显应用程序正在使用一些 "magic" 命名约定以允许在 security.yml 文件。

所以因为我在 admin.yml 文件中将 app.admin.equivalent 定义为服务,所以我在 security.yml 文件的相关位置添加了 ROLE_APP_ADMIN_EQUIVALENT_LIST,并且列表视图开始对我的用户正常工作。