aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/workflows/mod_approval.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/workflows/mod_approval.py')
-rw-r--r--src/mailman_pgp/workflows/mod_approval.py74
1 files changed, 65 insertions, 9 deletions
diff --git a/src/mailman_pgp/workflows/mod_approval.py b/src/mailman_pgp/workflows/mod_approval.py
index 90edf4c..f610c4c 100644
--- a/src/mailman_pgp/workflows/mod_approval.py
+++ b/src/mailman_pgp/workflows/mod_approval.py
@@ -17,40 +17,77 @@
""""""
import copy
+from enum import Enum
from mailman.email.message import UserNotification
+from mailman.interfaces.pending import IPendings
from mailman.interfaces.subscriptions import TokenOwner
from public import public
+from zope.component import getUtility
from mailman_pgp.pgp.mime import MIMEWrapper
from mailman_pgp.utils.email import overwrite_message
-MOD_APPROVAL_REQUEST = """\
+SUBSCRIPTION_MOD_REQUEST = """\
----------
TODO: this is a pgp enabled list.
-A subscriber with address {} requested a change of his key.
+A user with address {address} requested subscription
His new key is attached to this message.
-Fingerprint: {}
+Fingerprint: {new_fpr}
----------
"""
+KEY_CHANGE_MOD_REQUEST = """\
+----------
+TODO: this is a pgp enabled list.
+A subscriber with address {address} requested a change of his key.
+His new key is attached to this message.
+
+Old key fingerprint: {old_fpr}
+New key fingerprint: {new_fpr}
+----------
+"""
+
+
+@public
+class WhichApproval(Enum):
+ subscription = 1
+ key_change = 2
+
@public
class ModeratorApprovalMixin:
+ def __init__(self, approval_type, pre_approved=False):
+ self.approved = pre_approved
+ self._approval_type = approval_type
+
def _step_mod_approval(self):
- self.push('get_approval')
+ if not self.approved:
+ self.push('get_approval')
def _step_get_approval(self):
self._pend(TokenOwner.moderator)
- self.push('receive_confirmation')
+ self.push('receive_mod_confirmation')
self.save()
+ params = {'mlist': self.mlist.fqdn_listname,
+ 'address': self.pgp_address.email}
+
+ if self._approval_type is WhichApproval.subscription:
+ name = 'subscription'
+ body = SUBSCRIPTION_MOD_REQUEST
+ params['old_fpr'] = params['new_fpr'] = self.pubkey.fingerprint
+ else:
+ name = 'key change'
+ body = KEY_CHANGE_MOD_REQUEST
+ params['old_fpr'] = self.pgp_address.key_fingerprint
+ params['new_fpr'] = self.pubkey.fingerprint
+
if self.mlist.admin_immed_notify:
- subject = 'New key change request from {}'.format(
- self.pgp_address.email)
- text = MOD_APPROVAL_REQUEST.format(self.pgp_address.email,
- self.pubkey.fingerprint)
+ subject = 'New {} request from {}'.format(name,
+ self.pgp_address.email)
+ text = body.format(**params)
msg = UserNotification(
self.mlist.owner_address, self.mlist.owner_address,
subject, text, self.mlist.preferred_language)
@@ -60,3 +97,22 @@ class ModeratorApprovalMixin:
overwrite_message(msg, out)
out.send(self.mlist)
raise StopIteration
+
+ def _step_receive_mod_confirmation(self):
+ pendings = getUtility(IPendings)
+ if self.token is not None:
+ pendings.confirm(self.token)
+ self.token = None
+ self.token_owner = TokenOwner.no_one
+
+
+@public
+class ModeratorSubApprovalMixin(ModeratorApprovalMixin):
+ def __init__(self, pre_approved=False):
+ super().__init__(WhichApproval.subscription, pre_approved)
+
+
+@public
+class ModeratorKeyChangeApprovalMixin(ModeratorApprovalMixin):
+ def __init__(self, pre_approved=False):
+ super().__init__(WhichApproval.key_change, pre_approved)