svn keywords
[plcapi.git] / PLC / Methods / AddPersonKey.py
index a06ea06..cdf0235 100644 (file)
@@ -1,3 +1,5 @@
+# $Id$
+# $URL$
 from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
@@ -5,7 +7,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']
 
 class AddPersonKey(Method):
     """
@@ -29,7 +31,6 @@ class AddPersonKey(Method):
 
     returns = Parameter(int, 'New key_id (> 0) if successful')
 
-
     def call(self, auth, person_id_or_email, key_fields):
         key_fields = dict(filter(can_update, key_fields.items()))
 
@@ -38,7 +39,9 @@ class AddPersonKey(Method):
         if not persons:
             raise PLCInvalidArgument, "No such account"
         person = persons[0]
-       PLCCheckLocalPerson (person,"AddPersonKey")
+
+        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 'admin' not in self.caller['roles']:
@@ -49,6 +52,10 @@ class AddPersonKey(Method):
         key.sync(commit = False)
         person.add_key(key, commit = True)
 
-        self.object_ids = [person['person_id'], key['key_id']]
+        # Logging variables
+       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'])
 
         return key['key_id']