- # Make sure that only valid fields are specified
- if return_fields is None:
- return_fields = self.return_fields
- elif filter(lambda field: field not in self.return_fields, return_fields):
- raise PLCInvalidArgument, "Invalid return field specified"
-
- # Authenticated function
- assert self.caller is not None
-
- # Only admins can not specify person_id_or_email_list or
- # specify an empty list.
- if not person_id_or_email_list and 'admin' not in self.caller['roles']:
- raise PLCInvalidArgument, "List of accounts to retrieve not specified"
-
- # Get account information
- persons = Persons(self.api, person_id_or_email_list)
-
- # Filter out accounts that are not viewable and turn into list
- persons = filter(self.caller.can_view, persons.values())
-
- # Filter out undesired or None fields (XML-RPC cannot marshal
- # None) and turn each person into a real dict.
- valid_return_fields_only = lambda (key, value): \
- key in return_fields and value is not None
- persons = [dict(filter(valid_return_fields_only, person.items())) \
- for person in persons]
-
- return persons