我想知道如何使用 api-platform 保护自定义 itemsOperation,我在文档中找到了以下代码:
/**
* Secured resource.
*
* @ApiResource(
* attributes={"access_control"="is_granted('ROLE_USER')"},
* collectionOperations={
* "get"={"method"="GET"},
* "post"={"method"="POST", "access_control"="is_granted('ROLE_ADMIN')"}
* },
* itemOperations={
* "get"{"method"="GET","access_control"="is_granted('ROLE_USER') and object.owner == user"}
* }
* )
* @ORM\Entity
*/
但我想做类似的事情:
/**
* @ApiResource(itemOperations={
* "get"={"method"="GET"} //Public route,
* "special"={"route_name"="special", "access_control"="is_granted('ROLE_ADMIN') or object.owner == user"}},
* "special2"={"route_name"="special2", "access_control"="is_granted('ROLE_USER')"}
* })
*/
它有效吗?或者我必须检查特殊操作文件中的用户角色?
在这种情况下,最佳做法是什么?