Branch 5.0 for module PLCAPI created from tag PLCAPI-4.2-8
[plcapi.git] / PLC / Methods / AdmGetSitePersons.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Sites import Site, Sites
5 from PLC.Auth import Auth
6
7 class AdmGetSitePersons(Method):
8     """
9     Deprecated. See GetSites.
10
11     Return a list of person_ids for the site specified.
12
13     PIs may only retrieve the person_ids of accounts at their
14     site. Admins may retrieve the person_ids of accounts at any site.
15     """
16
17     status = "deprecated"
18
19     roles = ['admin', 'pi']
20
21     accepts = [
22         Auth(),
23         Mixed(Site.fields['site_id'],
24               Site.fields['login_base'])
25         ]
26
27     returns = Site.fields['person_ids']
28
29     def call(self, auth, site_id_or_login_base):
30         # Authenticated function
31         assert self.caller is not None
32
33         # Get site information
34         sites = Sites(self.api, [site_id_or_login_base])
35         if not sites:
36             raise PLCInvalidArgument, "No such site"
37
38         site = sites[0]
39
40         if 'admin' not in self.caller['roles']: 
41             if site['site_id'] not in self.caller['site_ids']:
42                 raise PLCPermissionDenied, "Not allowed to view accounts at that site"
43
44         return site['person_ids']