diff options
| author | Barry Warsaw | 2016-10-17 09:13:32 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2016-10-17 09:13:32 -0400 |
| commit | d45af03c4f2a560d51631fdfa7c55cd1a98e722c (patch) | |
| tree | 6cc33aa452d78c38a5d38e83855c5341f0422c2a /src/mailman/commands | |
| parent | 82a913bbf0e8772e7c98d5eb6160fe5b9f7f6f60 (diff) | |
| download | mailman-d45af03c4f2a560d51631fdfa7c55cd1a98e722c.tar.gz mailman-d45af03c4f2a560d51631fdfa7c55cd1a98e722c.tar.zst mailman-d45af03c4f2a560d51631fdfa7c55cd1a98e722c.zip | |
Simplify the implementation.
This merges the SubscriptionManager and UnsubscriptionManager into a
single SubscriptionManager implementation that handles both register()
and unregister(). This allows us to use direct class-based adaptation
instead of the more clunky getAdapter() API. We can also eliminate the
funky _get_workflow() implementation detail.
This has a couple of side-effects. .confirm() must lookup the token in
the pendings database and pull out the pending type, dispatching to the
proper class depending on the type, or raising a LookupError if the
token is None or there is no pendable associated with the given token.
This feels like an acceptable trade-off.
However, this *also* means that IWorkflowStateManager must lose its
'name' argument in its methods. That's because we won't actually know
the name until its too late. Honestly, the name wasn't providing much
value anyway (it was always the subclass's name), so losing that seems
fine too. The complication here is that the name was a primary key in
the 'workflowstate' table, so we need to add its removal in the database
migration.
Diffstat (limited to 'src/mailman/commands')
| -rw-r--r-- | src/mailman/commands/eml_confirm.py | 5 | ||||
| -rw-r--r-- | src/mailman/commands/eml_membership.py | 7 | ||||
| -rw-r--r-- | src/mailman/commands/tests/test_confirm.py | 10 |
3 files changed, 10 insertions, 12 deletions
diff --git a/src/mailman/commands/eml_confirm.py b/src/mailman/commands/eml_confirm.py index b8e1610c4..6787b0987 100644 --- a/src/mailman/commands/eml_confirm.py +++ b/src/mailman/commands/eml_confirm.py @@ -21,7 +21,6 @@ from mailman import public from mailman.core.i18n import _ from mailman.interfaces.command import ContinueProcessing, IEmailCommand from mailman.interfaces.subscriptions import ISubscriptionManager, TokenOwner -from zope.component import getAdapter from zope.interface import implementer @@ -50,8 +49,8 @@ class Confirm: tokens.add(token) results.confirms = tokens try: - new_token, token_owner, member = getAdapter( - mlist, ISubscriptionManager, name='subscribe').confirm(token) + new_token, token_owner, member = ISubscriptionManager( + mlist).confirm(token) if new_token is None: assert token_owner is TokenOwner.no_one, token_owner assert member is not None, member diff --git a/src/mailman/commands/eml_membership.py b/src/mailman/commands/eml_membership.py index 2c535a9d5..e658e7b58 100644 --- a/src/mailman/commands/eml_membership.py +++ b/src/mailman/commands/eml_membership.py @@ -25,7 +25,7 @@ from mailman.interfaces.member import DeliveryMode, MemberRole from mailman.interfaces.subscriptions import ( ISubscriptionManager, ISubscriptionService) from mailman.interfaces.usermanager import IUserManager -from zope.component import getAdapter, getUtility +from zope.component import getUtility from zope.interface import implementer @@ -101,8 +101,7 @@ used. print(_('$person is already a member'), file=results) return ContinueProcessing.yes subscriber = match_subscriber(email, display_name) - getAdapter( - mlist, ISubscriptionManager, name='subscribe').register(subscriber) + ISubscriptionManager(mlist).register(subscriber) print(_('Confirmation email sent to $person'), file=results) return ContinueProcessing.yes @@ -197,7 +196,7 @@ You may be asked to confirm your request.""") return ContinueProcessing.yes # Ignore any subsequent 'leave' commands. already_left.add(email) - manager = getAdapter(mlist, ISubscriptionManager, name='unsubscribe') + manager = ISubscriptionManager(mlist) token, token_owner, member = manager.unregister(user_address) person = formataddr((user.display_name, email)) # noqa if member is None: diff --git a/src/mailman/commands/tests/test_confirm.py b/src/mailman/commands/tests/test_confirm.py index 7351bd6b7..e0f816f24 100644 --- a/src/mailman/commands/tests/test_confirm.py +++ b/src/mailman/commands/tests/test_confirm.py @@ -30,7 +30,7 @@ from mailman.interfaces.usermanager import IUserManager from mailman.runners.command import CommandRunner, Results from mailman.testing.helpers import get_queue_messages, make_testable_runner from mailman.testing.layers import ConfigLayer -from zope.component import getAdapter, getUtility +from zope.component import getUtility class TestConfirm(unittest.TestCase): @@ -42,8 +42,8 @@ class TestConfirm(unittest.TestCase): self._mlist = create_list('test@example.com') anne = getUtility(IUserManager).create_address( 'anne@example.com', 'Anne Person') - self._token, token_owner, member = getAdapter( - self._mlist, ISubscriptionManager, name='subscribe').register(anne) + self._token, token_owner, member = ISubscriptionManager( + self._mlist).register(anne) self._command = Confirm() # Clear the virgin queue. get_queue_messages('virgin') @@ -88,8 +88,8 @@ class TestEmailResponses(unittest.TestCase): 'bart@example.com', 'Bart Person') # Clear any previously queued confirmation messages. get_queue_messages('virgin') - self._token, token_owner, member = getAdapter( - self._mlist, ISubscriptionManager, name='subscribe').register(bart) + self._token, token_owner, member = ISubscriptionManager( + self._mlist).register(bart) # There should now be one email message in the virgin queue, i.e. the # confirmation message sent to Bart. items = get_queue_messages('virgin', expected_count=1) |
