~barry/mailman/events-and-web

« back to all changes in this revision

Viewing changes to src/mailman/app/membership.py

  • Committer: Barry Warsaw
  • Date: 2012-11-25 20:48:08 UTC
  • Revision ID: barry@list.org-20121125204808-g0pvuil2xq559k4p
Interim commit for refactoring out web-centric logic.

* Use SubscriptionEvent to handle the sending of the welcome message.
* Use ConfirmationNeededEvent to send the confirmation message.
* For now, hard code the adminurl and comment out the listinfo_uri.
* Pend the list-id instead of the fqdn-listname
* Use the new configuration support for Postfix settings.
* Get rid of the IDomain's url_host, base_url, and scheme attributes, as well
  as the confirm_url() method. 
* Get rid of the IMailingList's script_url() method.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
__all__ = [
24
24
    'add_member',
25
25
    'delete_member',
 
26
    'handle_SubscriptionEvent',
26
27
    ]
27
28
 
28
29
 
29
30
from email.utils import formataddr
30
31
from zope.component import getUtility
 
32
from zope.event import notify
31
33
 
32
 
from mailman.app.notifications import send_goodbye_message
 
34
from mailman.app.notifications import (
 
35
    send_goodbye_message, send_welcome_message)
33
36
from mailman.config import config
34
37
from mailman.core.i18n import _
35
38
from mailman.email.message import OwnerNotification
36
39
from mailman.interfaces.address import IEmailValidator
37
40
from mailman.interfaces.bans import IBanManager
38
41
from mailman.interfaces.member import (
39
 
    MemberRole, MembershipIsBannedError, NotAMemberError)
 
42
    MemberRole, MembershipIsBannedError, NotAMemberError, SubscriptionEvent)
40
43
from mailman.interfaces.usermanager import IUserManager
41
44
from mailman.utilities.i18n import make
42
45
 
112
115
        member = mlist.subscribe(address, role)
113
116
        member.preferences.preferred_language = language
114
117
        member.preferences.delivery_mode = delivery_mode
 
118
    notify(SubscriptionEvent(member))
115
119
    return member
116
120
 
117
121
 
156
160
        msg = OwnerNotification(mlist, subject, text,
157
161
                                roster=mlist.administrators)
158
162
        msg.send(mlist)
 
163
 
 
164
 
 
165
 
 
166
def handle_SubscriptionEvent(event):
 
167
    if not isinstance(event, SubscriptionEvent):
 
168
        return
 
169
    member = event.member
 
170
    mlist = member.mailing_list
 
171
    if not mlist.send_welcome_message:
 
172
        return
 
173
    send_welcome_message(
 
174
        mlist, member.address.email, mlist.preferred_language,
 
175
        member.preferences.delivery_mode)