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 PasswordAuth
7 class AdmGetPersonRoles(Method):
9 Return the roles that the specified person has as a struct:
11 {'10': 'admin', '30': 'user', '20': 'pi', '40': 'tech'}
13 Admins can get the roles for any user. PIs can only get the roles
14 for members of their sites. All others may only get their own
17 Note that because of XML-RPC marshalling limitations, the keys to
18 this struct are string representations of the integer role
22 roles = ['admin', 'pi', 'user', 'tech']
26 Mixed(Person.fields['person_id'],
27 Person.fields['email'])
32 # Stupid return type, and can get now roles through
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"
42 person = persons.values()[0]
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))