I want to know how to secure custom itemsOperation with api-platform, I found this code on documentation:
/**
* 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
*/
But I want to do something like:
/**
* @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')"}
* })
*/
Does it work? Or I have to check user roles in special Action file?
What is the best practice in this case?