summaryrefslogtreecommitdiff
path: root/src/mailman/workflows/unsubscription.py
blob: 45dad92f5a6e8a316fb80db590e7e0bc28da25c8 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# Copyright (C) 2015-2017 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/>.

""""""

from mailman.core.i18n import _
from mailman.interfaces.workflows import IUnsubscriptionWorkflow
from mailman.workflows.common import (ConfirmationMixin, ModerationMixin,
                                      UnsubscriptionBase)
from public import public
from zope.interface import implementer


@public
@implementer(IUnsubscriptionWorkflow)
class OpenUnsubscriptionPolicy(UnsubscriptionBase):
    """"""

    name = 'unsub-policy-open'
    description = _(
            'An open unsubscription policy, only requires verification.')
    initial_state = 'prepare'
    save_attributes = (
        'address_key',
        'subscriber_key',
        'user_key',
        'token_owner_key',
        )

    def __init__(self, mlist, subscriber=None):
        """

        :param mlist:
        :param subscriber: The user or address to unsubscribe.
        :type subscriber: ``IUser`` or ``IAddress``
        """
        UnsubscriptionBase.__init__(self, mlist, subscriber)

    def _step_prepare(self):
        self.push('do_unsubscription')
        self.push('subscription_checks')


@public
@implementer(IUnsubscriptionWorkflow)
class ConfirmUnsubscriptionPolicy(UnsubscriptionBase, ConfirmationMixin):
    """"""

    name = 'unsub-policy-confirm'
    description = _('An unsubscription policy that requires confirmation.')
    initial_state = 'prepare'
    save_attributes = (
        'confirmed',
        'address_key',
        'subscriber_key',
        'user_key',
        'token_owner_key',
        )

    def __init__(self, mlist, subscriber=None, *,
                 pre_confirmed=False):
        """

        :param mlist:
        :param subscriber: The user or address to unsubscribe.
        :type subscriber: ``IUser`` or ``IAddress``
        :param pre_confirmed: A flag indicating whether, when required by the
            unsubscription policy, an unsubscription request should be
            considered pre-confirmed.  Normally in such cases, a mail-back
            confirmation message is sent to the subscriber, which must be
            positively acknowledged by some manner.  Setting this flag to True
            automatically confirms the unsubscription request.  (A confirmation
            message may still be sent under other conditions.)
        :type pre_confirmed: bool
        """
        UnsubscriptionBase.__init__(self, mlist, subscriber)
        ConfirmationMixin.__init__(self, pre_confirmed=pre_confirmed)

    def _step_prepare(self):
        self.push('do_unsubscription')
        self.push('confirmation_checks')
        self.push('subscription_checks')


@public
@implementer(IUnsubscriptionWorkflow)
class ModerationUnsubscriptionPolicy(UnsubscriptionBase, ModerationMixin):
    """"""

    name = 'unsub-policy-moderate'
    description = _('An unsubscription policy that requires moderation.')
    initial_state = 'prepare'
    save_attributes = (
        'approved',
        'address_key',
        'subscriber_key',
        'user_key',
        'token_owner_key',
        )

    def __init__(self, mlist, subscriber=None, *,
                 pre_approved=False):
        """

        :param mlist:
        :param subscriber: The user or address to unsubscribe.
        :type subscriber: ``IUser`` or ``IAddress``
        :param pre_approved: A flag indicating whether, when required by the
            unsubscription policy, an unsubscription request should be
            considered pre-approved.  Normally in such cases, the list
            administrator is notified that an approval is necessary, which
            must be positively acknowledged in some manner.  Setting this flag
            to True automatically approves the unsubscription request.
        :type pre_approved: bool
        """
        UnsubscriptionBase.__init__(self, mlist, subscriber)
        ModerationMixin.__init__(self, pre_approved=pre_approved)

    def _step_prepare(self):
        self.push('do_unsubscription')
        self.push('moderation_checks')
        self.push('subscription_checks')


@public
@implementer(IUnsubscriptionWorkflow)
class ConfirmModerationUnsubscriptionPolicy(UnsubscriptionBase,
                                            ConfirmationMixin,
                                            ModerationMixin):
    """"""

    name = 'unsub-policy-confirm-moderate'
    description = _(
        'An unsubscription policy, requires moderation after confirmation.')
    initial_state = 'prepare'
    save_attributes = (
        'approved',
        'confirmed',
        'address_key',
        'subscriber_key',
        'user_key',
        'token_owner_key',
        )

    def __init__(self, mlist, subscriber=None, *,
                 pre_confirmed=False, pre_approved=False):
        """

        :param mlist:
        :param subscriber: The user or address to unsubscribe.
        :type subscriber: ``IUser`` or ``IAddress``
        :param pre_confirmed: A flag indicating whether, when required by the
            unsubscription policy, an unsubscription request should be
            considered pre-confirmed.  Normally in such cases, a mail-back
            confirmation message is sent to the subscriber, which must be
            positively acknowledged by some manner.  Setting this flag to True
            automatically confirms the unsubscription request.  (A confirmation
            message may still be sent under other conditions.)
        :type pre_confirmed: bool
        :param pre_approved: A flag indicating whether, when required by the
            unsubscription policy, an unsubscription request should be
            considered pre-approved.  Normally in such cases, the list
            administrator is notified that an approval is necessary, which
            must be positively acknowledged in some manner.  Setting this flag
            to True automatically approves the unsubscription request.
        :type pre_approved: bool
        """
        UnsubscriptionBase.__init__(self, mlist, subscriber)
        ConfirmationMixin.__init__(self, pre_confirmed=pre_confirmed)
        ModerationMixin.__init__(self, pre_approved=pre_approved)

    def _step_prepare(self):
        self.push('do_unsubscription')
        self.push('moderation_checks')
        self.push('confirmation_checks')
        self.push('subscription_checks')