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