Initial checkin of new API implementation
[plcapi.git] / PLC / Methods / AdmGetSitePersons.py
1 import os
2
3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Sites import Site, Sites
7 from PLC.Auth import PasswordAuth
8
9 class AdmGetSitePersons(Method):
10     """
11     Return a list of person_ids for the site specified.
12
13     Admins may retrieve person_ids at any site by not specifying
14     site_id_or_name or by specifying an empty list. PIs may only retrieve 
15     the person_ids at their site
16
17     """
18
19     roles = ['admin', 'pi']
20
21     accepts = [
22         PasswordAuth(),
23         Site.fields['site_id']
24         ]
25
26     returns = [Site.all_fields['person_ids']]
27
28     def call(self, auth, site_id):
29         # Authenticated function
30         assert self.caller is not None
31
32         # Get site information
33         sites = Sites(self.api, [site_id], ['person_ids']).values()     
34
35         # make sure sites are found
36         if not sites:
37                 raise PLCInvalidArgument, "No such site"
38         site = sites[0]
39         if 'admin' not in self.caller['roles']: 
40                 if site['site_id'] not in self.caller['site_ids']:
41                         raise PLCPermissionDenied, "Not allowed to update node network"
42                 if 'pi' not in self.caller['roles']:
43                         raise PLCPermissionDenied, "User account not allowed to update node network"    
44         person_ids = site['person_ids']
45        
46         return person_ids