rename flush() to sync(), removed {default,all,join}_fields
[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 PasswordAuth
6
7 class AdmGetSitePersons(Method):
8     """
9     Return a list of person_ids for the site specified.
10
11     PIs may only retrieve the person_ids of accounts at their
12     site. Admins may retrieve the person_ids of accounts at any site.
13     """
14
15     roles = ['admin', 'pi']
16
17     accepts = [
18         PasswordAuth(),
19         Mixed(Site.fields['site_id'],
20               Site.fields['login_base'])
21         ]
22
23     returns = Site.fields['person_ids']
24
25     def call(self, auth, site_id_or_login_base):
26         # Authenticated function
27         assert self.caller is not None
28
29         # Get site information
30         sites = Sites(self.api, [site_id_or_login_base], ['person_ids']).values()
31         if not sites:
32             raise PLCInvalidArgument, "No such site"
33
34         site = sites[0]
35
36         if 'admin' not in self.caller['roles']: 
37             if site['site_id'] not in self.caller['site_ids']:
38                 raise PLCPermissionDenied, "Not allowed to view accounts at that site"
39
40         return site['person_ids']