diff options
| author | Barry Warsaw | 2011-04-01 18:51:29 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2011-04-01 18:51:29 -0400 |
| commit | 33ad44bc97f08df71f227f6f2a006e770a75c353 (patch) | |
| tree | ef369d5dc968372d824cbe50421a1f5331461149 /src/mailman/model | |
| parent | dee26f391da59c68a23f8fb960dff9ebd879e916 (diff) | |
| download | mailman-33ad44bc97f08df71f227f6f2a006e770a75c353.tar.gz mailman-33ad44bc97f08df71f227f6f2a006e770a75c353.tar.zst mailman-33ad44bc97f08df71f227f6f2a006e770a75c353.zip | |
* Re-organize the interface between buildout.cfg and the zope.testing layer
initialization. buildout.cfg is now really simple; it calls one method.
That method does all the relevant layer initializations. This better
localizes what has to be set up before testing can even begin.
* IUsers now have a created_on property which contains the datetime at which
the user record was created.
* Rework the date and uid factories so that they consult the
MockAndMonkeyLayer for the current testing flag. Also, those factories
register themselves with the layer so that they'll get automatically reset
between tests, without the layer actually having to know about them.
* Move the User model object initialization into User.__init__() from the user
manager. The User now also adds itself to the store.
* Add a 'uid factory' for unique id creation, which is test suite aware.
Diffstat (limited to 'src/mailman/model')
| -rw-r--r-- | src/mailman/model/docs/users.txt | 15 | ||||
| -rw-r--r-- | src/mailman/model/user.py | 18 | ||||
| -rw-r--r-- | src/mailman/model/usermanager.py | 15 |
3 files changed, 29 insertions, 19 deletions
diff --git a/src/mailman/model/docs/users.txt b/src/mailman/model/docs/users.txt index 1703db1ee..29d8601cd 100644 --- a/src/mailman/model/docs/users.txt +++ b/src/mailman/model/docs/users.txt @@ -36,15 +36,16 @@ The password and real name can be changed at any time. another password -User id -======= +Basic user identification +========================= Although rarely visible to users, every user has a unique ID in Mailman, which never changes. This ID is generated randomly at the time the user is created. - >>> print len(user_1.user_id) - 40 + # The test suite uses a predictable user id. + >>> print user_1.user_id + 1 The user id cannot change. @@ -53,6 +54,12 @@ The user id cannot change. ... AttributeError: can't set attribute +User records also have a date on which they where created. + + # The test suite uses a predictable timestamp. + >>> print user_1.created_on + 2005-08-01 07:49:23 + Users addresses =============== diff --git a/src/mailman/model/user.py b/src/mailman/model/user.py index f037bdd48..05ce356ca 100644 --- a/src/mailman/model/user.py +++ b/src/mailman/model/user.py @@ -24,7 +24,7 @@ __all__ = [ 'User', ] -from storm.locals import Int, Reference, ReferenceSet, Unicode +from storm.locals import DateTime, Int, Reference, ReferenceSet, Unicode from zope.interface import implements from mailman.config import config @@ -35,6 +35,8 @@ from mailman.interfaces.user import IUser from mailman.model.address import Address from mailman.model.preferences import Preferences from mailman.model.roster import Memberships +from mailman.utilities.datetime import factory as date_factory +from mailman.utilities.uid import factory as uid_factory @@ -47,11 +49,20 @@ class User(Model): real_name = Unicode() password = Unicode() _user_id = Unicode() + _created_on = DateTime() addresses = ReferenceSet(id, 'Address.user_id') preferences_id = Int() preferences = Reference(preferences_id, 'Preferences.id') + def __init__(self, real_name=None, preferences=None): + super(User, self).__init__() + self._created_on = date_factory.now() + self._user_id = uid_factory.new_uid() + self.real_name = ('' if real_name is None else real_name) + self.preferences = preferences + config.db.store.add(self) + def __repr__(self): return '<User "{0.real_name}" ({0.user_id}) at {1:#x}>'.format( self, id(self)) @@ -61,6 +72,11 @@ class User(Model): """See `IUser`.""" return self._user_id + @property + def created_on(self): + """See `IUser`.""" + return self._created_on + def link(self, address): """See `IUser`.""" if address.user is not None: diff --git a/src/mailman/model/usermanager.py b/src/mailman/model/usermanager.py index 3294b3e7f..d6817021d 100644 --- a/src/mailman/model/usermanager.py +++ b/src/mailman/model/usermanager.py @@ -25,10 +25,6 @@ __all__ = [ ] -import os -import time -import hashlib - from zope.interface import implements from mailman.config import config @@ -37,7 +33,6 @@ from mailman.interfaces.usermanager import IUserManager from mailman.model.address import Address from mailman.model.preferences import Preferences from mailman.model.user import User -from mailman.utilities.passwords import SALT_LENGTH @@ -45,18 +40,10 @@ class UserManager: implements(IUserManager) def create_user(self, email=None, real_name=None): - user = User() - user.real_name = ('' if real_name is None else real_name) + user = User(real_name, Preferences()) if email: address = self.create_address(email, real_name) user.link(address) - user.preferences = Preferences() - # Generate a unique random SHA1 hash for the user id. - salt = os.urandom(SALT_LENGTH) - h = hashlib.sha1(repr(time.time())) - h.update(salt) - user._user_id = unicode(h.hexdigest(), 'us-ascii') - config.db.store.add(user) return user def delete_user(self, user): |
