Branch 5.0 for module PLCAPI created from tag PLCAPI-4.2-8
[plcapi.git] / PLC / Methods / AdmGetSiteTechContacts.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.Persons import Person, Persons
6 from PLC.Auth import Auth
7
8 class AdmGetSiteTechContacts(Method):
9     """
10     Deprecated. Functionality can be implemented with GetSites and
11     GetPersons.
12
13     Return a list of person_ids of the technical contacts for the site
14     specified.
15     """
16
17     status = "deprecated"
18
19     roles = ['admin']
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         persons = Persons(self.api, site['person_ids'])
41
42         has_tech_role = lambda person: 'tech' in person['roles']
43         techs = filter(has_tech_role, persons)
44
45         return [tech['person_id'] for tech in techs]