如何在子资源操作中正确定义访问控制和大范围上下文?

时间:2019-05-28 06:12:27

标签: symfony4 api-platform.com

我正在使用实体中的注释设置子资源操作。我尝试使用“ access_control”和“ swagger_context”,但忽略了我。

/**
 * @ORM\Entity
 *
 * @ApiResource(
 *     attributes={"access_control"="is_granted('ROLE_API')"},
 *     normalizationContext={"groups"={"company", "company:read"}},
 *     denormalizationContext={"groups"={"company", "company:write"}},
 *     collectionOperations={
 *         "get" = {"access_control"="is_granted('ROLE_SUPER_ADMIN')"},
 *         "post" = {"access_control"="is_granted('ROLE_SUPER_ADMIN')"}
 *     },
 *     itemOperations={
 *         "get"={ "access_control"="is_granted('view', object)" },
 *         "put"={ "access_control"="is_granted('edit', object)" },
 *         "delete"={"access_control"="is_granted('ROLE_SUPER_ADMIN')"}
 *     },
 *     subresourceOperations={
 *         "api_eolo_companies_eolo_users_get_subresource"={
 *               "method"="GET",
 *               "access_control"="has_role('ROLE_COMPANY')",
 *               "swagger_context"={ "summary" = "Get Users by Company",
 *                                  "responses"={ 200 ={"description"="OK"}},
 *              },
 *          },
 *     }
 * )
 */

class EoloCompany {

        //..

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="company", orphanRemoval=true)
     * @Groups({"company:read"})
     * @ApiSubresource()
     */
    private $users;
}

我想在开放的api(swagger)文档中添加如下内容:

GET /api/eolo_companies/{id}/users Get Users by Company.

但是,我得到的是默认文字。

GET  /api/eolo_companies/{id}/users Retrieves the collection of User resources.

此外,访问控制不起作用。

0 个答案:

没有答案