I'm currently using FOSRESTBundle with JMSSerialize to make a RESTFull API (of course).
My project is an extranet for customers and administrators.
In this way, I have to disable some field from being viewed by customer, only visible for administrators.
I started by made this serializer configuration for an entity:
AppBundle\Entity\IncidentComment:
exclusion_policy: ALL
properties:
id:
expose: true
groups: [list, details]
author:
expose: true
groups: [list, details]
addedAt:
expose: true
groups: [list, details]
content:
expose: true
groups: [details]
customerVisible:
expose: true
groups: [list_admin, details_admin]
As you can see, customerVisible
groups have _admin
suffix. This field should be shown only for administrators.
I want to dynamically add groups with _admin
suffix to set groups on views if user has, for example, a ROLE_ADMIN role or another condition without write it on each action of each rest controllers.
I was thinking about create a custom view handler with security context argument to add group, but I don't know if is the proper way.
Do you think is the good way? Have you any suggestions about it?
Btw, if some dev had the same problematic, I will be glad to here how he solved it! :)
Thanks.