Add unsubscribe links to digest e-mails.

(imported from commit 4e2a324decf4bc694752cc24b9085361338a08a5)
This commit is contained in:
Jessica McKellar
2013-12-01 19:39:10 -05:00
parent 1b068d5433
commit 207cfc449d
5 changed files with 37 additions and 7 deletions

View File

@@ -52,4 +52,11 @@ Click here to log in to Zulip and catch up: https://{{ external_host }}.
Cheers,
The Zulip Team
To disable future email notifications, please visit https://{{ external_host }}/#settings.
--
Manage email preferences:
https://{{ external_host }}/#settings
Unsubscribe from digest emails:
{{ unsubscribe_link }}

View File

@@ -95,5 +95,7 @@ Here are some of the hot conversations that have happened while you've been gone
<br>
The Zulip Team</p>
<p>To disable future email notifications, please visit your <a
href="https://{{ external_host }}/#settings">Zulip Settings page</a>.</p>
<p>
<a href="https://{{ external_host }}/#settings">Manage email preferences</a> |
<a href="{{ unsubscribe_link }}">Unsubscribe from digest emails</a>
</p>

View File

@@ -1223,6 +1223,19 @@ def do_change_enable_offline_push_notifications(user_profile, offline_push_notif
'user': user_profile.email,
'enable_offline_push_notifications': offline_push_notifications})
def do_change_enable_digest_emails(user_profile, enable_digest_emails, log=True):
user_profile.enable_digest_emails = enable_digest_emails
user_profile.save(update_fields=["enable_digest_emails"])
if not enable_digest_emails:
# Remove any digest emails that have been enqueued.
clear_followup_emails_queue(user_profile.email)
if log:
log_event({'type': 'enable_digest_emails',
'user': user_profile.email,
'enable_digest_emails': enable_digest_emails})
def do_change_enter_sends(user_profile, enter_sends):
user_profile.enter_sends = enter_sends
user_profile.save(update_fields=["enter_sends"])

View File

@@ -8,7 +8,7 @@ from django.template import loader
from django.conf import settings
from zerver.lib.actions import build_message_list, hashchange_encode, \
send_future_email
send_future_email, one_click_unsubscribe_link
from zerver.models import UserProfile, UserMessage, Recipient, Stream, \
Subscription
@@ -118,7 +118,11 @@ def handle_digest_email(user_profile_id, cutoff):
message__pub_date__gt=cutoff).order_by("message__pub_date")
# Start building email template data.
template_payload = {'name': user_profile.full_name, 'external_host': settings.EXTERNAL_HOST}
template_payload = {
'name': user_profile.full_name,
'external_host': settings.EXTERNAL_HOST,
'unsubscribe_link': one_click_unsubscribe_link(user_profile, "digest")
}
# Gather recent missed PMs, re-using the missed PM email logic.
pms = all_messages.filter(~Q(message__recipient__type=Recipient.STREAM))

View File

@@ -34,7 +34,7 @@ from zerver.lib.actions import bulk_remove_subscriptions, \
update_user_presence, bulk_add_subscriptions, do_update_message_flags, \
recipient_for_emails, extract_recipients, do_events_register, \
get_status_dict, do_change_enable_offline_email_notifications, \
do_update_message, internal_prep_message, \
do_change_enable_digest_emails, do_update_message, internal_prep_message, \
do_send_messages, get_default_subs, do_deactivate_user, do_reactivate_user, \
user_email_is_unique, do_invite_users, do_refer_friend, compute_mit_user_fullname, \
do_add_alert_words, do_remove_alert_words, do_set_alert_words, get_subscriber_emails, \
@@ -2352,13 +2352,17 @@ def do_missedmessage_unsubscribe(user_profile):
def do_welcome_unsubscribe(user_profile):
clear_followup_emails_queue(user_profile.email)
def do_digest_unsubscribe(user_profile):
do_change_enable_digest_emails(user_profile, False)
# The keys are part of the URL for the unsubscribe link and must be valid
# without encoding.
# The values are a tuple of (display name, unsubscribe function), where the
# display name is what we call this class of email in user-visible text.
email_unsubscribers = {
"missed_messages": ("missed messages", do_missedmessage_unsubscribe),
"welcome": ("welcome", do_welcome_unsubscribe)
"welcome": ("welcome", do_welcome_unsubscribe),
"digest": ("digest", do_digest_unsubscribe)
}
# Login NOT required. These are for one-click unsubscribes.