Skip to content

Commit 1000f7b

Browse files
author
Richard Jones
committed
On second thought, that last checkin was dumb.
The old, nasty, for-purely-historical-reasons journaltag-as-username has gone away now. The code should handle existing journaltag-as-username entries, but will use userid from now on.
1 parent f42afc7 commit 1000f7b

File tree

7 files changed

+106
-74
lines changed

7 files changed

+106
-74
lines changed

roundup/backends/back_anydbm.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.82 2002-09-20 01:20:31 richard Exp $
18+
#$Id: back_anydbm.py,v 1.83 2002-09-20 05:08:00 richard Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in a database
2121
chosen by anydbm. It is guaranteed to always be available in python
@@ -73,11 +73,21 @@ def __init__(self, config, journaltag=None):
7373
os.umask(0002)
7474

7575
def post_init(self):
76-
'''Called once the schema initialisation has finished.'''
76+
''' Called once the schema initialisation has finished.
77+
'''
7778
# reindex the db if necessary
7879
if self.indexer.should_reindex():
7980
self.reindex()
8081

82+
# figure the "curuserid"
83+
if self.journaltag is None:
84+
self.curuserid = None
85+
elif self.journaltag == 'admin':
86+
# admin user may not exist, but always has ID 1
87+
self.curuserid = '1'
88+
else:
89+
self.curuserid = self.user.lookup(self.journaltag)
90+
8191
def reindex(self):
8292
for klass in self.classes.values():
8393
for nodeid in klass.list():
@@ -237,11 +247,13 @@ def addnode(self, classname, nodeid, node):
237247
if __debug__:
238248
print >>hyperdb.DEBUG, 'addnode', (self, classname, nodeid, node)
239249

240-
# add in the "calculated" properties (dupe so we don't affect
241-
# calling code's node assumptions)
242-
node = node.copy()
243-
node['creator'] = self.journaltag
244-
node['creation'] = node['activity'] = date.Date()
250+
# we'll be supplied these props if we're doing an import
251+
if not node.has_key('creator'):
252+
# add in the "calculated" properties (dupe so we don't affect
253+
# calling code's node assumptions)
254+
node = node.copy()
255+
node['creator'] = self.curuserid
256+
node['creation'] = node['activity'] = date.Date()
245257

246258
self.newnodes.setdefault(classname, {})[nodeid] = 1
247259
self.cache.setdefault(classname, {})[nodeid] = node
@@ -631,7 +643,7 @@ def doSaveJournal(self, classname, nodeid, action, params, creator,
631643
if creator:
632644
journaltag = creator
633645
else:
634-
journaltag = self.journaltag
646+
journaltag = self.curuserid
635647
if creation:
636648
journaldate = creation.serialise()
637649
else:
@@ -949,7 +961,10 @@ def import_list(self, propnames, proplist):
949961
value = pwd
950962
d[propname] = value
951963

952-
# extract the extraneous journalling gumpf and nuke it
964+
# add the node and journal
965+
self.db.addnode(self.classname, newid, d)
966+
967+
# extract the journalling stuff and nuke it
953968
if d.has_key('creator'):
954969
creator = d['creator']
955970
del d['creator']
@@ -963,8 +978,6 @@ def import_list(self, propnames, proplist):
963978
if d.has_key('activity'):
964979
del d['activity']
965980

966-
# add the node and journal
967-
self.db.addnode(self.classname, newid, d)
968981
self.db.addjournal(self.classname, newid, 'create', d, creator,
969982
creation)
970983
return newid
@@ -1020,9 +1033,19 @@ def get(self, nodeid, propname, default=_marker, cache=1):
10201033
raise ValueError, 'Journalling is disabled for this class'
10211034
journal = self.db.getjournal(self.classname, nodeid)
10221035
if journal:
1023-
return self.db.getjournal(self.classname, nodeid)[0][2]
1036+
num_re = re.compile('^\d+$')
1037+
value = self.db.getjournal(self.classname, nodeid)[0][2]
1038+
if num_re.match(value):
1039+
return value
1040+
else:
1041+
# old-style "username" journal tag
1042+
try:
1043+
return self.db.user.lookup(value)
1044+
except KeyError:
1045+
# user's been retired, return admin
1046+
return '1'
10241047
else:
1025-
return self.db.journaltag
1048+
return self.db.curuserid
10261049

10271050
# get the property (raises KeyErorr if invalid)
10281051
prop = self.properties[propname]
@@ -1779,9 +1802,7 @@ def getprops(self, protected=1):
17791802
d['id'] = String()
17801803
d['creation'] = hyperdb.Date()
17811804
d['activity'] = hyperdb.Date()
1782-
# can't be a link to user because the user might have been
1783-
# retired since the journal entry was created
1784-
d['creator'] = hyperdb.String()
1805+
d['creator'] = hyperdb.Link('user')
17851806
return d
17861807

17871808
def addprop(self, **properties):

roundup/backends/back_metakit.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ def reindex(self):
4848
# --- defined in ping's spec
4949
def __getattr__(self, classname):
5050
if classname == 'curuserid':
51+
if self.journaltag is None:
52+
return None
53+
5154
try:
5255
self.curuserid = x = int(self.classes['user'].lookup(self.journaltag))
5356
except KeyError:
54-
x = 0
57+
if self.journaltag == 'admin':
58+
self.curuserid = x = 1
59+
else:
60+
x = 0
5561
return x
5662
elif classname == 'transactions':
5763
return self.dirty
@@ -194,7 +200,7 @@ def __init__(self, db, classname, **properties):
194200
self.privateprops = { 'id' : hyperdb.String(),
195201
'activity' : hyperdb.Date(),
196202
'creation' : hyperdb.Date(),
197-
'creator' : hyperdb.String() }
203+
'creator' : hyperdb.Link('user') }
198204
self.auditors = {'create': [], 'set': [], 'retire': []} # event -> list of callables
199205
self.reactors = {'create': [], 'set': [], 'retire': []} # ditto
200206
view = self.__getview()
@@ -291,7 +297,7 @@ def set(self, nodeid, **propvalues):
291297
if propvalues.has_key('id'):
292298
raise KeyError, '"id" is reserved'
293299
if self.db.journaltag is None:
294-
raise DatabaseError, 'Database open read-only'
300+
raise hyperdb.DatabaseError, 'Database open read-only'
295301
view = self.getview(1)
296302
# node must exist & not be retired
297303
id = int(nodeid)
@@ -341,7 +347,7 @@ def set(self, nodeid, **propvalues):
341347
# must be a string or None
342348
if value is not None and not isinstance(value, type('')):
343349
raise ValueError, 'property "%s" link value be a string'%(
344-
propname)
350+
key)
345351
# Roundup sets to "unselected" by passing None
346352
if value is None:
347353
value = 0

