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
7 class AdmGetPersonRoles(Method):
9 Deprecated. See GetPersons.
11 Return the roles that the specified person has as a struct:
13 {'10': 'admin', '30': 'user', '20': 'pi', '40': 'tech'}
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
19 Note that because of XML-RPC marshalling limitations, the keys to
20 this struct are string representations of the integer role
26 roles = ['admin', 'pi', 'user', 'tech']
30 Mixed(Person.fields['person_id'],
31 Person.fields['email'])
36 def call(self, auth, person_id_or_email):
37 # Get account information
38 persons = Persons(self.api, [person_id_or_email])
40 raise PLCInvalidArgument, "No such account"
44 # Authenticated function
45 assert self.caller is not None
47 # Check if we can view this account
48 if not self.caller.can_view(person):
49 raise PLCPermissionDenied, "Not allowed to view specified account"
52 role_ids = map(str, person['role_ids'])
53 roles = person['roles']
55 return dict(zip(role_ids, roles))