summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 429f34e)
raw | patch | inline | side by side (parent: 429f34e)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 20 Sep 2002 05:08:00 +0000 (05:08 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 20 Sep 2002 05:08:00 +0000 (05:08 +0000) |
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.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1200 57a73879-2fb5-44c3-a270-3262357dd7e2
gone away now. The code should handle existing journaltag-as-username
entries, but will use userid from now on.
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1200 57a73879-2fb5-44c3-a270-3262357dd7e2
index ef047bac41a21cf2a3000a891adb99a4fb6c037f..0fdcf28e40bd12eb71c0f4b062a11c1e7606cfde 100644 (file)
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-#$Id: back_anydbm.py,v 1.82 2002-09-20 01:20:31 richard Exp $
+#$Id: back_anydbm.py,v 1.83 2002-09-20 05:08:00 richard 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
os.umask(0002)
def post_init(self):
- '''Called once the schema initialisation has finished.'''
+ ''' Called once the schema initialisation has finished.
+ '''
# reindex the db if necessary
if self.indexer.should_reindex():
self.reindex()
+ # figure 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 reindex(self):
for klass in self.classes.values():
for nodeid in klass.list():
if __debug__:
print >>hyperdb.DEBUG, 'addnode', (self, classname, nodeid, node)
- # add in the "calculated" properties (dupe so we don't affect
- # calling code's node assumptions)
- node = node.copy()
- node['creator'] = self.journaltag
- node['creation'] = node['activity'] = date.Date()
+ # we'll be supplied these props if we're doing an import
+ if not node.has_key('creator'):
+ # add in the "calculated" properties (dupe so we don't affect
+ # calling code's node assumptions)
+ node = node.copy()
+ node['creator'] = self.curuserid
+ node['creation'] = node['activity'] = date.Date()
self.newnodes.setdefault(classname, {})[nodeid] = 1
self.cache.setdefault(classname, {})[nodeid] = node
if creator:
journaltag = creator
else:
- journaltag = self.journaltag
+ journaltag = self.curuserid
if creation:
journaldate = creation.serialise()
else:
value = pwd
d[propname] = value
- # extract the extraneous journalling gumpf and nuke it
+ # add the node and journal
+ self.db.addnode(self.classname, newid, d)
+
+ # extract the journalling stuff and nuke it
if d.has_key('creator'):
creator = d['creator']
del d['creator']
if d.has_key('activity'):
del d['activity']
- # add the node and journal
- self.db.addnode(self.classname, newid, d)
self.db.addjournal(self.classname, newid, 'create', d, creator,
creation)
return newid
raise ValueError, 'Journalling is disabled for this class'
journal = self.db.getjournal(self.classname, nodeid)
if journal:
- return self.db.getjournal(self.classname, nodeid)[0][2]
+ num_re = re.compile('^\d+$')
+ value = self.db.getjournal(self.classname, nodeid)[0][2]
+ if num_re.match(value):
+ return value
+ else:
+ # old-style "username" journal tag
+ try:
+ return self.db.user.lookup(value)
+ except KeyError:
+ # user's been retired, return admin
+ return '1'
else:
- return self.db.journaltag
+ return self.db.curuserid
# get the property (raises KeyErorr if invalid)
prop = self.properties[propname]
d['id'] = String()
d['creation'] = hyperdb.Date()
d['activity'] = hyperdb.Date()
- # can't be a link to user because the user might have been
- # retired since the journal entry was created
- d['creator'] = hyperdb.String()
+ d['creator'] = hyperdb.Link('user')
return d
def addprop(self, **properties):
index 2a90a5c06b31b5c3fb8e8ae5fa640461140a96d2..d3b4b1486064d7b1cf1d552869c36b67f8d85043 100755 (executable)
# --- defined in ping's spec
def __getattr__(self, classname):
if classname == 'curuserid':
+ if self.journaltag is None:
+ return None
+
try:
self.curuserid = x = int(self.classes['user'].lookup(self.journaltag))
except KeyError:
- x = 0
+ if self.journaltag == 'admin':
+ self.curuserid = x = 1
+ else:
+ x = 0
return x
elif classname == 'transactions':
return self.dirty
self.privateprops = { 'id' : hyperdb.String(),
'activity' : hyperdb.Date(),
'creation' : hyperdb.Date(),
- 'creator' : hyperdb.String() }
+ 'creator' : hyperdb.Link('user') }
self.auditors = {'create': [], 'set': [], 'retire': []} # event -> list of callables
self.reactors = {'create': [], 'set': [], 'retire': []} # ditto
view = self.__getview()
if propvalues.has_key('id'):
raise KeyError, '"id" is reserved'
if self.db.journaltag is None:
- raise DatabaseError, 'Database open read-only'
+ raise hyperdb.DatabaseError, 'Database open read-only'
view = self.getview(1)
# node must exist & not be retired
id = int(nodeid)
# must be a string or None
if value is not None and not isinstance(value, type('')):
raise ValueError, 'property "%s" link value be a string'%(
- propname)
+ key)
# Roundup sets to "unselected" by passing None
if value is None:
value = 0
index 6ddf71ae66f17bf9356a01983ab28eba9512b1ea..d39234f0fe1eaac9a1033143fae9f9edda3a8e57 100644 (file)
-# $Id: rdbms_common.py,v 1.8 2002-09-20 01:48:34 richard Exp $
+# $Id: rdbms_common.py,v 1.9 2002-09-20 05:08:00 richard Exp $
# standard python modules
import sys, os, time, re, errno, weakref, copy
# commit
self.conn.commit()
+ # figure 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 reindex(self):
for klass in self.classes.values():
for nodeid in klass.list():
# add the special props
node = node.copy()
node['creation'] = node['activity'] = date.Date()
- node['creator'] = self.journaltag
+ node['creator'] = self.curuserid
# default the non-multilink columns
for col, prop in cl.properties.items():
if creator:
journaltag = creator
else:
- journaltag = self.journaltag
+ journaltag = self.curuserid
if creation:
journaldate = creation.serialise()
else:
if d.has_key('creator'):
return d['creator']
else:
- return self.db.journaltag
+ return self.db.curuserid
# get the property (raises KeyErorr if invalid)
prop = self.properties[propname]
d['id'] = String()
d['creation'] = hyperdb.Date()
d['activity'] = hyperdb.Date()
- d['creator'] = hyperdb.String()
+ d['creator'] = hyperdb.Link('user')
return d
def addprop(self, **properties):
diff --git a/test/test_db.py b/test/test_db.py
index 00e67e7c8dd1e968772074ca9055a239beecf82f..c9ef86857295c54b5a5229a326e468f7b5b3b9d0 100644 (file)
--- a/test/test_db.py
+++ b/test/test_db.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: test_db.py,v 1.51 2002-09-20 01:20:32 richard Exp $
+# $Id: test_db.py,v 1.52 2002-09-20 05:08:00 richard Exp $
import unittest, os, shutil, time
assignable=Boolean(), age=Number(), roles=String())
user.setkey("username")
file = module.FileClass(db, "file", name=String(), type=String(),
- comment=String(indexme="yes"))
+ comment=String(indexme="yes"), fooz=Password())
issue = module.IssueClass(db, "issue", title=String(indexme="yes"),
status=Link("status"), nosy=Multilink("user"), deadline=Date(),
foo=Interval(), files=Multilink("file"), assignedto=Link('user'))
session.disableJournalling()
db.post_init()
if create:
+ user.create(username="admin", roles='Admin')
status.create(name="unread")
status.create(name="in-progress")
status.create(name="testing")
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- self.db = anydbm.Database(config, 'test')
+ self.db = anydbm.Database(config, 'admin')
setupSchema(self.db, 1, anydbm)
- self.db2 = anydbm.Database(config, 'test')
+ self.db2 = anydbm.Database(config, 'admin')
setupSchema(self.db2, 0, anydbm)
def testStringChange(self):
self.assertEqual(self.db.user.get('1', "assignable"), None)
def testNumberChange(self):
- self.db.user.create(username='foo', age=1)
- self.assertEqual(1, self.db.user.get('1', 'age'))
+ nid = self.db.user.create(username='foo', age=1)
+ self.assertEqual(1, self.db.user.get(nid, 'age'))
self.db.user.set('1', age=3)
self.assertNotEqual(self.db.user.get('1', 'age'), 1)
self.db.user.set('1', age=1.0)
# key property
#
# key must be a String
- ar(TypeError, self.db.user.setkey, 'password')
+ ar(TypeError, self.db.file.setkey, 'fooz')
# key must exist
- ar(KeyError, self.db.user.setkey, 'fubar')
+ ar(KeyError, self.db.file.setkey, 'fubar')
#
# class get
ar(TypeError, self.db.user.create, username='foo', age='a')
# invalid boolean value
ar(TypeError, self.db.user.create, username='foo', assignable='true')
- self.db.user.create(username='foo')
+ nid = self.db.user.create(username='foo')
# invalid number value
- ar(TypeError, self.db.user.set, '3', username='foo', age='a')
+ ar(TypeError, self.db.user.set, nid, username='foo', age='a')
# invalid boolean value
- ar(TypeError, self.db.user.set, '3', username='foo', assignable='true')
+ ar(TypeError, self.db.user.set, nid, username='foo', assignable='true')
def testJournals(self):
self.db.user.create(username="mary")
self.assertEqual(1, len(journal))
(nodeid, date_stamp, journaltag, action, params) = journal[0]
self.assertEqual(nodeid, '1')
- self.assertEqual(journaltag, 'test')
+ self.assertEqual(journaltag, self.db.user.lookup('admin'))
self.assertEqual(action, 'create')
keys = params.keys()
keys.sort()
self.assertEqual(2, len(journal))
(nodeid, date_stamp, journaltag, action, params) = journal[1]
self.assertEqual('1', nodeid)
- self.assertEqual('test', journaltag)
+ self.assertEqual('1', journaltag)
self.assertEqual('link', action)
self.assertEqual(('issue', '1', 'assignedto'), params)
self.assertEqual(3, len(journal))
(nodeid, date_stamp, journaltag, action, params) = journal[2]
self.assertEqual('1', nodeid)
- self.assertEqual('test', journaltag)
+ self.assertEqual('1', journaltag)
self.assertEqual('unlink', action)
self.assertEqual(('issue', '1', 'assignedto'), params)
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- db = anydbm.Database(config, 'test')
+ db = anydbm.Database(config, 'admin')
setupSchema(db, 1, anydbm)
self.db = anydbm.Database(config)
setupSchema(self.db, 0, anydbm)
- self.db2 = anydbm.Database(config, 'test')
+ self.db2 = anydbm.Database(config, 'admin')
setupSchema(self.db2, 0, anydbm)
def testExceptions(self):
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- self.db = bsddb.Database(config, 'test')
+ self.db = bsddb.Database(config, 'admin')
setupSchema(self.db, 1, bsddb)
- self.db2 = bsddb.Database(config, 'test')
+ self.db2 = bsddb.Database(config, 'admin')
setupSchema(self.db2, 0, bsddb)
class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- db = bsddb.Database(config, 'test')
+ db = bsddb.Database(config, 'admin')
setupSchema(db, 1, bsddb)
self.db = bsddb.Database(config)
setupSchema(self.db, 0, bsddb)
- self.db2 = bsddb.Database(config, 'test')
+ self.db2 = bsddb.Database(config, 'admin')
setupSchema(self.db2, 0, bsddb)
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- self.db = bsddb3.Database(config, 'test')
+ self.db = bsddb3.Database(config, 'admin')
setupSchema(self.db, 1, bsddb3)
- self.db2 = bsddb3.Database(config, 'test')
+ self.db2 = bsddb3.Database(config, 'admin')
setupSchema(self.db2, 0, bsddb3)
class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- db = bsddb3.Database(config, 'test')
+ db = bsddb3.Database(config, 'admin')
setupSchema(db, 1, bsddb3)
self.db = bsddb3.Database(config)
setupSchema(self.db, 0, bsddb3)
- self.db2 = bsddb3.Database(config, 'test')
+ self.db2 = bsddb3.Database(config, 'admin')
setupSchema(self.db2, 0, bsddb3)
shutil.rmtree(config.DATABASE)
config.GADFLY_DATABASE = ('test', config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- self.db = gadfly.Database(config, 'test')
+ self.db = gadfly.Database(config, 'admin')
setupSchema(self.db, 1, gadfly)
def testIDGeneration(self):
shutil.rmtree(config.DATABASE)
config.GADFLY_DATABASE = ('test', config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- db = gadfly.Database(config, 'test')
+ db = gadfly.Database(config, 'admin')
setupSchema(db, 1, gadfly)
self.db = gadfly.Database(config)
setupSchema(self.db, 0, gadfly)
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- self.db = sqlite.Database(config, 'test')
+ self.db = sqlite.Database(config, 'admin')
setupSchema(self.db, 1, sqlite)
def testIDGeneration(self):
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- db = sqlite.Database(config, 'test')
+ db = sqlite.Database(config, 'admin')
setupSchema(db, 1, sqlite)
self.db = sqlite.Database(config)
setupSchema(self.db, 0, sqlite)
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- self.db = metakit.Database(config, 'test')
+ self.db = metakit.Database(config, 'admin')
setupSchema(self.db, 1, metakit)
- #self.db2 = metakit.Database(config, 'test')
- #setupSchema(self.db2, 0, metakit)
def testIDGeneration(self):
id1 = self.db.issue.create(title="spam", status='1')
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- db = metakit.Database(config, 'test')
+ db = metakit.Database(config, 'admin')
setupSchema(db, 1, metakit)
self.db = metakit.Database(config)
setupSchema(self.db, 0, metakit)
-# self.db2 = metakit.Database(config, 'test')
-# setupSchema(self.db2, 0, metakit)
def suite():
l = [
]
# return unittest.TestSuite(l)
- try:
- import sqlite
- l.append(unittest.makeSuite(sqliteDBTestCase, 'test'))
- l.append(unittest.makeSuite(sqliteReadOnlyDBTestCase, 'test'))
- except:
- print 'sqlite module not found, skipping gadfly DBTestCase'
-# return unittest.TestSuite(l)
-
try:
import gadfly
l.append(unittest.makeSuite(gadflyDBTestCase, 'test'))
except:
print 'gadfly module not found, skipping gadfly DBTestCase'
+ try:
+ import sqlite
+ l.append(unittest.makeSuite(sqliteDBTestCase, 'test'))
+ l.append(unittest.makeSuite(sqliteReadOnlyDBTestCase, 'test'))
+ except:
+ print 'sqlite module not found, skipping gadfly DBTestCase'
+
try:
import bsddb
l.append(unittest.makeSuite(bsddbDBTestCase, 'test'))
diff --git a/test/test_mailgw.py b/test/test_mailgw.py
index 650133fd4031613fb2dfa430eed8493fc4fdca91..71293a5fdfbe00c133d349986d14d7ef071cd899 100644 (file)
--- a/test/test_mailgw.py
+++ b/test/test_mailgw.py
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
-# $Id: test_mailgw.py,v 1.30 2002-09-12 04:21:20 richard Exp $
+# $Id: test_mailgw.py,v 1.31 2002-09-20 05:08:00 richard Exp $
import unittest, cStringIO, tempfile, os, shutil, errno, imp, sys, difflib
# check we can load the package
self.instance = instance.open(self.dirname)
# and open the database
- self.db = self.instance.open('sekrit')
+ self.db = self.instance.open('admin')
self.db.user.create(username='Chef', address='chef@bork.bork.bork',
roles='User')
self.db.user.create(username='richard', address='richard@test',
diff --git a/test/test_schema.py b/test/test_schema.py
index 9ad53c88f7bbb4b0f222273ed141a0ca8726ac09..051b07d9d562f8c649bc2daf878a71f4d73943fb 100644 (file)
--- a/test/test_schema.py
+++ b/test/test_schema.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: test_schema.py,v 1.11 2002-09-12 04:21:21 richard Exp $
+# $Id: test_schema.py,v 1.12 2002-09-20 05:08:00 richard Exp $
import unittest, os, shutil
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- self.db = back_anydbm.Database(config, 'test')
+ self.db = back_anydbm.Database(config, 'admin')
+ self.db.post_init()
self.db.clear()
def tearDown(self):
diff --git a/test/test_security.py b/test/test_security.py
index df55be46807ce19d47a5f393a644cca7c4b77568..97e759f7a58e3da873a4395062c9c6fb0ae97fc5 100644 (file)
--- a/test/test_security.py
+++ b/test/test_security.py
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
-# $Id: test_security.py,v 1.4 2002-09-10 00:19:55 richard Exp $
+# $Id: test_security.py,v 1.5 2002-09-20 05:08:00 richard Exp $
import os, unittest, shutil
if os.path.exists(config.DATABASE):
shutil.rmtree(config.DATABASE)
os.makedirs(config.DATABASE + '/files')
- self.db = anydbm.Database(config, 'test')
+ self.db = anydbm.Database(config, 'admin')
setupSchema(self.db, 1, anydbm)
def testInterfaceSecurity(self):
self.db.security.getPermission('View', 'issue')
def testDBinit(self):
- self.db.user.create(username="admin", roles='Admin')
self.db.user.create(username="anonymous", roles='User')
def testAccessControls(self):