1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Persons import Person, Persons
5 from PLC.Sites import Site, Sites
6 from PLC.Auth import PasswordAuth
8 class AdmGetPersonSites(Method):
10 Returns the sites that the specified person is associated with as
11 an array of site identifiers.
13 Admins may retrieve details about anyone. Users and techs may only
14 retrieve details about themselves. PIs may retrieve details about
15 themselves and others at their sites.
18 roles = ['admin', 'pi', 'user', 'tech']
22 Mixed(Person.fields['person_id'],
23 Person.fields['email'])
26 returns = [Site.fields['site_id']]
28 def call(self, auth, person_id_or_email):
29 # Get account information
30 persons = Persons(self.api, [person_id_or_email])
32 raise PLCInvalidArgument, "No such account"
34 person = persons.values()[0]
36 # Authenticated function
37 assert self.caller is not None
39 # Check if we can view this account
40 if not self.caller.can_view(person):
41 raise PLCPermissionDenied, "Not allowed to view specified account"
43 return person['site_ids']