Skip to content

Commit ecf55fe

Browse files
author
Johannes Gijsbers
committed
Use getuid(), not figure_curuserid()
- Extended getuid() to replace figure_curuserid(). - Replace all references to curuserid with calls to getuid(). - Changed the docs to point to always point to getuid() and mention the change in upgrading.txt.
1 parent 34332a7 commit ecf55fe

File tree

9 files changed

+37
-56
lines changed

9 files changed

+37
-56
lines changed

doc/customizing.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.96 $
5+
:Version: $Revision: 1.97 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx
@@ -1635,7 +1635,7 @@ you want access to the "user" class, for example, you would use::
16351635
python:db.user
16361636

16371637
Also, the current id of the current user is available as
1638-
``db.curuserid``. This isn't so useful in templates (where you have
1638+
``db.getuid()``. This isn't so useful in templates (where you have
16391639
``request/user``), but it can be useful in detectors or interfaces.
16401640

16411641
The access results in a `hyperdb class wrapper`_.

doc/design.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,6 @@ Here is the interface provided by the hyperdatabase::
292292
class Database:
293293
"""A database for storing records containing flexible data
294294
types.
295-
296-
The id of the current user is available on the database as
297-
'self.curuserid'.
298295
"""
299296

300297
def __init__(self, config, journaltag=None):

doc/upgrading.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ accordingly.
77

88
.. contents::
99

10+
Migrating from 0.6 to 0.7
11+
=========================
12+
13+
0.7.0 Getting the current user id
14+
---------------------------------
15+
16+
Removed Database.curuserid attribute. Any code referencing this attribute should
17+
be replaced with a call to Database.getuid().
18+
19+
1020
Migrating from 0.5 to 0.6
1121
=========================
1222

roundup/backends/back_anydbm.py

Lines changed: 5 additions & 6 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.126 2003-09-06 20:01:10 jlgijsbers Exp $
18+
#$Id: back_anydbm.py,v 1.127 2003-09-08 20:39:18 jlgijsbers 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
@@ -87,7 +87,6 @@ def post_init(self):
8787
# reindex the db if necessary
8888
if self.indexer.should_reindex():
8989
self.reindex()
90-
self.figure_curuserid()
9190

9291
def reindex(self):
9392
for klass in self.classes.values():
@@ -243,7 +242,7 @@ def addnode(self, classname, nodeid, node):
243242
# add in the "calculated" properties (dupe so we don't affect
244243
# calling code's node assumptions)
245244
node = node.copy()
246-
node['creator'] = self.curuserid
245+
node['creator'] = self.getuid()
247246
node['creation'] = node['activity'] = date.Date()
248247

