aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/plugin.py
blob: eceff75056871b337cc6b175a64568c58cd7906d (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
"""A PGP plugin for GNU Mailman."""
from mailman.interfaces.listmanager import ListDeletedEvent
from mailman.interfaces.plugin import IPlugin
from public import public
from zope.event import classhandler
from zope.interface import implementer

from mailman_pgp.config import config
from mailman_pgp.database import Database, transaction
from mailman_pgp.model.list import EncryptedMailingList
from mailman_pgp.rest.root import RESTRoot


@public
@implementer(IPlugin)
class PGPMailman:
    def pre_hook(self):
        """See `IPlugin`."""
        config.load(self.name)
        config.db = Database()

    def post_hook(self):
        """See `IPlugin`."""
        pass

    def rest_object(self):
        """See `IPlugin`."""
        return RESTRoot()


@classhandler.handler(ListDeletedEvent)
def on_delete(mlist):
    encrypted_list = config.db.session.query(EncryptedMailingList).filter_by(
        list_id=mlist.list_id).first()
    if encrypted_list:
        with transaction():
            config.db.session.delete(encrypted_list)