From: Mark Huang Date: Wed, 11 Oct 2006 15:41:10 +0000 (+0000) Subject: - add mandatory fields to method arguments X-Git-Tag: pycurl-7_13_1~616 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=d4ac4bfce126bc5ad0eee837b8aac0379e684a63;p=plcapi.git - add mandatory fields to method arguments - fix documentation --- diff --git a/PLC/Methods/AddKey.py b/PLC/Methods/AddKey.py index 310165c5..0e2e0d59 100644 --- a/PLC/Methods/AddKey.py +++ b/PLC/Methods/AddKey.py @@ -7,46 +7,43 @@ from PLC.Auth import PasswordAuth class AddKey(Method): """ - Adds a new key for the specified person. If the key already exists, - the call returns successful. + Adds a new key to the specified account. - Non-admin, they can only modify their own keys. + Non-admins can only modify their own keys. Returns the new key_id (> 0) if successful, faults otherwise. """ roles = ['admin', 'pi', 'tech', 'user'] - can_update = lambda (field, value): field in \ - ['key_type', 'key','is_blacklisted', 'is_primary'] - update_fields = dict(filter(can_update, Key.fields.items())) - accepts = [ PasswordAuth(), Mixed(Person.fields['person_id'], Person.fields['email']), - update_fields + Key.fields['key_type'], + Key.fields['key'] ] - returns = Parameter(int, 'New Key_id (> 0) if successful') - - def call(self, auth, person_id_or_email, key_fields = {}): - if filter(lambda field: field not in self.update_fields, key_fields): - raise PLCInvalidArgument, "Invalid field specified" + returns = Parameter(int, 'New key_id (> 0) if successful') + def call(self, auth, person_id_or_email, key_type, key_value): # Get account details persons = Persons(self.api, [person_id_or_email]).values() if not persons: raise PLCInvalidArgument, "No such account" person = persons[0] - #If we are not admin, make sure caller is adding a key to their account + # If we are not admin, make sure caller is adding a key to their account if 'admin' not in self.caller['roles']: - if person['person_id'] not in [self.caller['person_id']]: + if person['person_id'] != self.caller['person_id']: raise PLCPermissionDenied, "You may only modify your own keys" - key = Key(self.api, key_fields) - key.sync() - key.add_person(person) + key = Key(self.api) + key['person_id'] = person['person_id'] + key['key_type'] = key_type + key['key'] = key_value + key.sync(commit = False) + + person.add_key(key, commit = True) return key['key_id']