diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/app/subscriptions.py | 8 | ||||
| -rw-r--r-- | src/mailman/interfaces/subscriptions.py | 12 | ||||
| -rw-r--r-- | src/mailman/rest/members.py | 13 |
3 files changed, 28 insertions, 5 deletions
diff --git a/src/mailman/app/subscriptions.py b/src/mailman/app/subscriptions.py index e87eb9731..e901e1922 100644 --- a/src/mailman/app/subscriptions.py +++ b/src/mailman/app/subscriptions.py @@ -39,7 +39,7 @@ from mailman.interfaces.mailinglist import SubscriptionPolicy from mailman.interfaces.member import MembershipIsBannedError from mailman.interfaces.pending import IPendable, IPendings from mailman.interfaces.registrar import ConfirmationNeededEvent -from mailman.interfaces.subscriptions import ISubscriptionService, TokenOwner +from mailman.interfaces.subscriptions import ISubscriptionService,SubscriptionPendingError,TokenOwner from mailman.interfaces.user import IUser from mailman.interfaces.usermanager import IUserManager from mailman.interfaces.workflow import IWorkflowStateManager @@ -185,6 +185,12 @@ class SubscriptionWorkflow(Workflow): # Is this email address banned? if IBanManager(self.mlist).is_banned(self.address.email): raise MembershipIsBannedError(self.mlist, self.address.email) + # Check if the request for this email is already pending under + # moderation + pendings = getUtility(IPendings).find(mlist=self.mlist,pend_type='subscription') + for token,pendable in pendings: + if pendable['email']==self.address.email and pendable['token_owner']=='moderator': + raise SubscriptionPendingError(self.address.email, self.mlist) # Start out with the subscriber being the token owner. self.push('verification_checks') diff --git a/src/mailman/interfaces/subscriptions.py b/src/mailman/interfaces/subscriptions.py index 41ebcfa64..564090cf9 100644 --- a/src/mailman/interfaces/subscriptions.py +++ b/src/mailman/interfaces/subscriptions.py @@ -21,6 +21,7 @@ __all__ = [ 'ISubscriptionService', 'MissingUserError', 'RequestRecord', + 'SubscriptionPendingError', 'TokenOwner', 'TooManyMembersError', ] @@ -45,6 +46,16 @@ class MissingUserError(MailmanError): return self.user_id +class SubscriptionPendingError(MailmanError): + def __init__(self, email, list_id): + super().__init__() + self.email = email + self.list_id = list_id + + def __str__(self): + return 'Subscription request for email {0} is pending for mailing list{1}'.format( + self.email,self.list_id.fqdn_listname) + class TooManyMembersError(MembershipError): def __init__(self, subscriber, list_id, role): super().__init__() @@ -52,7 +63,6 @@ class TooManyMembersError(MembershipError): self.list_id = list_id self.role = role - _RequestRecord = namedtuple( 'RequestRecord', diff --git a/src/mailman/rest/members.py b/src/mailman/rest/members.py index c65ee08f3..9e2c4fbba 100644 --- a/src/mailman/rest/members.py +++ b/src/mailman/rest/members.py @@ -32,9 +32,10 @@ from mailman.interfaces.listmanager import IListManager from mailman.interfaces.member import ( AlreadySubscribedError, DeliveryMode, MemberRole, MembershipError, MembershipIsBannedError, MissingPreferredAddressError) +from mailman.interfaces.pending import IPendings from mailman.interfaces.registrar import IRegistrar from mailman.interfaces.subscriptions import ( - ISubscriptionService, RequestRecord, TokenOwner) + ISubscriptionService, RequestRecord, SubscriptionPendingError, TokenOwner) from mailman.interfaces.user import IUser, UnverifiedAddressError from mailman.interfaces.usermanager import IUserManager from mailman.rest.helpers import ( @@ -45,7 +46,6 @@ from mailman.rest.validator import ( Validator, enum_validator, subscriber_validator) from uuid import UUID from zope.component import getUtility -from mailman.interfaces.pending import IPendings class _MemberBase(CollectionMixin): @@ -260,16 +260,23 @@ class AllMembers(_MemberBase): pre_verified = arguments.pop('pre_verified', False) pre_confirmed = arguments.pop('pre_confirmed', False) pre_approved = arguments.pop('pre_approved', False) + ''' # Check if the request for this email is already pending under moderation pendings = getUtility(IPendings).find(mlist=mlist, pend_type='subscription') for token,pendable in pendings: if pendable['email']==subscriber.email and pendable['token_owner']=='moderator': conflict(response,b'Subscription request pending for moderation') return + ''' # Now we can run the registration process until either the # subscriber is subscribed, or the workflow is paused for # verification, confirmation, or approval. - registrar = IRegistrar(mlist) + try: + registrar = IRegistrar(mlist) + except SubscriptionPendingError: + print('hi') + conflict(response ,b'Subscrition request already pending') + return try: token, token_owner, member = registrar.register( subscriber, |
