X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetKeys.py;h=434859f2fe401e5c6a1419be56347562bc6f13e8;hb=1d3540bd2ece27d91a2ec5843628c5fa38a25024;hp=fcbd2b16c2eba9500aa7009e1d0273c69cc154da;hpb=e347fc823bbba9d88a3fddf07d5c21024dfd1e55;p=plcapi.git diff --git a/PLC/Methods/GetKeys.py b/PLC/Methods/GetKeys.py index fcbd2b1..434859f 100644 --- a/PLC/Methods/GetKeys.py +++ b/PLC/Methods/GetKeys.py @@ -2,6 +2,7 @@ from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Filter import Filter +from PLC.Persons import Person, Persons from PLC.Keys import Key, Keys from PLC.Auth import Auth @@ -17,22 +18,24 @@ class GetKeys(Method): keys. """ - roles = ['admin', 'pi', 'user', 'tech'] + roles = ['admin', 'pi', 'user', 'tech', 'node'] accepts = [ Auth(), Mixed([Mixed(Key.fields['key_id'])], Filter(Key.fields)), - Parameter([str], "List of fields to return", nullok = True) + Parameter([str], "List of fields to return", nullok = True) ] returns = [Key.fields] + def call(self, auth, key_filter = None, return_fields = None): - keys = Keys(self.api, key_filter, return_fields) + keys = Keys(self.api, key_filter, return_fields) - # If we are not admin, make sure to only return our own keys - if 'admin' not in self.caller['roles']: - keys = filter(lambda key: key['key_id'] in self.caller['key_ids'], keys) + # If we are not admin, make sure to only return our own keys + if isinstance(self.caller, Person) and \ + 'admin' not in self.caller['roles']: + keys = [key for key in keys if key['key_id'] in self.caller['key_ids']] return keys