1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: roundupdb.py,v 1.43 2002-02-14 22:33:15 richard Exp $
18+ # $Id: roundupdb.py,v 1.44 2002-02-15 07:08:44 richard Exp $
1919
2020__doc__ = """
2121Extending hyperdb with types specific to issue-tracking.
@@ -42,6 +42,23 @@ def splitDesignator(designator, dre=re.compile(r'([^\d]+)(\d+)')):
4242 return m .group (1 ), m .group (2 )
4343
4444
45+ def extractUserFromList (users ):
46+ '''Given a list of users, try to extract the first non-anonymous user
47+ and return that user, otherwise return None
48+ '''
49+ if len (users ) > 1 :
50+ # make sure we don't match the anonymous or admin user
51+ for user in users :
52+ if user == '1' : continue
53+ if self .user .get (user , 'username' ) == 'anonymous' : continue
54+ # first valid match will do
55+ return user
56+ # well, I guess we have no choice
57+ return user [0 ]
58+ elif users :
59+ return users [0 ]
60+ return None
61+
4562class Database :
4663 def getuid (self ):
4764 """Return the id of the "user" node associated with the user
@@ -54,26 +71,25 @@ def uidFromAddress(self, address, create=1):
5471 user is created if they don't exist in the db already
5572 '''
5673 (realname , address ) = address
57- users = self . user . stringFind ( address = address )
58- for dummy in range ( 2 ):
59- if len ( users ) > 1 :
60- # make sure we don't match the anonymous or admin user
61- for user in users :
62- if user == '1' : continue
63- if self .user .get ( user , 'username' ) == 'anonymous' : continue
64- # first valid match will do
65- return user
66- # well, I guess we have no choice
67- return user [ 0 ]
68- elif users :
69- return users [ 0 ]
70- # try to match the username to the address (for local
71- # submissions where the address is empty)
72- users = self .user .stringFind (username = address )
74+
75+ # try a straight match of the address
76+ user = extractUserFromList ( self . user . stringFind ( address = address ))
77+ if user is not None : return user
78+
79+ # try the user alternate addresses if possible
80+ props = self .user .getprops ()
81+ if props . has_key ( 'alternate_addresses' ):
82+ users = self . user . filter ({ 'alternate_addresses' : address },
83+ [], [])
84+ user = extractUserFromList ( users )
85+ if user is not None : return user
86+
87+ # try to match the username to the address (for local
88+ # submissions where the address is empty)
89+ user = extractUserFromList ( self .user .stringFind (username = address ) )
7390
7491 # couldn't match address or username, so create a new user
7592 if create :
76- print 'CREATING USER' , address
7793 return self .user .create (username = address , address = address ,
7894 realname = realname )
7995 else :
@@ -571,6 +587,9 @@ def generateChangeNote(self, nodeid, oldvalues):
571587
572588#
573589# $Log: not supported by cvs2svn $
590+ # Revision 1.43 2002/02/14 22:33:15 richard
591+ # . Added a uniquely Roundup header to email, "X-Roundup-Name"
592+ #
574593# Revision 1.42 2002/01/21 09:55:14 rochecompaan
575594# Properties in change note are now sorted
576595#
0 commit comments