From a56ed409b380d97a063698baaf957ebc75198465 Mon Sep 17 00:00:00 2001 From: jlgijsbers Date: Mon, 8 Sep 2003 20:39:18 +0000 Subject: [PATCH] - 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. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1867 57a73879-2fb5-44c3-a270-3262357dd7e2 --- doc/customizing.txt | 4 ++-- doc/design.txt | 3 --- doc/upgrading.txt | 10 ++++++++++ roundup/backends/back_anydbm.py | 11 +++++------ roundup/backends/back_bsddb.py | 4 ++-- roundup/backends/back_bsddb3.py | 4 ++-- roundup/backends/back_metakit.py | 26 ++++---------------------- roundup/backends/rdbms_common.py | 10 ++++------ roundup/roundupdb.py | 21 ++++++++------------- 9 files changed, 37 insertions(+), 56 deletions(-) diff --git a/doc/customizing.txt b/doc/customizing.txt index 9ac41f5..120eaff 100644 --- a/doc/customizing.txt +++ b/doc/customizing.txt @@ -2,7 +2,7 @@ Customising Roundup =================== -:Version: $Revision: 1.96 $ +:Version: $Revision: 1.97 $ .. This document borrows from the ZopeBook section on ZPT. The original is at: 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:: python:db.user Also, the current id of the current user is available as -``db.curuserid``. This isn't so useful in templates (where you have +``db.getuid()``. This isn't so useful in templates (where you have ``request/user``), but it can be useful in detectors or interfaces. The access results in a `hyperdb class wrapper`_. diff --git a/doc/design.txt b/doc/design.txt index 4d9bcc0..6b00926 100644 --- a/doc/design.txt +++ b/doc/design.txt @@ -292,9 +292,6 @@ Here is the interface provided by the hyperdatabase:: class Database: """A database for storing records containing flexible data types. - - The id of the current user is available on the database as - 'self.curuserid'. """ def __init__(self, config, journaltag=None): diff --git a/doc/upgrading.txt b/doc/upgrading.txt index 6c6e613..e77d41d 100644 --- a/doc/upgrading.txt +++ b/doc/upgrading.txt @@ -7,6 +7,16 @@ accordingly. .. contents:: +Migrating from 0.6 to 0.7 +========================= + +0.7.0 Getting the current user id +--------------------------------- + +Removed Database.curuserid attribute. Any code referencing this attribute should +be replaced with a call to Database.getuid(). + + Migrating from 0.5 to 0.6 ========================= diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index 0eaf605..33392a7 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.126 2003-09-06 20:01:10 jlgijsbers Exp $ +#$Id: back_anydbm.py,v 1.127 2003-09-08 20:39:18 jlgijsbers Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -87,7 +87,6 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): # reindex the db if necessary if self.indexer.should_reindex(): self.reindex() - self.figure_curuserid() def reindex(self): for klass in self.classes.values(): @@ -243,7 +242,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): # add in the "calculated" properties (dupe so we don't affect # calling code's node assumptions) node = node.copy() - node['creator'] = self.curuserid + node['creator'] = self.getuid() node['creation'] = node['activity'] = date.Date() self.newnodes.setdefault(classname, {})[nodeid] = 1 @@ -489,7 +488,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): cache_creator, cache_creation) = args if cache_classname == classname and cache_nodeid == nodeid: if not cache_creator: - cache_creator = self.curuserid + cache_creator = self.getuid() if not cache_creation: cache_creation = date.Date() res.append((cache_nodeid, cache_creation, cache_creator, @@ -636,7 +635,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): if creator: journaltag = creator else: - journaltag = self.curuserid + journaltag = self.getuid() if creation: journaldate = creation.serialise() else: @@ -1056,7 +1055,7 @@ class Class(hyperdb.Class): # user's been retired, return admin return '1' else: - return self.db.curuserid + return self.db.getuid() # get the property (raises KeyErorr if invalid) prop = self.properties[propname] diff --git a/roundup/backends/back_bsddb.py b/roundup/backends/back_bsddb.py index bffebf9..2b2a504 100644 --- a/roundup/backends/back_bsddb.py +++ b/roundup/backends/back_bsddb.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_bsddb.py,v 1.26 2003-05-09 01:47:50 richard Exp $ +#$Id: back_bsddb.py,v 1.27 2003-09-08 20:39:18 jlgijsbers Exp $ ''' This module defines a backend that saves the hyperdatabase in BSDDB. ''' @@ -93,7 +93,7 @@ class Database(Database): cache_creator, cache_creation) = args if cache_classname == classname and cache_nodeid == nodeid: if not cache_creator: - cache_creator = self.curuserid + cache_creator = self.getuid() if not cache_creation: cache_creation = date.Date() res.append((cache_nodeid, cache_creation, cache_creator, diff --git a/roundup/backends/back_bsddb3.py b/roundup/backends/back_bsddb3.py index 90f3379..2c01d57 100644 --- a/roundup/backends/back_bsddb3.py +++ b/roundup/backends/back_bsddb3.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_bsddb3.py,v 1.19 2003-05-09 01:47:50 richard Exp $ +#$Id: back_bsddb3.py,v 1.20 2003-09-08 20:39:18 jlgijsbers Exp $ ''' This module defines a backend that saves the hyperdatabase in BSDDB3. ''' @@ -93,7 +93,7 @@ class Database(Database): cache_creator, cache_creation) = args if cache_classname == classname and cache_nodeid == nodeid: if not cache_creator: - cache_creator = self.curuserid + cache_creator = self.getuid() if not cache_creation: cache_creation = date.Date() res.append((cache_nodeid, cache_creation, cache_creator, diff --git a/roundup/backends/back_metakit.py b/roundup/backends/back_metakit.py index 64ab3d7..68dc295 100755 --- a/roundup/backends/back_metakit.py +++ b/roundup/backends/back_metakit.py @@ -1,4 +1,4 @@ -# $Id: back_metakit.py,v 1.49 2003-09-04 00:47:01 richard Exp $ +# $Id: back_metakit.py,v 1.50 2003-09-08 20:39:18 jlgijsbers Exp $ ''' Metakit backend for Roundup, originally by Gordon McMillan. @@ -48,10 +48,6 @@ def Database(config, journaltag=None): _dbs[config.DATABASE] = db else: db.journaltag = journaltag - try: - delattr(db, 'curuserid') - except AttributeError: - pass return db class _Database(hyperdb.Database, roundupdb.Database): @@ -81,21 +77,7 @@ class _Database(hyperdb.Database, roundupdb.Database): # --- defined in ping's spec def __getattr__(self, classname): - if classname == 'curuserid': - if self.journaltag is None: - return None - - # try to set the curuserid from the journaltag - try: - x = int(self.classes['user'].lookup(self.journaltag)) - self.curuserid = x - except KeyError: - if self.journaltag == 'admin': - self.curuserid = x = 1 - else: - x = 0 - return x - elif classname == 'transactions': + if classname == 'transactions': return self.dirty # fall back on the classes return self.getclass(classname) @@ -154,7 +136,7 @@ class _Database(hyperdb.Database, roundupdb.Database): if tblid == -1: tblid = self.tables.append(name=tablenm) if creator is None: - creator = self.curuserid + creator = self.getuid() else: try: creator = int(creator) @@ -642,7 +624,7 @@ class Class: if not row.creation: row.creation = int(time.time()) if not row.creator: - row.creator = self.db.curuserid + row.creator = self.db.getuid() self.db.dirty = 1 if self.do_journal: diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index 216fce9..5d67abc 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -1,4 +1,4 @@ -# $Id: rdbms_common.py,v 1.61 2003-09-06 20:01:10 jlgijsbers Exp $ +# $Id: rdbms_common.py,v 1.62 2003-09-08 20:39:18 jlgijsbers Exp $ ''' Relational database (SQL) backend common code. Basics: @@ -145,8 +145,6 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): # commit self.conn.commit() - self.figure_curuserid() - def reindex(self): for klass in self.classes.values(): for nodeid in klass.list(): @@ -442,7 +440,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): # calling code's node assumptions) node = node.copy() node['creation'] = node['activity'] = date.Date() - node['creator'] = self.curuserid + node['creator'] = self.getuid() # default the non-multilink columns for col, prop in cl.properties.items(): @@ -732,7 +730,7 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): if creator: journaltag = creator else: - journaltag = self.curuserid + journaltag = self.getuid() if creation: journaldate = creation.serialise() else: @@ -1198,7 +1196,7 @@ class Class(hyperdb.Class): if d.has_key('creator'): return d['creator'] else: - return self.db.curuserid + return self.db.getuid() # get the property (raises KeyErorr if invalid) prop = self.properties[propname] diff --git a/roundup/roundupdb.py b/roundup/roundupdb.py index 5bc4928..417067b 100644 --- a/roundup/roundupdb.py +++ b/roundup/roundupdb.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: roundupdb.py,v 1.89 2003-09-08 09:28:28 jlgijsbers Exp $ +# $Id: roundupdb.py,v 1.90 2003-09-08 20:39:18 jlgijsbers Exp $ __doc__ = """ Extending hyperdb with types specific to issue-tracking. @@ -35,7 +35,13 @@ class Database: def getuid(self): """Return the id of the "user" node associated with the user that owns this connection to the hyperdatabase.""" - return self.user.lookup(self.journaltag) + if self.journaltag is None: + return None + elif self.journaltag == 'admin': + # admin user may not exist, but always has ID 1 + return '1' + else: + return self.user.lookup(self.journaltag) def getUserTimezone(self): """Return user timezone defined in 'timezone' property of user class. @@ -51,16 +57,6 @@ class Database: timezone = 0 return timezone - def figure_curuserid(self): - """Figure out the 'curuserid'.""" - if self.journaltag is None: - self.curuserid = None - elif self.journaltag == 'admin': - # admin user may not exist, but always has ID 1 - self.curuserid = '1' - else: - self.curuserid = self.user.lookup(self.journaltag) - def confirm_registration(self, otk): props = self.otks.getall(otk) for propname, proptype in self.user.getprops().items(): @@ -77,7 +73,6 @@ class Database: # tag new user creation with 'admin' self.journaltag = 'admin' - self.figure_curuserid() # create the new user cl = self.user -- 2.30.2