roundup/backends/rdbms_common.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.8 2002-09-20 01:48:34 richard Exp $
1+
# $Id: rdbms_common.py,v 1.9 2002-09-20 05:08:00 richard Exp $
22

33
# standard python modules
44
import sys, os, time, re, errno, weakref, copy
@@ -115,6 +115,15 @@ def post_init(self):
115115
# commit
116116
self.conn.commit()
117117

118+
# figure the "curuserid"
119+
if self.journaltag is None:
120+
self.curuserid = None
121+
elif self.journaltag == 'admin':
122+
# admin user may not exist, but always has ID 1
123+
self.curuserid = '1'
124+
else:
125+
self.curuserid = self.user.lookup(self.journaltag)
126+
118127
def reindex(self):
119128
for klass in self.classes.values():
120129
for nodeid in klass.list():
@@ -461,7 +470,7 @@ def addnode(self, classname, nodeid, node):
461470
# add the special props
462471
node = node.copy()
463472
node['creation'] = node['activity'] = date.Date()
464-
node['creator'] = self.journaltag
473+
node['creator'] = self.curuserid
465474

466475
# default the non-multilink columns
467476
for col, prop in cl.properties.items():
@@ -769,7 +778,7 @@ def addjournal(self, classname, nodeid, action, params, creator=None,
769778
if creator:
770779
journaltag = creator
771780
else:
772-
journaltag = self.journaltag
781+
journaltag = self.curuserid
773782
if creation:
774783
journaldate = creation.serialise()
775784
else:
@@ -1199,7 +1208,7 @@ def get(self, nodeid, propname, default=_marker, cache=1):
11991208
if d.has_key('creator'):
12001209
return d['creator']
12011210
else:
1202-
return self.db.journaltag
1211+
return self.db.curuserid
12031212

12041213
# get the property (raises KeyErorr if invalid)
12051214
prop = self.properties[propname]
@@ -1788,7 +1797,7 @@ def getprops(self, protected=1):
17881797
d['id'] = String()
17891798
d['creation'] = hyperdb.Date()
17901799
d['activity'] = hyperdb.Date()
1791-
d['creator'] = hyperdb.String()
1800+
d['creator'] = hyperdb.Link('user')
17921801
return d
17931802

17941803
def addprop(self, **properties):

0 commit comments

Comments
 (0)