+ # only persons can call this (as per roles, but..)
+ if not isinstance(self.caller,Person):
+ return []
+
+ # If we are not admin, make sure to only return viewable accounts
+ valid_person_ids=None
+ added_fields=[]
+ if 'admin' not in self.caller['roles']:
+ # Get accounts that we are able to view
+ valid_person_ids = [self.caller['person_id']]
+ if 'pi' in self.caller['roles'] and self.caller['site_ids']:
+ sites = Sites(self.api, self.caller['site_ids'])
+ for site in sites:
+ valid_person_ids += site['person_ids']
+
+ if not valid_person_ids:
+ return []
+
+ # if we have to filter out on person_id, make sure this is returned from db
+ if return_fields:
+ added_fields = set(['person_id']).difference(return_fields)
+ return_fields += added_fields
+