Skip to content

Commit 0eeebb2

Browse files
authored
Merge pull request #607 from Tim59/FIX-461
#461 - Add access control example
2 parents 7218281 + ed3dcb9 commit 0eeebb2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

core/operations.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,29 @@ class Question
462462
}
463463
```
464464

465+
### Access Control of Subresources
466+
467+
The `subresourceOperations` attribute also allows you to add an access control on each path with the attribute `access_control`.
468+
469+
```php
470+
<?php
471+
// api/src/Entity/Question.php
472+
473+
/**
474+
* ...
475+
* @ApiResource(
476+
* subresourceOperations={
477+
* "answer_get_subresource"= {
478+
* "method"="GET",
479+
* "access_control"="has_role('ROLE_AUTHENTICATED')"
480+
* }
481+
* }
482+
* )
483+
class Question
484+
{
485+
}
486+
```
487+
465488
### Control the Depth of Subresources
466489

467490
You can control depth of subresources with the parameter `maxDepth`. For example, if `Answer` entity also have subresource
@@ -663,7 +686,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
663686
class Book
664687
{
665688
//...
666-
689+
667690
/**
668691
* @Groups("special")
669692
*/

0 commit comments

Comments
 (0)