diff options
| author | Barry Warsaw | 2012-04-07 15:59:30 -0600 |
|---|---|---|
| committer | Barry Warsaw | 2012-04-07 15:59:30 -0600 |
| commit | 7abcd4faa1553fb012020b6204fb8b6208fa5bf2 (patch) | |
| tree | a10fdad6d006c79e83997aa46401667eb61457e0 | |
| parent | 98169dac0fc89c4846b8396373b58be34c749f8e (diff) | |
| download | mailman-7abcd4faa1553fb012020b6204fb8b6208fa5bf2.tar.gz mailman-7abcd4faa1553fb012020b6204fb8b6208fa5bf2.tar.zst mailman-7abcd4faa1553fb012020b6204fb8b6208fa5bf2.zip | |
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 2 | ||||
| -rw-r--r-- | src/mailman/interfaces/address.py | 3 | ||||
| -rw-r--r-- | src/mailman/interfaces/user.py | 13 | ||||
| -rw-r--r-- | src/mailman/model/docs/users.rst | 19 | ||||
| -rw-r--r-- | src/mailman/model/user.py | 15 |
5 files changed, 49 insertions, 3 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index aaf630c45..301703d52 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -29,6 +29,8 @@ Architecture is hashed with the currently selected scheme. * An `AddressVerificationEvent` is triggered when an `IAddress` is verified or unverified. (LP: #975698) + * A `PasswordChangeEvent` is triggered when an `IUser`'s password changes. + (LP: #975700) Configuration ------------- diff --git a/src/mailman/interfaces/address.py b/src/mailman/interfaces/address.py index 38a490839..54bf6b283 100644 --- a/src/mailman/interfaces/address.py +++ b/src/mailman/interfaces/address.py @@ -89,7 +89,8 @@ class AddressVerificationEvent: self.address = address def __str__(self): - return '<AddressVerificationEvent {0} {1}>'.format( + return '<{0} {1} {2}>'.format( + self.__class__.__name__, self.address.email, ('unverified' if self.address.verified_on is None else self.address.verified_on)) diff --git a/src/mailman/interfaces/user.py b/src/mailman/interfaces/user.py index 8d0cbfb54..341a41205 100644 --- a/src/mailman/interfaces/user.py +++ b/src/mailman/interfaces/user.py @@ -22,6 +22,7 @@ from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ 'IUser', + 'PasswordChangeEvent', 'UnverifiedAddressError', ] @@ -37,6 +38,18 @@ class UnverifiedAddressError(AddressError): +class PasswordChangeEvent: + """Event which gets triggered when a user changes their password.""" + + def __init__(self, user): + self.user = user + + def __str__(self): + return '<{0} {1}>'.format(self.__class__.__name__, + self.user.display_name) + + + class IUser(Interface): """A basic user.""" diff --git a/src/mailman/model/docs/users.rst b/src/mailman/model/docs/users.rst index ae2acfd48..95e08a8d7 100644 --- a/src/mailman/model/docs/users.rst +++ b/src/mailman/model/docs/users.rst @@ -36,6 +36,25 @@ The password and real name can be changed at any time. >>> dump_list(user.password for user in user_manager.users) another password +When the user's password is changed, an event is triggered. + + >>> saved_event = None + >>> def save_event(event): + ... global saved_event + ... saved_event = event + >>> from mailman.testing.helpers import event_subscribers + >>> with event_subscribers(save_event): + ... user_1.password = b'changed again' + >>> print saved_event + <PasswordChangeEvent Zoe X. Person> + +The event holds a reference to the `IUser` that changed their password. + + >>> print saved_event.user.display_name + Zoe X. Person + >>> print saved_event.user.password + changed again + Basic user identification ========================= diff --git a/src/mailman/model/user.py b/src/mailman/model/user.py index 11c719eea..9ca9b5aea 100644 --- a/src/mailman/model/user.py +++ b/src/mailman/model/user.py @@ -27,13 +27,15 @@ __all__ = [ from storm.locals import ( DateTime, Int, RawStr, Reference, ReferenceSet, Unicode) from storm.properties import UUID +from zope.event import notify from zope.interface import implements from mailman.config import config from mailman.database.model import Model from mailman.interfaces.address import ( AddressAlreadyLinkedError, AddressNotLinkedError) -from mailman.interfaces.user import IUser, UnverifiedAddressError +from mailman.interfaces.user import ( + IUser, PasswordChangeEvent, UnverifiedAddressError) from mailman.model.address import Address from mailman.model.preferences import Preferences from mailman.model.roster import Memberships @@ -52,7 +54,7 @@ class User(Model): id = Int(primary=True) display_name = Unicode() - password = RawStr() + _password = RawStr(name='password') _user_id = UUID() _created_on = DateTime() @@ -88,6 +90,15 @@ class User(Model): """See `IUser`.""" return self._created_on + @property + def password(self): + return self._password + + @password.setter + def password(self, new_password): + self._password = new_password + notify(PasswordChangeEvent(self)) + def link(self, address): """See `IUser`.""" if address.user is not None: |
