Skip to content

Commit 585e2b2

Browse files
mikemilanodunglas
authored andcommitted
Added yaml config to security page (#552)
* Added yaml config to security page as indicated in #785. * Corrected method and admin message for collection post example.
1 parent f8d876a commit 585e2b2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

core/security.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,23 @@ class Book
100100
// ...
101101
}
102102
```
103+
104+
Alternatively, using YAML:
105+
106+
```yaml
107+
# api/config/api_platform/resources.yaml
108+
App\Entity\Book:
109+
attributes:
110+
access_control: 'is_granted("ROLE_USER")'
111+
collectionOperations:
112+
post:
113+
method: 'POST'
114+
access_control: 'is_granted("ROLE_ADMIN")'
115+
access_control_message: 'Only admins can add books.'
116+
itemOperations:
117+
get:
118+
method: 'GET'
119+
access_control: 'is_granted("ROLE_USER") and object.owner == user'
120+
access_control_message: 'Sorry, but you are not the book owner.'
121+
# ...
122+
```

0 commit comments

Comments
 (0)