+# $Id$
+# $URL$
from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Keys import Key, Keys
from PLC.Persons import Person, Persons
from PLC.Auth import Auth
+from PLC.SFA import SFA
-can_update = lambda (field, value): field not in ['key_id']
+can_update = lambda (field, value): field in ['key_type','key']
class AddPersonKey(Method):
"""
returns = Parameter(int, 'New key_id (> 0) if successful')
- object_type = 'Person'
-
-
def call(self, auth, person_id_or_email, key_fields):
key_fields = dict(filter(can_update, key_fields.items()))
if person['peer_id'] is not None:
raise PLCInvalidArgument, "Not a local account"
- # 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'] != self.caller['person_id']:
raise PLCPermissionDenied, "You may only modify your own keys"
person.add_key(key, commit = True)
# Logging variables
- self.object_ids = [person['person_id'], key['key_id']]
- self.message = 'Key %d added to person %d' % \
- (key['key_id'], person['person_id'])
-
+ self.event_objects = {'Person': [person['person_id']],
+ 'Key': [key['key_id']]}
+ self.message = 'Key %d added to person %d' % \
+ (key['key_id'], person['person_id'])
+
+ # sync with the geni db
+ person['key'] = key_fields['key']
+ sfa = SFA(self.api)
+ sfa.update_record(person, 'user')
+
return key['key_id']