- if the appropriate message template doesn't exist log error and exit without throwi...
[plcapi.git] / PLC / Methods / AddPersonKey.py
index 3749ecd..6badf39 100644 (file)
@@ -3,7 +3,7 @@ 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 PasswordAuth
+from PLC.Auth import Auth
 
 can_update = lambda (field, value): field not in ['key_id']
 
@@ -21,7 +21,7 @@ class AddPersonKey(Method):
     key_fields = dict(filter(can_update, Key.fields.items()))
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
         key_fields
@@ -29,18 +29,16 @@ class AddPersonKey(Method):
 
     returns = Parameter(int, 'New key_id (> 0) if successful')
 
-    event_type = 'Add'
-    object_type = 'Key'
-    object_ids = []
 
     def call(self, auth, person_id_or_email, key_fields):
         key_fields = dict(filter(can_update, key_fields.items()))
 
         # Get account details
-        persons = Persons(self.api, [person_id_or_email]).values()
+        persons = Persons(self.api, [person_id_or_email])
         if not persons:
             raise PLCInvalidArgument, "No such account"
         person = persons[0]
+       PLCCheckLocalPerson (person,"AddPersonKey")
 
        # If we are not admin, make sure caller is adding a key to their account
         if 'admin' not in self.caller['roles']:
@@ -51,6 +49,9 @@ 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.object_ids = [person['person_id'], key['key_id']]
+       self.message = 'Key %d added to person %d' % \
+               (key['key_id'], person['person_id'])
 
         return key['key_id']