summaryrefslogtreecommitdiff
path: root/src/mailman/workflows/common.py
diff options
context:
space:
mode:
authorJ08nY2017-07-12 18:57:01 +0200
committerJ08nY2017-08-07 18:18:00 +0200
commit139a4b484415843d4f0dcf723ed7b56fc52b2547 (patch)
treec9d1f401f7f044e85a8851fb15648b71b6d1e7a7 /src/mailman/workflows/common.py
parent39fba3777fc7d37414368f40bf3504dadaa1841a (diff)
downloadmailman-139a4b484415843d4f0dcf723ed7b56fc52b2547.tar.gz
mailman-139a4b484415843d4f0dcf723ed7b56fc52b2547.tar.zst
mailman-139a4b484415843d4f0dcf723ed7b56fc52b2547.zip
Diffstat (limited to 'src/mailman/workflows/common.py')
-rw-r--r--src/mailman/workflows/common.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/mailman/workflows/common.py b/src/mailman/workflows/common.py
index 41733f6e5..1f63d3d1d 100644
--- a/src/mailman/workflows/common.py
+++ b/src/mailman/workflows/common.py
@@ -23,8 +23,10 @@ import logging
from datetime import timedelta
from email.utils import formataddr
from enum import Enum
+from itertools import chain
from mailman.app.membership import delete_member
+from mailman.config import config
from mailman.core.i18n import _
from mailman.email.message import UserNotification
from mailman.interfaces.address import IAddress
@@ -38,14 +40,12 @@ from mailman.interfaces.subscriptions import (SubscriptionPendingError,
from mailman.interfaces.template import ITemplateLoader
from mailman.interfaces.user import IUser
from mailman.interfaces.usermanager import IUserManager
-from mailman.interfaces.workflows import (ISubscriptionWorkflow,
- IUnsubscriptionWorkflow, IWorkflow)
+from mailman.interfaces.workflows import ISubscriptionWorkflow
from mailman.utilities.datetime import now
from mailman.utilities.string import expand, wrap
from mailman.workflows.base import Workflow
from zope.component import getUtility
from zope.interface import implementer
-from zope.interface.exceptions import DoesNotImplement
log = logging.getLogger('mailman.subscribe')
@@ -157,14 +157,7 @@ class SubscriptionWorkflowCommon(Workflow):
self.token = None
return
- if ISubscriptionWorkflow.implementedBy(self.__class__):
- pendable_class = PendableSubscription
- elif IUnsubscriptionWorkflow.implementedBy(self.__class__):
- pendable_class = PendableUnsubscription
- else:
- raise DoesNotImplement(IWorkflow)
-
- pendable = pendable_class(
+ pendable = self.pendable_class()(
list_id=self.mlist.list_id,
email=self.address.email,
display_name=self.address.display_name,
@@ -173,6 +166,13 @@ class SubscriptionWorkflowCommon(Workflow):
)
self.token = pendings.add(pendable, timedelta(days=3650))
+ @classmethod
+ def pendable_class(cls):
+ @implementer(IPendable)
+ class Pendable(dict):
+ PEND_TYPE = cls.name
+ return Pendable
+
class SubscriptionBase(SubscriptionWorkflowCommon):
@@ -219,9 +219,17 @@ class SubscriptionBase(SubscriptionWorkflowCommon):
if IBanManager(self.mlist).is_banned(self.address.email):
raise MembershipIsBannedError(self.mlist, self.address.email)
# Check if there is already a subscription request for this email.
- pendings = getUtility(IPendings).find(
- mlist=self.mlist,
- pend_type='subscription')
+ # Look at all known subscription workflows, because any pending
+ # subscription workflow is exclusive.
+ sub_workflows = [workflow_class
+ for workflow_class in config.workflows.values()
+ if ISubscriptionWorkflow.implementedBy(workflow_class)
+ ]
+ generators = [getUtility(IPendings).find(mlist=self.mlist,
+ pend_type=sub_workflow.name)
+ for
+ sub_workflow in sub_workflows]
+ pendings = chain.from_iterable(generators)
for token, pendable in pendings:
if pendable['email'] == self.address.email:
raise SubscriptionPendingError(self.mlist, self.address.email)