comparison roundup/roundupdb.py @ 905:502a5ae11cc5

Very close now. The cgi and mailgw now use the new security API. The two templates have been migrated to that setup. Lots of unit tests. Still some issue in the web form for editing Roles assigned to users.
author Richard Jones <richard@users.sourceforge.net>
date Fri, 26 Jul 2002 08:27:00 +0000
parents 2dd862af72ee
children 9b910e8d987d
comparison
equal deleted inserted replaced
904:02763530b9e8 905:502a5ae11cc5
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 # $Id: roundupdb.py,v 1.62 2002-07-14 02:05:53 richard Exp $ 18 # $Id: roundupdb.py,v 1.63 2002-07-26 08:26:59 richard Exp $
19 19
20 __doc__ = """ 20 __doc__ = """
21 Extending hyperdb with types specific to issue-tracking. 21 Extending hyperdb with types specific to issue-tracking.
22 """ 22 """
23 23
34 34
35 # set to indicate to roundup not to actually _send_ email 35 # set to indicate to roundup not to actually _send_ email
36 # this var must contain a file to write the mail to 36 # this var must contain a file to write the mail to
37 SENDMAILDEBUG = os.environ.get('SENDMAILDEBUG', '') 37 SENDMAILDEBUG = os.environ.get('SENDMAILDEBUG', '')
38 38
39
40 def extractUserFromList(userClass, users):
41 '''Given a list of users, try to extract the first non-anonymous user
42 and return that user, otherwise return None
43 '''
44 if len(users) > 1:
45 # make sure we don't match the anonymous or admin user
46 for user in users:
47 if user == '1': continue
48 if userClass.get(user, 'username') == 'anonymous': continue
49 # first valid match will do
50 return user
51 # well, I guess we have no choice
52 return user[0]
53 elif users:
54 return users[0]
55 return None
56
57 class Database: 39 class Database:
58 def getuid(self): 40 def getuid(self):
59 """Return the id of the "user" node associated with the user 41 """Return the id of the "user" node associated with the user
60 that owns this connection to the hyperdatabase.""" 42 that owns this connection to the hyperdatabase."""
61 return self.user.lookup(self.journaltag) 43 return self.user.lookup(self.journaltag)
62
63 def uidFromAddress(self, address, create=1):
64 ''' address is from the rfc822 module, and therefore is (name, addr)
65
66 user is created if they don't exist in the db already
67 '''
68 (realname, address) = address
69
70 # try a straight match of the address
71 user = extractUserFromList(self.user,
72 self.user.stringFind(address=address))
73 if user is not None: return user
74
75 # try the user alternate addresses if possible
76 props = self.user.getprops()
77 if props.has_key('alternate_addresses'):
78 users = self.user.filter(None, {'alternate_addresses': address},
79 [], [])
80 user = extractUserFromList(self.user, users)
81 if user is not None: return user
82
83 # try to match the username to the address (for local
84 # submissions where the address is empty)
85 user = extractUserFromList(self.user,
86 self.user.stringFind(username=address))
87
88 # couldn't match address or username, so create a new user
89 if create:
90 return self.user.create(username=address, address=address,
91 realname=realname)
92 else:
93 return 0
94 44
95 class MessageSendError(RuntimeError): 45 class MessageSendError(RuntimeError):
96 pass 46 pass
97 47
98 class DetectorError(RuntimeError): 48 class DetectorError(RuntimeError):
474 m.insert(0, '') 424 m.insert(0, '')
475 return '\n'.join(m) 425 return '\n'.join(m)
476 426
477 # 427 #
478 # $Log: not supported by cvs2svn $ 428 # $Log: not supported by cvs2svn $
429 # Revision 1.62 2002/07/14 02:05:53 richard
430 # . all storage-specific code (ie. backend) is now implemented by the backends
431 #
479 # Revision 1.61 2002/07/09 04:19:09 richard 432 # Revision 1.61 2002/07/09 04:19:09 richard
480 # Added reindex command to roundup-admin. 433 # Added reindex command to roundup-admin.
481 # Fixed reindex on first access. 434 # Fixed reindex on first access.
482 # Also fixed reindexing of entries that change. 435 # Also fixed reindexing of entries that change.
483 # 436 #

Roundup Issue Tracker: http://roundup-tracker.org/