fix roles interface
[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 Role, 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):
23         roles_list = Roles(self.api).values()
24
25         roles_dict = {}
26         for role in roles_list:
27             # Stringify the keys!
28             roles_dict[str(role['role_id'])] = role['name']
29
30         return roles_dict