- added logging variable 'object_type'
[plcapi.git] / PLC / Methods / UpdatePerson.py
index 4e91a8f..594f1ff 100644 (file)
@@ -2,7 +2,7 @@ from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
+from PLC.Auth import Auth
 
 can_update = lambda (field, value): field in \
              ['first_name', 'last_name', 'title', 'email',
@@ -25,7 +25,7 @@ class UpdatePerson(Method):
     person_fields = dict(filter(can_update, Person.fields.items()))
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
         person_fields
@@ -33,6 +33,8 @@ class UpdatePerson(Method):
 
     returns = Parameter(int, '1 if successful')
 
+    object_type = 'Person'
+
     def call(self, auth, person_id_or_email, person_fields):
         person_fields = dict(filter(can_update, person_fields.items()))
 
@@ -40,8 +42,10 @@ class UpdatePerson(Method):
         persons = Persons(self.api, [person_id_or_email])
         if not persons:
             raise PLCInvalidArgument, "No such account"
+        person = persons[0]
 
-        person = persons.values()[0]
+        if person['peer_id'] is not None:
+            raise PLCInvalidArgument, "Not a local account"
 
         # Authenticated function
         assert self.caller is not None
@@ -52,5 +56,16 @@ class UpdatePerson(Method):
 
         person.update(person_fields)
         person.sync()
+       
+       # Logging variables
+       self.object_ids = [person['person_id']]
+
+        # Redact password
+        if 'password' in person_fields:
+            person_fields['password'] = "Removed by API"
+        self.message = 'Person %d updated: %s.' % \
+                       (person['person_id'], person_fields.keys())
+       if 'enabled' in person_fields:
+            self.message += ' Person enabled'  
 
         return 1