Skip to content

#461 - Add access control example #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion core/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,29 @@ class Question
}
```

### Access Control of Subresources

The `subresourceOperations` attribute also allows you to add an access control on each path with the attribute `access_control `.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment: you can remove the space in "access_control ".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sorry


```php
<?php
// api/src/Entity/Question.php

/**
* ...
* @ApiResource(
* subresourceOperations={
* "answer_get_subresource"= {
* "method"="GET",
* "access_control"="has_role('ROLE_AUTHENTICATED')"
* }
* }
* )
class Question
{
}
```

### Control the Depth of Subresources

You can control depth of subresources with the parameter `maxDepth`. For example, if `Answer` entity also have subresource
Expand Down Expand Up @@ -663,7 +686,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
class Book
{
//...

/**
* @Groups("special")
*/
Expand Down