I’m working on a plugin that needs to add stuff to the user serializer. It’s working!
But I need to add it to the user serializer only for staff and the current user.
But . . . backing up, perhaps, I really need this information only on the user profile page, so perhaps I need to put it somewhere else?
add_to_serializer(:user, :manager_status) {
# TODO: include only for current user and staff
return object.manager_status
}
I’m currently displaying this on the user profile page. I’d like to know how to create a separate profile page with just this stuff on it. Links to something doing that would be great.
You’d have to create a new route and make sure it’s guarded against anyone but staff and the current user from seeing it. Probably a lot more complex than serializing it where you are.
I’m thinking you can do this via something like so:
add_to_serializer(:user, :manager_status) {
return object.manager_status if object.admin || object.staff
}
Off the top of my head you may have to do a dance to pull in the current user object and check for a match.
add_to_serializer(:post, :user_xxx, false) {
#object.user.custom_fields['xxx'] if object.user && scope.is_admin?
#object.user.custom_fields['xxx'] if object.user && scope.is_moderator?
# Staff will allow for Admins and Moderators
object.user.custom_fields['xxx'] if object.user && scope.is_staff?
}