summaryrefslogtreecommitdiff
path: root/src/mailman/interfaces/requests.py
blob: cfb38c15b9b510241f24ced1e78bdd8bf9fe1056 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright (C) 2007-2015 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
# GNU Mailman 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.
#
# GNU Mailman 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
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.

"""Interfaces for the request database.

The request database handles events that must be approved by the list
moderators, such as subscription requests and held messages.
"""

__all__ = [
    'IListRequests',
    'RequestType',
    ]


from enum import Enum
from zope.interface import Interface, Attribute



class RequestType(Enum):
    held_message = 1
    subscription = 2
    unsubscription = 3



class IListRequests(Interface):
    """Held requests for a specific mailing list."""

    mailing_list = Attribute(
        """The IMailingList for these requests.""")

    count = Attribute(
        """The total number of requests held for the mailing list.""")

    def count_of(request_type):
        """The total number of requests held of the given request type.

        :param request_type: A `RequestType` enum value.
        :return: An integer.
        """

    def hold_request(request_type, key, data=None):
        """Hold some data for moderator approval.

        :param request_type: A `RequestType` enum value.
        :param key: The key piece of request data being held.
        :param data: Additional optional data in the form of a dictionary that
            is associated with the held request.
        :return: A unique id for this held request.
        """

    held_requests = Attribute(
        """An iterator over the held requests.

        Returned items have two attributes:
         * `id` is the held request's unique id;
         * `type` is a `RequestType` enum value.
        """)

    def of_type(request_type):
        """An iterator over the held requests of the given type.

        Returned items have two  attributes:
         * `id` is the held request's unique id;
         * `type` is a `RequestType` enum value.

         Only items with a matching `type' are returned.
         """

    def get_request(request_id, request_type):
        """Get the data associated with the request id, or None.

        :param request_id: The unique id for the request.
        :type request_id: int
        :param request_type: Optional request type that the requested id must
            match, otherwise no match is returned.
        :type request_type: `RequestType`
        :return: A 2-tuple of the key and data originally held, or None if the
            `request_id` is not in the database.
        """

    def delete_request(request_id):
        """Delete the request associated with the id.

        :param request_id: The unique id for the request.
        :raises KeyError: If `request_id` is not in the database.
        """