Merge from HEAD. Signed off by tmack.
[plcapi.git] / PLC / Methods / AdmGetPersonKeys.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.Keys import Key, Keys
6 from PLC.Auth import Auth
7 from PLC.Methods.GetKeys import GetKeys
8
9 class AdmGetPersonKeys(GetKeys):
10     """
11     Deprecated. Functionality can be implemented with GetPersons and
12     GetKeys.
13     """
14
15     status = "deprecated"
16
17     roles = ['admin', 'pi', 'user', 'tech']
18
19     accepts = [
20         Auth(),
21         Mixed(Person.fields['person_id'],
22               Person.fields['email']),
23         [Key.fields['key_id']]
24         ]
25
26     returns = [Key.fields]
27
28     def call(self, auth, person_id_or_email):
29         # Get account information
30         persons = Persons(self.api, [person_id_or_email])
31         if not persons:
32             raise PLCInvalidArgument, "No such account"
33
34         person = persons[0]
35
36         if 'admin' not in self.caller['roles']:
37             if self.caller['person_id'] != person['person_id']:
38                 raise PLCPermissionDenied, "Not allowed to view keys for specified account"
39
40         return GetKeys.call(self, auth, person['key_ids'])