mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	Add one-click unsubscribe links to day 1 and day 2 emails.
(imported from commit 9396f96365430baf894c708f9eaea642fc648435)
This commit is contained in:
		@@ -47,6 +47,12 @@ def fn(arg):
 | 
			
		||||
</td></tr>
 | 
			
		||||
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
<p>
 | 
			
		||||
  <a href="https://{{ external_host }}/#settings">Manage email preferences</a> |
 | 
			
		||||
  <a href="{{ unsubscribe_link }}">Unsubscribe from welcome emails</a>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
 
 | 
			
		||||
@@ -24,3 +24,12 @@ https://{{ external_host }}/hello has a nice overview of what we're up to, but h
 | 
			
		||||
Zulip is under active development, and we have a team of engineers standing by to respond to your feedback, so please report bugs and let us know what you think! There's a feedback tab under the gear icon in the upper-right corner, or you can e-mail us at feedback@zulip.com.
 | 
			
		||||
{% endif %}
 | 
			
		||||
-Waseem, for the Zulip team
 | 
			
		||||
 | 
			
		||||
--
 | 
			
		||||
Manage email preferences:
 | 
			
		||||
 | 
			
		||||
https://{{ external_host }}/#settings
 | 
			
		||||
 | 
			
		||||
Unsubscribe from welcome emails:
 | 
			
		||||
 | 
			
		||||
{{ unsubscribe_link }}
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,12 @@ and <b>topics</b>.</p>
 | 
			
		||||
</td></tr>
 | 
			
		||||
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
<p>
 | 
			
		||||
  <a href="https://{{ external_host }}/#settings">Manage email preferences</a> |
 | 
			
		||||
  <a href="{{ unsubscribe_link }}">Unsubscribe from welcome emails</a>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</html>
 | 
			
		||||
 
 | 
			
		||||
@@ -19,3 +19,12 @@ Some tips:
 | 
			
		||||
Try it out now! https://{{ external_host }}
 | 
			
		||||
 | 
			
		||||
-Waseem, for the Zulip team
 | 
			
		||||
 | 
			
		||||
--
 | 
			
		||||
Manage email preferences:
 | 
			
		||||
 | 
			
		||||
https://{{ external_host }}/#settings
 | 
			
		||||
 | 
			
		||||
Unsubscribe from welcome emails:
 | 
			
		||||
 | 
			
		||||
{{ unsubscribe_link }}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,8 +4,7 @@
 | 
			
		||||
 | 
			
		||||
<h1>Email settings updated</h1>
 | 
			
		||||
 | 
			
		||||
<p>We've updated your email subscription settings, and you won't get emails
 | 
			
		||||
about {{ subscription_type }} anymore.</p>
 | 
			
		||||
<p>We've updated your email subscription settings, and you won't get {{ subscription_type }} emails anymore.</p>
 | 
			
		||||
 | 
			
		||||
<p>To undo this change or review your other subscription settings, please visit your <a href="https://{{ external_host }}/#settings">Zulip Settings page</a>.</p>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ from zerver.lib.actions import bulk_remove_subscriptions, \
 | 
			
		||||
    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, \
 | 
			
		||||
    do_set_muted_topics, do_rename_stream, \
 | 
			
		||||
    do_set_muted_topics, do_rename_stream, clear_followup_emails_queue, \
 | 
			
		||||
    notify_for_streams_by_default, do_change_enable_offline_push_notifications, \
 | 
			
		||||
    do_deactivate_stream
 | 
			
		||||
from zerver.lib.create_user import random_api_key
 | 
			
		||||
@@ -2331,22 +2331,34 @@ def remove_apns_device_token(request, user_profile, token=REQ):
 | 
			
		||||
def generate_204(request):
 | 
			
		||||
    return HttpResponse(content=None, status=204)
 | 
			
		||||
 | 
			
		||||
def process_missedmessages_unsubscribe(token):
 | 
			
		||||
