Initial checkin of new API implementation
[plcapi.git] / PLC / Methods / AdmGetAllRoles.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter
4 from PLC.Roles import Roles
5 from PLC.Auth import PasswordAuth
6
7 class AdmGetAllRoles(Method):
8     """
9     Return all possible roles as a struct:
10
11     {'10': 'admin', '20': 'pi', '30': 'user', '40': 'tech'}
12
13     Note that because of XML-RPC marshalling limitations, the keys to
14     this struct are string representations of the integer role
15     identifiers.
16     """
17
18     roles = ['admin', 'pi', 'user', 'tech']
19     accepts = [PasswordAuth()]
20     returns = dict
21
22     def call(self, auth, person_id_or_email_list = None, return_fields = None):
23         roles = Roles(self.api)
24
25         # Just the role_id: name mappings
26         roles = dict(filter(lambda (role_id, name): isinstance(role_id, (int, long)), \
27                             roles.items()))
28
29         # Stringify the keys!
30         keys = map(str, roles.keys())
31
32         return dict(zip(keys, roles.values()))