- updated with Thierrys patch which handles conflicting email addresses between peers
[plcapi.git] / PLC / Persons.py
index e7057f1..32549cf 100644 (file)
@@ -4,7 +4,7 @@
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: Persons.py,v 1.33 2007/01/16 17:05:41 mlhuang Exp $
+# $Id: Persons.py,v 1.36 2007/03/29 20:14:46 tmack Exp $
 #
 
 from types import StringTypes
@@ -100,8 +100,15 @@ class Person(Row):
         if len(domain) < 2:
             raise invalid_email
 
-        conflicts = Persons(self.api, [email])
-        for person in conflicts:
+               # check only against users on the same peer  
+       if 'peer_id' in self:
+            namespace_peer_id = self['peer_id']
+        else:
+            namespace_peer_id = None
+         
+       conflicts = Persons(self.api, {'email':email,'peer_id':namespace_peer_id}) 
+       
+       for person in conflicts:
             if 'person_id' not in self or self['person_id'] != person['person_id']:
                 raise PLCInvalidArgument, "E-mail address already in use"
 
@@ -246,8 +253,7 @@ class Persons(Table):
                           'slice_ids': ('slice_id', 'slice_person')
                           }
        foreign_keys = {}
-       db_fields = Person(api, Person.fields).db_fields().keys() + \
-                   ['last_updated', 'date_created', 'password', 'verification_key', 'verification_expires']
+       db_fields = filter(lambda field: field not in foreign_fields.keys(), Person.fields.keys())
        all_fields = db_fields + [value[0] for value in foreign_fields.values()]
        fields = []
        _select = "SELECT "
@@ -288,7 +294,7 @@ class Persons(Table):
        
        # postgres will return timestamps as datetime objects. 
        # XMLPRC cannot marshal datetime so convert to int
-       timestamps = ['date_created', 'last_updated']
+       timestamps = ['date_created', 'last_updated', 'verification_expires']
        for field in fields:
            if field in timestamps:
                fields[fields.index(field)] = \