- added logging variable 'object_type'
[plcapi.git] / PLC / Methods / UpdatePerson.py
index 7f769f5..594f1ff 100644 (file)
@@ -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,9 +42,11 @@ class UpdatePerson(Method):
         persons = Persons(self.api, [person_id_or_email])
         if not persons:
             raise PLCInvalidArgument, "No such account"
-
         person = persons[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