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.py91
1 files changed, 63 insertions, 28 deletions
diff --git a/src/mailman_pgp/workflows/mod_approval.py b/src/mailman_pgp/workflows/mod_approval.py
index f610c4c..367f773 100644
--- a/src/mailman_pgp/workflows/mod_approval.py
+++ b/src/mailman_pgp/workflows/mod_approval.py
@@ -17,7 +17,6 @@
""""""
import copy
-from enum import Enum
from mailman.email.message import UserNotification
from mailman.interfaces.pending import IPendings
@@ -31,10 +30,10 @@ from mailman_pgp.utils.email import overwrite_message
SUBSCRIPTION_MOD_REQUEST = """\
----------
TODO: this is a pgp enabled list.
-A user with address {address} requested subscription
-His new key is attached to this message.
+A user with address {address} requested subscription.
+The key is attached to this message.
-Fingerprint: {new_fpr}
+Fingerprint: {fingerprint}
----------
"""
@@ -42,25 +41,29 @@ 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.
+The new key is attached to this message.
Old key fingerprint: {old_fpr}
New key fingerprint: {new_fpr}
----------
"""
+KEY_REVOKE_MOD_REQUEST = """\
+----------
+TODO: this is a pgp enabled list.
+A subscriber with address {address} revoked a part of his key,
+which made it unusable and needs to be reset. The subscriber
+supplied a new key. The new key is attached to this message.
-@public
-class WhichApproval(Enum):
- subscription = 1
- key_change = 2
+Old key fingerprint: {old_fpr}
+New key fingerprint: {new_fpr}
+----------
+"""
-@public
class ModeratorApprovalMixin:
- def __init__(self, approval_type, pre_approved=False):
+ def __init__(self, pre_approved=False):
self.approved = pre_approved
- self._approval_type = approval_type
def _step_mod_approval(self):
if not self.approved:
@@ -71,26 +74,15 @@ class ModeratorApprovalMixin:
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
+ name = self._request_name
+ body = self._request_body
if self.mlist.admin_immed_notify:
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)
+ subject, body, self.mlist.preferred_language)
out = copy.deepcopy(msg)
wrapped = MIMEWrapper(msg)
msg = wrapped.attach_keys(self.pubkey)
@@ -109,10 +101,53 @@ class ModeratorApprovalMixin:
@public
class ModeratorSubApprovalMixin(ModeratorApprovalMixin):
def __init__(self, pre_approved=False):
- super().__init__(WhichApproval.subscription, pre_approved)
+ super().__init__(pre_approved)
+
+ @property
+ def _request_name(self):
+ return 'subscription'
+
+ @property
+ def _request_body(self):
+ params = {'mlist': self.mlist.fqdn_listname,
+ 'address': self.pgp_address.email,
+ 'fingerprint': self.pubkey.fingerprint}
+ return SUBSCRIPTION_MOD_REQUEST.format(**params)
@public
class ModeratorKeyChangeApprovalMixin(ModeratorApprovalMixin):
def __init__(self, pre_approved=False):
- super().__init__(WhichApproval.key_change, pre_approved)
+ super().__init__(pre_approved)
+
+ @property
+ def _request_name(self):
+ return 'key change'
+
+ @property
+ def _request_body(self):
+ params = {'mlist': self.mlist.fqdn_listname,
+ 'address': self.pgp_address.email,
+ 'fingerprint': self.pubkey.fingerprint,
+ 'old_fpr': self.pgp_address.key_fingerprint,
+ 'new_fpr': self.pubkey.fingerprint}
+ return KEY_CHANGE_MOD_REQUEST.format(**params)
+
+
+@public
+class ModeratorKeyRevokeApprovalMixin(ModeratorApprovalMixin):
+ def __init__(self, pre_approved=False):
+ super().__init__(pre_approved)
+
+ @property
+ def _request_name(self):
+ return 'key reset'
+
+ @property
+ def _request_body(self):
+ params = {'mlist': self.mlist.fqdn_listname,
+ 'address': self.pgp_address.email,
+ 'fingerprint': self.pubkey.fingerprint,
+ 'old_fpr': self.pgp_address.key_fingerprint,
+ 'new_fpr': self.pubkey.fingerprint}
+ return KEY_REVOKE_MOD_REQUEST.format(**params)