[英]SonataAdmin: add new role from route defined in admin class
I need to create a new ROLE called STATUS to appear in ROLE MANAGER of User CRUD like the image at link see image , this roles is based on a custom route defined in the admin class, and a custom controller. 我需要创建一个名为STATUS的新角色,以显示在User CRUD的ROLE MANAGER中,就像链接see image上的图像一样 ,此角色基于admin类和自定义控制器中定义的自定义路由。
I've resolved modifying the config file adding a information
parameter with the default list of ROLE, but this will apply to all admin class defined in the service, and I don't want that, I want define the ROLE for a specific admin class, and also that can appear in the role manager in order to be assigned a user. 我已经解决了修改配置文件的问题,并在其中添加了带有ROLE默认列表的information
参数,但这将适用于服务中定义的所有管理类,但我不想这样做,我想为特定的管理类定义ROLE ,也可以出现在角色管理器中以便分配用户。
Any suggestion is welcome 欢迎任何建议
Thanks for help! 感谢帮助!
These are my configurations: 这些是我的配置:
config.yml 配置文件
#SONATAADMINBUNDLE
sonata_admin:
security:
handler: sonata.admin.security.handler.role
information:
EDIT: EDIT
LIST: LIST
CREATE: CREATE
VIEW: VIEW
DELETE: DELETE
EXPORT: EXPORT
OPERATOR: OPERATOR
MASTER: MASTER
STATUS: STATUS
AdminClass 管理类
//..
use Sonata\AdminBundle\Route\RouteCollection;
class SolicitudMantenimientoAdmin extends Admin
{
//...
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('status',$this->getRouterIdParameter().'/status');
}
}
Service 服务
<service id="sonata.admin.solicitudmantenimiento" class="Minsal\SimBundle\Admin\SolicitudMantenimientoAdmin">
<tag name="sonata.admin" manager_type="orm" group="Solicitud" label="Solicitud Mantenimiento" />
<argument />
<argument>Minsal\SimBundle\Entity\SolicitudMantenimiento</argument>
<argument>MinsalSimBundle:SolicitudMantenimiento</argument>
</service>
Controller 控制者
use Sonata\AdminBundle\Controller\CRUDController;
class SolicitudMantenimientoController extends CRUDController {
//..
public function statusAction() {
//... code here
return new Response('<html><body>Test</body></html>');
}
Finally I solved the problem, I read the documentation deeper ( Role Handler ), I made the next changes in the follow file: 最后,我解决了这个问题,我更深入地阅读了文档( Role Handler ),在跟随文件中进行了以下更改:
security.yml 安全性
I added a new role in the security file, in the role_hierarchy section like the follow: 我在安全文件的role_hierarchy部分中添加了一个新角色 ,如下所示:
security:
role_hierarchy:
ROLE_SONATA_SOLICITUDMANTENIMIENTO:
- ROLE_SONATA_ADMIN_SOLICITUDMANTENIMIENTO_STATUS
When I added the new role, it appeared in the ROLE MANAGER of User CRUD, like the image at the link see image 当我添加新角色时,它出现在User CRUD的ROLE MANAGER中,如链接上的图像所示。
and it works!!!... 它有效!!!! ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.