summaryrefslogtreecommitdiff
path: root/src/mailman_pgp/workflows/mod_approval.py
blob: e7ff0613b6645ff8e811c35eda19607c93b3591f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright (C) 2017 Jan Jancar
#
# This file is a part of the Mailman PGP plugin.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.

""""""

from mailman.email.message import UserNotification
from mailman.interfaces.subscriptions import TokenOwner
from public import public

from mailman_pgp.pgp.mime import MIMEWrapper

MOD_APPROVAL_REQUEST = """\
----------
TODO: this is a pgp enabled list.
A subscriber with address {} requested a change of his key.
His new key is attached to this message.

Fingerprint: {}
----------
"""


@public
class ModeratorApprovalMixin:
    def _step_mod_approval(self):
        self.push('restore')
        self.push('get_approval')

    def _step_get_approval(self):
        self._set_token(TokenOwner.moderator)
        self.push('restore')
        self.save()

        if self.mlist.admin_immed_notify:
            subject = 'New key change request to {} from {}'.format(
                    self.mlist.display_name, self.pgp_address.email)
            text = MOD_APPROVAL_REQUEST.format(self.pgp_address.email,
                                               self.pubkey.fingerprint)
            msg = UserNotification(
                    self.mlist.owner_address, self.mlist.owner_address,
                    subject, text, self.mlist.preferred_language)
            wrapped = MIMEWrapper(msg)
            msg = wrapped.attach_keys(self.pubkey)
            msg.send(self.mlist)
        raise StopIteration

    def _step_restore(self):
        self._set_token(TokenOwner.no_one)