- allow session key to be specified (for use on nodes)
[plcapi.git] / PLC / Methods / AdmGetPersonRoles.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Persons import Person, Persons
5 from PLC.Auth import Auth
6
7 class AdmGetPersonRoles(Method):
8     """
9     Deprecated. See GetPersons.
10
11     Return the roles that the specified person has as a struct:
12
13     {'10': 'admin', '30': 'user', '20': 'pi', '40': 'tech'}
14
15     Admins can get the roles for any user. PIs can only get the roles
16     for members of their sites. All others may only get their own
17     roles.
18
19     Note that because of XML-RPC marshalling limitations, the keys to
20     this struct are string representations of the integer role
21     identifiers.
22     """
23
24     status = "deprecated"
25
26     roles = ['admin', 'pi', 'user', 'tech']
27
28     accepts = [
29         Auth(),
30         Mixed(Person.fields['person_id'],
31               Person.fields['email'])
32         ]
33
34     returns = dict
35
36     object_type = 'Person'
37
38     def call(self, auth, person_id_or_email):
39         # Get account information
40         persons = Persons(self.api, [person_id_or_email])
41         if not persons:
42             raise PLCInvalidArgument, "No such account"
43
44         person = persons[0]
45
46         # Authenticated function
47         assert self.caller is not None
48
49         # Check if we can view this account
50         if not self.caller.can_view(person):
51             raise PLCPermissionDenied, "Not allowed to view specified account"
52
53         # Stringify the keys!
54         role_ids = map(str, person['role_ids'])
55         roles = person['roles']
56
57         return dict(zip(role_ids, roles))