more compatibility functions
[plcapi.git] / PLC / Methods / AdmGetPersonKeys.py
1 from PLC.Methods.GetKeys import GetKeys
2
3 class AdmGetPersonKeys(GetKeys):
4     """
5     Deprecated. Functionality can be implemented with GetPersons and
6     GetKeys.
7     """
8
9     status = "deprecated"
10
11     roles = ['admin', 'pi', 'user', 'tech']
12
13     accepts = [
14         PasswordAuth(),
15         Mixed(Person.fields['person_id'],
16               Person.fields['email']),
17         [Key.fields['key_id']]
18         ]
19
20     returns = [Key.fields]
21
22     def call(auth, person_id_or_email):
23         # Get account information
24         persons = Persons(self.api, [person_id_or_email])
25         if not persons:
26             raise PLCInvalidArgument, "No such account"
27
28         person = persons.values()[0]
29
30         if 'admin' not in self.caller['roles']:
31             if self.caller['person_id'] != person['person_id']:
32                 raise PLCPermissionDenied, "Not allowed to view keys for specified account"
33
34         return GetKeys.call(self, auth, person['key_ids'])