Fix KeyTypes, Keys
[plcapi.git] / PLC / Methods / AddPersonKey.py
index 0bba3a1..2c3fb9d 100644 (file)
@@ -5,7 +5,7 @@ from PLC.Keys import Key, Keys
 from PLC.Persons import Person, Persons
 from PLC.Auth import Auth
 
-can_update = lambda (field, value): field not in ['key_id']
+can_update = lambda (field, value): field in ['key_type', 'key', 'key_id']
 
 class AddPersonKey(Method):
     """
@@ -27,10 +27,7 @@ class AddPersonKey(Method):
         key_fields
         ]
 
-    returns = Parameter(int, 'New key_id (> 0) if successful')
-
-    object_type = 'Person'
-
+    returns = Parameter(str, 'The key_id')
 
     def call(self, auth, person_id_or_email, key_fields):
         key_fields = dict(filter(can_update, key_fields.items()))
@@ -44,18 +41,14 @@ class AddPersonKey(Method):
         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"
 
+        key_fields['person_id'] = person['person_id']
         key = Key(self.api, key_fields)
-        key.sync(commit = False)
-        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'])
+        key.sync()
+        #person.add_key(key, commit = True)
 
         return key['key_id']