UpdatePerson.py
[plcapi.git] / 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 PasswordAuth
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     accepts = [
21         PasswordAuth(),
22         Mixed(Person.fields['person_id'],
23               Person.fields['email'])
24         ]
25
26     returns = Person.fields['site_ids']
27
28     def call(self, auth, person_id_or_email):
29         # Get account information
30         persons = Persons(self.api, [person_id_or_email])
31         if not persons:
32             raise PLCInvalidArgument, "No such account"
33
34         person = persons.values()[0]
35
36         # Authenticated function
37         assert self.caller is not None
38
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"
42
43         return person['site_ids']