249248
self.newnodes.setdefault(classname, {})[nodeid] = 1
@@ -489,7 +488,7 @@ def getjournal(self, classname, nodeid):
489488
cache_creator, cache_creation) = args
490489
if cache_classname == classname and cache_nodeid == nodeid:
491490
if not cache_creator:
492-
cache_creator = self.curuserid
491+
cache_creator = self.getuid()
493492
if not cache_creation:
494493
cache_creation = date.Date()
495494
res.append((cache_nodeid, cache_creation, cache_creator,
@@ -636,7 +635,7 @@ def doSaveJournal(self, classname, nodeid, action, params, creator,
636635
if creator:
637636
journaltag = creator
638637
else:
639-
journaltag = self.curuserid
638+
journaltag = self.getuid()
640639
if creation:
641640
journaldate = creation.serialise()
642641
else:
@@ -1056,7 +1055,7 @@ def get(self, nodeid, propname, default=_marker, cache=1):
10561055
# user's been retired, return admin
10571056
return '1'
10581057
else:
1059-
return self.db.curuserid
1058+
return self.db.getuid()
10601059

10611060
# get the property (raises KeyErorr if invalid)
10621061
prop = self.properties[propname]

roundup/backends/back_bsddb.py

Lines changed: 2 additions & 2 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_bsddb.py,v 1.26 2003-05-09 01:47:50 richard Exp $
18+
#$Id: back_bsddb.py,v 1.27 2003-09-08 20:39:18 jlgijsbers Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in BSDDB.
2121
'''
@@ -93,7 +93,7 @@ def getjournal(self, classname, nodeid):
9393
cache_creator, cache_creation) = args
9494
if cache_classname == classname and cache_nodeid == nodeid:
9595
if not cache_creator:
96-
cache_creator = self.curuserid
96+
cache_creator = self.getuid()
9797
if not cache_creation:
9898
cache_creation = date.Date()
9999
res.append((cache_nodeid, cache_creation, cache_creator,

roundup/backends/back_bsddb3.py

Lines changed: 2 additions & 2 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_bsddb3.py,v 1.19 2003-05-09 01:47:50 richard Exp $
18+
#$Id: back_bsddb3.py,v 1.20 2003-09-08 20:39:18 jlgijsbers Exp $
1919
'''
2020
This module defines a backend that saves the hyperdatabase in BSDDB3.
2121
'''
@@ -93,7 +93,7 @@ def getjournal(self, classname, nodeid):
9393
cache_creator, cache_creation) = args
9494
if cache_classname == classname and cache_nodeid == nodeid:
9595
if not cache_creator:
96-
cache_creator = self.curuserid
96+
cache_creator = self.getuid()
9797
if not cache_creation:
9898
cache_creation = date.Date()
9999
res.append((cache_nodeid, cache_creation, cache_creator,

roundup/backends/back_metakit.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_metakit.py,v 1.49 2003-09-04 00:47:01 richard Exp $
1+
# $Id: back_metakit.py,v 1.50 2003-09-08 20:39:18 jlgijsbers Exp $
22
'''
33
Metakit backend for Roundup, originally by Gordon McMillan.
44
@@ -48,10 +48,6 @@ def Database(config, journaltag=None):
4848
_dbs[config.DATABASE] = db
4949
else:
5050
db.journaltag = journaltag
51-
try:
52-
delattr(db, 'curuserid')
53-
except AttributeError:
54-
pass
5551
return db
5652

5753
class _Database(hyperdb.Database, roundupdb.Database):
@@ -81,21 +77,7 @@ def reindex(self):
8177

8278
# --- defined in ping's spec
8379
def __getattr__(self, classname):
84-
if classname == 'curuserid':
85-
if self.journaltag is None:
86-
return None
87-
88-
# try to set the curuserid from the journaltag
89-
try:
90-
x = int(self.classes['user'].lookup(self.journaltag))
91-
self.curuserid = x
92-
except KeyError:
93-
if self.journaltag == 'admin':
94-
self.curuserid = x = 1
95-
else:
96-
x = 0
97-
return x
98-
elif classname == 'transactions':
80+
if classname == 'transactions':
9981
return self.dirty
10082
# fall back on the classes
10183
return self.getclass(classname)
@@ -154,7 +136,7 @@ def addjournal(self, tablenm, nodeid, action, params, creator=None,
154136
if tblid == -1:
155137
tblid = self.tables.append(name=tablenm)
156138
if creator is None:
157-
creator = self.curuserid
139+
creator = self.getuid()
158140
else:
159141
try:
160142
creator = int(creator)
@@ -642,7 +624,7 @@ def set(self, nodeid, **propvalues):
642624
if not row.creation:
643625
row.creation = int(time.time())
644626
if not row.creator:
645-
row.creator = self.db.curuserid
627+
row.creator = self.db.getuid()
646628

647629
self.db.dirty = 1
648630
if self.do_journal:

roundup/backends/rdbms_common.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: rdbms_common.py,v 1.61 2003-09-06 20:01:10 jlgijsbers Exp $
1+
# $Id: rdbms_common.py,v 1.62 2003-09-08 20:39:18 jlgijsbers Exp $
22
''' Relational database (SQL) backend common code.
33
44
Basics:
@@ -145,8 +145,6 @@ def post_init(self):
145145
# commit
146146
self.conn.commit()
147147

148-
self.figure_curuserid()
149-
150148
def reindex(self):
151149
for klass in self.classes.values():
152150
for nodeid in klass.list():
@@ -442,7 +440,7 @@ def addnode(self, classname, nodeid, node):
442440
# calling code's node assumptions)
443441
node = node.copy()
444442
node['creation'] = node['activity'] = date.Date()
445-
node['creator'] = self.curuserid
443+
node['creator'] = self.getuid()
446444

447445
# default the non-multilink columns
448446
for col, prop in cl.properties.items():
@@ -732,7 +730,7 @@ def addjournal(self, classname, nodeid, action, params, creator=None,
732730
if creator:
733731
journaltag = creator
734732
else:
735-
journaltag = self.curuserid
733+
journaltag = self.getuid()
736734
if creation:
737735
journaldate = creation.serialise()
738736
else:
@@ -1198,7 +1196,7 @@ def get(self, nodeid, propname, default=_marker, cache=1):
11981196
if d.has_key('creator'):
11991197
return d['creator']
12001198
else:
1201-
return self.db.curuserid
1199+
return self.db.getuid()
12021200

12031201
# get the property (raises KeyErorr if invalid)
12041202
prop = self.properties[propname]

roundup/roundupdb.py

Lines changed: 8 additions & 13 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: roundupdb.py,v 1.89 2003-09-08 09:28:28 jlgijsbers Exp $
18+
# $Id: roundupdb.py,v 1.90 2003-09-08 20:39:18 jlgijsbers Exp $
1919

2020
__doc__ = """
2121
Extending hyperdb with types specific to issue-tracking.
@@ -35,7 +35,13 @@ class Database:
3535
def getuid(self):
3636
"""Return the id of the "user" node associated with the user
3737
that owns this connection to the hyperdatabase."""
38-
return self.user.lookup(self.journaltag)
38+
if self.journaltag is None:
39+
return None
40+
elif self.journaltag == 'admin':
41+
# admin user may not exist, but always has ID 1
42+
return '1'
43+
else:
44+
return self.user.lookup(self.journaltag)
3945

4046
def getUserTimezone(self):
4147
"""Return user timezone defined in 'timezone' property of user class.
@@ -51,16 +57,6 @@ def getUserTimezone(self):
5157
timezone = 0
5258
return timezone
5359

54-
def figure_curuserid(self):
55-
"""Figure out the 'curuserid'."""
56-
if self.journaltag is None:
57-
self.curuserid = None
58-
elif self.journaltag == 'admin':
59-
# admin user may not exist, but always has ID 1
60-
self.curuserid = '1'
61-
else:
62-
self.curuserid = self.user.lookup(self.journaltag)
63-
6460
def confirm_registration(self, otk):
6561
props = self.otks.getall(otk)
6662
for propname, proptype in self.user.getprops().items():
@@ -77,7 +73,6 @@ def confirm_registration(self, otk):
7773

7874
# tag new user creation with 'admin'
7975
self.journaltag = 'admin'
80-
self.figure_curuserid()
8176

8277
# create the new user
8378
cl = self.user

0 commit comments

Comments
 (0)