def process_unsubscribe(token, type, unsubscribe_function):
 | 
			
		||||
    try:
 | 
			
		||||
        confirmation = Confirmation.objects.get(confirmation_key=token)
 | 
			
		||||
    except Confirmation.DoesNotExist:
 | 
			
		||||
        return render_to_response('zerver/unsubscribe_link_error.html')
 | 
			
		||||
 | 
			
		||||
    user_profile = confirmation.content_object
 | 
			
		||||
    do_change_enable_offline_email_notifications(user_profile, False)
 | 
			
		||||
    unsubscribe_function(user_profile)
 | 
			
		||||
    return render_to_response('zerver/unsubscribe_success.html',
 | 
			
		||||
                              {"subscription_type": "missed messages",
 | 
			
		||||
                              {"subscription_type": type,
 | 
			
		||||
                               "external_host": settings.EXTERNAL_HOST})
 | 
			
		||||
 | 
			
		||||
# Email unsubscribe functions. All have the function signature
 | 
			
		||||
# processor(user_profile).
 | 
			
		||||
 | 
			
		||||
def do_missedmessage_unsubscribe(user_profile):
 | 
			
		||||
    do_change_enable_offline_email_notifications(user_profile, False)
 | 
			
		||||
 | 
			
		||||
def do_welcome_unsubscribe(user_profile):
 | 
			
		||||
    clear_followup_emails_queue(user_profile.email)
 | 
			
		||||
 | 
			
		||||
email_unsubscribers = {"missed_messages": do_missedmessage_unsubscribe,
 | 
			
		||||
                       "welcome": do_welcome_unsubscribe}
 | 
			
		||||
 | 
			
		||||
# Login NOT required. These are for one-click unsubscribes.
 | 
			
		||||
def email_unsubscribe(request, type, token):
 | 
			
		||||
    if type == "missed_messages":
 | 
			
		||||
        return process_missedmessages_unsubscribe(token)
 | 
			
		||||
    if type in email_unsubscribers:
 | 
			
		||||
        return process_unsubscribe(token, type, email_unsubscribers[type])
 | 
			
		||||
 | 
			
		||||
    return render_to_response('zerver/unsubscribe_link_error.html', {},
 | 
			
		||||
                              context_instance=RequestContext(request))
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ from zerver.lib.timestamp import timestamp_to_datetime
 | 
			
		||||
from zerver.lib.actions import handle_missedmessage_emails, do_send_confirmation_email, \
 | 
			
		||||
    do_update_user_activity, do_update_user_activity_interval, do_update_user_presence, \
 | 
			
		||||
    internal_send_message, send_local_email_template_with_delay, clear_followup_emails_queue, \
 | 
			
		||||
    check_send_message, extract_recipients
 | 
			
		||||
    check_send_message, extract_recipients, one_click_unsubscribe_link
 | 
			
		||||
from zerver.lib.digest import handle_digest_email
 | 
			
		||||
from zerver.decorator import JsonableError
 | 
			
		||||
from zerver.lib.socket import req_redis_key
 | 
			
		||||
@@ -113,9 +113,13 @@ class SignupWorker(QueueProcessingWorker):
 | 
			
		||||
        if settings.ENTERPRISE:
 | 
			
		||||
            sender = {'email': settings.ZULIP_ADMINISTRATOR, 'name': 'Zulip'}
 | 
			
		||||
 | 
			
		||||
        user_profile = get_user_profile_by_email(email)
 | 
			
		||||
        unsubscribe_link = one_click_unsubscribe_link(user_profile, "welcome")
 | 
			
		||||
 | 
			
		||||
        template_payload = {'name': name,
 | 
			
		||||
                            'not_enterprise': not settings.ENTERPRISE,
 | 
			
		||||
                            'external_host': settings.EXTERNAL_HOST}
 | 
			
		||||
                            'external_host': settings.EXTERNAL_HOST,
 | 
			
		||||
                            'unsubscribe_link': unsubscribe_link}
 | 
			
		||||
 | 
			
		||||
        #Send day 1 email
 | 
			
		||||
        send_local_email_template_with_delay([{'email': email, 'name': name}],
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user