mirror of
https://github.com/zulip/zulip.git
synced 2025-10-31 20:13:46 +00:00
@@ -4,12 +4,22 @@ from typing import Dict, Any
|
||||
from django.http import HttpRequest
|
||||
from django.conf import settings
|
||||
|
||||
from zerver.models import get_realm_by_string_id
|
||||
from zerver.models import UserProfile, get_realm_by_string_id
|
||||
from zproject.backends import (password_auth_enabled, dev_auth_enabled,
|
||||
google_auth_enabled, github_auth_enabled)
|
||||
from zerver.lib.utils import get_subdomain
|
||||
|
||||
|
||||
def common_context(user):
|
||||
# type: (UserProfile) -> Dict[str, Any]
|
||||
return {
|
||||
'realm_uri': user.realm.uri,
|
||||
'server_uri': settings.SERVER_URI,
|
||||
'external_uri_scheme': settings.EXTERNAL_URI_SCHEME,
|
||||
'external_host': settings.EXTERNAL_HOST,
|
||||
}
|
||||
|
||||
|
||||
def add_settings(request):
|
||||
# type: (HttpRequest) -> Dict[str, Any]
|
||||
realm = None
|
||||
|
||||
@@ -14,6 +14,7 @@ from zerver.lib.notifications import build_message_list, hashchange_encode, \
|
||||
send_future_email, one_click_unsubscribe_link
|
||||
from zerver.models import UserProfile, UserMessage, Recipient, Stream, \
|
||||
Subscription, get_active_streams
|
||||
from zerver.context_processors import common_context
|
||||
|
||||
import logging
|
||||
|
||||
@@ -166,15 +167,13 @@ def handle_digest_email(user_profile_id, cutoff):
|
||||
user_profile=user_profile,
|
||||
message__pub_date__gt=cutoff_date).order_by("message__pub_date")
|
||||
|
||||
template_payload = common_context(user_profile)
|
||||
|
||||
# Start building email template data.
|
||||
template_payload = {
|
||||
template_payload.update({
|
||||
'name': user_profile.full_name,
|
||||
'external_host': settings.EXTERNAL_HOST,
|
||||
'external_uri_scheme': settings.EXTERNAL_URI_SCHEME,
|
||||
'server_uri': settings.SERVER_URI,
|
||||
'realm_uri': user_profile.realm.uri,
|
||||
'unsubscribe_link': one_click_unsubscribe_link(user_profile, "digest")
|
||||
} # type: Dict[str, Any]
|
||||
})
|
||||
|
||||
# Gather recent missed PMs, re-using the missed PM email logic.
|
||||
# You can't have an unread message that you sent, but when testing
|
||||
|
||||
@@ -235,6 +235,7 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
|
||||
`missed_messages` is a list of Message objects to remind about they should
|
||||
all have the same recipient and subject
|
||||
"""
|
||||
from zerver.context_processors import common_context
|
||||
# Disabled missedmessage emails internally
|
||||
if not user_profile.enable_offline_email_notifications:
|
||||
return
|
||||
@@ -247,19 +248,16 @@ def do_send_missedmessage_events_reply_in_zulip(user_profile, missed_messages, m
|
||||
)
|
||||
|
||||
unsubscribe_link = one_click_unsubscribe_link(user_profile, "missed_messages")
|
||||
template_payload = {
|
||||
template_payload = common_context(user_profile)
|
||||
template_payload.update({
|
||||
'name': user_profile.full_name,
|
||||
'messages': build_message_list(user_profile, missed_messages),
|
||||
'message_count': message_count,
|
||||
'reply_warning': False,
|
||||
'external_host': settings.EXTERNAL_HOST,
|
||||
'external_uri_scheme': settings.EXTERNAL_URI_SCHEME,
|
||||
'server_uri': settings.SERVER_URI,
|
||||
'realm_uri': user_profile.realm.uri,
|
||||
'mention': missed_messages[0].recipient.type == Recipient.STREAM,
|
||||
'reply_to_zulip': True,
|
||||
'unsubscribe_link': unsubscribe_link,
|
||||
}
|
||||
})
|
||||
|
||||
headers = {}
|
||||
from zerver.lib.email_mirror import create_missed_message_address
|
||||
@@ -469,6 +467,7 @@ def send_local_email_template_with_delay(recipients, template_prefix,
|
||||
|
||||
def enqueue_welcome_emails(email, name):
|
||||
# type: (text_type, text_type) -> None
|
||||
from zerver.context_processors import common_context
|
||||
if settings.WELCOME_EMAIL_SENDER is not None:
|
||||
sender = settings.WELCOME_EMAIL_SENDER # type: Dict[str, text_type]
|
||||
else:
|
||||
@@ -476,13 +475,11 @@ def enqueue_welcome_emails(email, name):
|
||||
|
||||
user_profile = get_user_profile_by_email(email)
|
||||
unsubscribe_link = one_click_unsubscribe_link(user_profile, "welcome")
|
||||
|
||||
template_payload = {'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
|
||||
'external_host': settings.EXTERNAL_HOST,
|
||||
'external_uri_scheme': settings.EXTERNAL_URI_SCHEME,
|
||||
'server_uri': settings.SERVER_URI,
|
||||
'realm_uri': user_profile.realm.uri,
|
||||
'unsubscribe_link': unsubscribe_link}
|
||||
template_payload = common_context(user_profile)
|
||||
template_payload.update({
|
||||
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
|
||||
'unsubscribe_link': unsubscribe_link
|
||||
})
|
||||
|
||||
# Send day 1 email
|
||||
send_local_email_template_with_delay([{'email': email, 'name': name}],
|
||||
|
||||
@@ -8,6 +8,7 @@ from confirmation.models import Confirmation
|
||||
from zerver.lib.actions import do_change_enable_offline_email_notifications, \
|
||||
do_change_enable_digest_emails, clear_followup_emails_queue
|
||||
from zerver.models import UserProfile
|
||||
from zerver.context_processors import common_context
|
||||
from zproject.jinja2 import render_to_response
|
||||
|
||||
def process_unsubscribe(token, subscription_type, unsubscribe_function):
|
||||
@@ -19,13 +20,9 @@ def process_unsubscribe(token, subscription_type, unsubscribe_function):
|
||||
|
||||
user_profile = confirmation.content_object
|
||||
unsubscribe_function(user_profile)
|
||||
return render_to_response('zerver/unsubscribe_success.html',
|
||||
{"subscription_type": subscription_type,
|
||||
"external_host": settings.EXTERNAL_HOST,
|
||||
'external_uri_scheme': settings.EXTERNAL_URI_SCHEME,
|
||||
'server_uri': settings.SERVER_URI,
|
||||
'realm_uri': user_profile.realm.uri,
|
||||
})
|
||||
context = common_context(user_profile)
|
||||
context.update({"subscription_type": subscription_type})
|
||||
return render_to_response('zerver/unsubscribe_success.html', context)
|
||||
|
||||
# Email unsubscribe functions. All have the function signature
|
||||
# processor(user_profile).
|
||||
|
||||
@@ -23,6 +23,7 @@ from confirmation.models import Confirmation
|
||||
from zerver.lib.db import reset_queries
|
||||
from django.core.mail import EmailMessage
|
||||
from zerver.lib.redis_utils import get_redis_client
|
||||
from zerver.context_processors import common_context
|
||||
|
||||
import os
|
||||
import sys
|
||||
@@ -152,16 +153,17 @@ class ConfirmationEmailWorker(QueueProcessingWorker):
|
||||
|
||||
# queue invitation reminder for two days from now.
|
||||
link = Confirmation.objects.get_link_for_object(invitee, host=referrer.realm.host)
|
||||
send_local_email_template_with_delay([{'email': data["email"], 'name': ""}],
|
||||
"zerver/emails/invitation/invitation_reminder_email",
|
||||
{'activate_url': link,
|
||||
context = common_context(referrer)
|
||||
context.update({
|
||||
'activate_url': link,
|
||||
'referrer': referrer,
|
||||
'verbose_support_offers': settings.VERBOSE_SUPPORT_OFFERS,
|
||||
'external_host': settings.EXTERNAL_HOST,
|
||||
'external_uri_scheme': settings.EXTERNAL_URI_SCHEME,
|
||||
'server_uri': settings.SERVER_URI,
|
||||
'realm_uri': referrer.realm.uri,
|
||||
'support_email': settings.ZULIP_ADMINISTRATOR},
|
||||
'support_email': settings.ZULIP_ADMINISTRATOR
|
||||
})
|
||||
send_local_email_template_with_delay(
|
||||
[{'email': data["email"], 'name': ""}],
|
||||
"zerver/emails/invitation/invitation_reminder_email",
|
||||
context,
|
||||
datetime.timedelta(days=2),
|
||||
tags=["invitation-reminders"],
|
||||
sender={'email': settings.ZULIP_ADMINISTRATOR, 'name': 'Zulip'})
|
||||
|
||||
Reference in New Issue
Block a user