Merge from trunk
[plcapi.git] / trunk / PLC / Methods / AdmGetPersonSites.py
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 Auth
7
8 class AdmGetPersonSites(Method):
9     """
10     Deprecated. See GetPersons.
11
12     Returns the sites that the specified person is associated with as
13     an array of site identifiers.
14
15     Admins may retrieve details about anyone. Users and techs may only
16     retrieve details about themselves. PIs may retrieve details about
17     themselves and others at their sites.
18     """
19
20     status = "deprecated"
21
22     roles = ['admin', 'pi', 'user', 'tech']
23
24     accepts = [
25         Auth(),
26         Mixed(Person.fields['person_id'],
27               Person.fields['email'])
28         ]
29
30     returns = Person.fields['site_ids']
31
32     def call(self, auth, person_id_or_email):
33         # Get account information
34         persons = Persons(self.api, [person_id_or_email])
35         if not persons:
36             raise PLCInvalidArgument, "No such account"
37
38         person = persons[0]
39
40         # Authenticated function
41         assert self.caller is not None
42
43         # Check if we can view this account
44         if not self.caller.can_view(person):
45             raise PLCPermissionDenied, "Not allowed to view specified account"
46
47         return person['site_ids']