- allow members of slice to delete nodes from slice
[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     Returns the sites that the specified person is associated with as
11     an array of site identifiers.
12
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.
16     """
17
18     roles = ['admin', 'pi', 'user', 'tech']
19
20     accepts = [
21         PasswordAuth(),
22         Mixed(Person.fields['person_id'],
23               Person.fields['email'])
24         ]
25
26     returns = [Site.fields['site_id']]
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']