emails: Cleanup followup day1 email.

This commit is contained in:
Vishnu Ks
2018-11-14 11:46:56 +00:00
committed by Tim Abbott
parent 3e3eb2aa7f
commit 3258ce1fa4
8 changed files with 148 additions and 71 deletions

View File

@@ -5,50 +5,45 @@
{% endblock %}
{% block content %}
<p>{{ _('Hi there,') }}</p>
<p>{{ _('Welcome to Zulip!') }}</p>
<p>{{ _('Welcome to Zulip! A few tips to get you started:') }}</p>
<p>
&bull;
{% if realm_creation %}
{% trans %}
Zulip works best when it's always open, so we suggest downloading
our <a href="https://zulipchat.com/apps">desktop and mobile apps</a>.
You've created the new Zulip organization <b>{{ realm_name }}</b>.
{% endtrans %}
<br/><br/>
{% else %}
{% trans %}
To access your account from the apps, enter this Organization URL:
You've joined the Zulip organization <b>{{ realm_name }}</b>.
{% endtrans %}
{% endif %}
</p>
<p>
{{ _('Your account details:') }}
<li>{{ _('Organization URL:') }} {{ realm_uri }}<br/></li>
{% if ldap_username %}
<li>{{ _('Use your LDAP account to login') }}<br/></li>
{% else %}
<li>{{ _('Email:') }} {{ email }}<br/></li>
{% endif %}
{% trans %}
(you'll need these to sign in to the <a href="https://zulipchat.com/apps">mobile and desktop</a> apps)
{% endtrans %}
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;<b>{{ realm_uri }}</b>
</p>
<p>
&bull;
{% if is_realm_admin %}
{% trans %}
Become a Zulip pro with a few
<a href="{{ keyboard_shortcuts_link }}">keyboard shortcuts</a>:
Check out our <a href="{{ getting_started_link }}">guide for admins</a>, become a Zulip pro with a
few <a href="{{ keyboard_shortcuts_link }}">keyboard shortcuts</a>, or <a href="{{ realm_uri }}">dive right in</a>!
{% endtrans %}
<br/>
<b>n</b>: {{ _('Next unread thread') }}<br/>
<b>r</b>: {{ _('Reply to message under the blue box') }}<br/>
<b>c</b>: {{ _('Start a new topic') }}
</p>
<p>
&bull;
{% else %}
{% trans %}
Give our <a href="{{ getting_started_link }}">guide for new
{{ user_role_group }}</a> a spin.
{% endtrans %}
</p>
<p>
<br/>
{% trans %}
Zulip combines the real-time ease of chat with the threaded organization
of email. Zulip is about productivity&mdash;making communication fun and
easy, while avoiding the distracting and disorganized conversations of
chatrooms. We hope you love using Zulip as much as we do.
<a href="{{ getting_started_link }}">Learn more</a> about Zulip, become a pro with a few
<a href="{{ keyboard_shortcuts_link }}">keyboard shortcuts</a>, or <a href="{{ realm_uri }}">dive right in</a>!
{% endtrans %}
{% endif %}
</p>
<p>

View File

@@ -1 +1,9 @@
{{ _('Welcome to Zulip') }}
{% if realm_creation %}
{% trans %}
{{ realm_name }} on Zulip: Your new organization details
{% endtrans %}
{% else %}
{% trans %}
{{ realm_name }} on Zulip: Your new account details
{% endtrans %}
{% endif %}

View File

@@ -1,34 +1,37 @@
{{ _('Hi there,') }}
{{ _('Welcome to Zulip! A few tips to get you started:') }}
{{ _('Welcome to Zulip!') }}
{% if realm_creation %}
{% trans %}
* Zulip works best when it's always open, so we suggest pinning a browser
tab or downloading our desktop and mobile apps (https://zulipchat.com/apps).
You've created the new Zulip organization {{ realm_name }}.
{% endtrans %}
{% else %}
{% trans %}
You've joined the Zulip organization {{ realm_name }}.
{% endtrans %}
{% endif %}
{{ _('Your account details:') }}
* {{ _('Organization URL:') }} {{ realm_uri }}
{% if ldap_username %}
* {{ _('LDAP username:') }} {{ ldap_username }}
{% else %}
* {{ _('Email:') }} {{ email }}
{% endif %}
{% trans %}
(you'll need these to sign in to the mobile and desktop apps (https://zulipchat.com/apps))
{% endtrans %}
{% if is_realm_admin %}
{% trans %}
To access your account from the apps, enter this Organization URL:
Check out our guide ({{ getting_started_link }}) for admins, become a Zulip pro with a
few keyboard shortcuts ({{ keyboard_shortcuts_link }}), or dive right in to {{ realm_uri }}!
{% endtrans %}
{{ realm_uri }}
* {{ _('Become a Zulip pro with a few keyboard shortcuts:') }}
n: {{ _('Next unread thread') }}
r: {{ _('Reply to message under the blue box') }}
c: {{ _('Start a new topic') }}
{% else %}
{% trans %}
* Give our guide for new {{ user_role_group }} ({{ getting_started_link }})
a spin.
{% endtrans %}
{% trans %}
* Zulip combines the real-time ease of chat with the threaded organization
of email. Zulip is about productivity---making communication fun and
easy, while avoiding the distracting and disorganized conversations of
chatrooms. We hope you love using Zulip as much as we do.
Learn more ({{ getting_started_link }}) about Zulip, become a pro with a few keyboard
shortcuts ({{ keyboard_shortcuts_link }}), or dive right in to {{ realm_uri }}!
{% endtrans %}
{% endif %}
{{ _("Cheers,") }}
{{ _("Team Zulip") }}

View File

@@ -8,4 +8,4 @@ ZULIP_VERSION = "1.9.0+git"
# Typically, adding a dependency only requires a minor version bump, and
# removing a dependency requires a major version bump.
PROVISION_VERSION = '26.13'
PROVISION_VERSION = '26.14'

View File

@@ -6,6 +6,8 @@ from django.conf import settings
from django.template import loader
from django.utils.timezone import now as timezone_now
from django.utils.translation import ugettext as _
from django.contrib.auth import get_backends
from django_auth_ldap.backend import LDAPBackend
from zerver.decorator import statsd_increment
from zerver.lib.message import bulk_access_messages
@@ -507,14 +509,20 @@ def enqueue_welcome_emails(user: UserProfile, realm_creation: bool=False) -> Non
context.update({
'unsubscribe_link': unsubscribe_link,
'keyboard_shortcuts_link': user.realm.uri + '/help/keyboard-shortcuts',
'realm_name': user.realm.name,
'realm_creation': realm_creation,
'email': user.email,
'is_realm_admin': user.is_realm_admin,
})
if user.is_realm_admin:
context['user_role_group'] = _('admins')
context['getting_started_link'] = (user.realm.uri +
'/help/getting-your-organization-started-with-zulip')
else:
context['user_role_group'] = _('members')
context['getting_started_link'] = user.realm.uri + '/help/getting-started-with-zulip'
context['getting_started_link'] = "https://zulipchat.com"
from zproject.backends import email_belongs_to_ldap, require_email_format_usernames
if email_belongs_to_ldap(user.realm, user.email) and not require_email_format_usernames(user.realm):
context["ldap_username"] = True
send_future_email(
"zerver/emails/followup_day1", user.realm, to_user_id=user.id, from_name=from_name,

View File

@@ -12,22 +12,81 @@ from email.utils import formataddr
from mock import patch, MagicMock
from typing import Any, Dict, List, Optional
from zerver.lib.notifications import fix_emojis, \
handle_missedmessage_emails, relative_to_full_url
from zerver.lib.actions import do_update_message, \
do_change_notification_settings
from zerver.lib.notifications import fix_emojis, handle_missedmessage_emails, \
enqueue_welcome_emails, relative_to_full_url
from zerver.lib.actions import do_update_message, do_change_notification_settings
from zerver.lib.message import access_message
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.send_email import FromAddress
from zerver.lib.test_helpers import MockLDAP
from zerver.models import (
get_realm,
get_stream,
Recipient,
UserMessage,
UserProfile,
ScheduledEmail
)
from zerver.lib.test_helpers import get_test_image_file
class TestFollowupEmails(ZulipTestCase):
def test_day1_email_context(self) -> None:
hamlet = self.example_user("hamlet")
enqueue_welcome_emails(hamlet)
scheduled_emails = ScheduledEmail.objects.filter(user=hamlet)
email_data = ujson.loads(scheduled_emails[0].data)
self.assertEqual(email_data["context"]["email"], self.example_email("hamlet"))
self.assertEqual(email_data["context"]["is_realm_admin"], False)
self.assertEqual(email_data["context"]["getting_started_link"], "https://zulipchat.com")
self.assertNotIn("ldap_username", email_data["context"])
ScheduledEmail.objects.all().delete()
iago = self.example_user("iago")
enqueue_welcome_emails(iago)
scheduled_emails = ScheduledEmail.objects.filter(user=iago)
email_data = ujson.loads(scheduled_emails[0].data)
self.assertEqual(email_data["context"]["email"], self.example_email("iago"))
self.assertEqual(email_data["context"]["is_realm_admin"], True)
self.assertEqual(email_data["context"]["getting_started_link"],
"http://zulip.testserver/help/getting-your-organization-started-with-zulip")
self.assertNotIn("ldap_username", email_data["context"])
@override_settings(AUTHENTICATION_BACKENDS=('zproject.backends.ZulipLDAPAuthBackend',
'zproject.backends.ZulipDummyBackend'))
def test_day1_email_ldap_login_credentials(self) -> None:
password = "testing"
email = "newuser@zulip.com"
ldap_user_attr_map = {'full_name': 'fn', 'short_name': 'sn'}
ldap_patcher = patch('django_auth_ldap.config.ldap.initialize')
mock_initialize = ldap_patcher.start()
mock_ldap = MockLDAP()
mock_initialize.return_value = mock_ldap
full_name = 'New LDAP fullname'
mock_ldap.directory = {
'uid=newuser,ou=users,dc=zulip,dc=com': {
'userPassword': 'testing',
'fn': [full_name],
'sn': ['shortname'],
}
}
with self.settings(
LDAP_APPEND_DOMAIN='zulip.com',
AUTH_LDAP_USER_ATTR_MAP=ldap_user_attr_map,
AUTH_LDAP_USER_DN_TEMPLATE='uid=%(user)s,ou=users,dc=zulip,dc=com'):
self.login_with_return(email, password)
user = UserProfile.objects.get(email=email)
scheduled_emails = ScheduledEmail.objects.filter(user=user)
self.assertEqual(len(scheduled_emails), 2)
email_data = ujson.loads(scheduled_emails[0].data)
self.assertEqual(email_data["context"]["ldap_username"], True)
class TestMissedMessages(ZulipTestCase):
def normalize_string(self, s: str) -> str:
s = s.strip()

View File

@@ -463,7 +463,7 @@ class LoginTest(ZulipTestCase):
with queries_captured() as queries:
self.register(self.nonreg_email('test'), "test")
# Ensure the number of queries we make is not O(streams)
self.assert_length(queries, 78)
self.assert_length(queries, 79)
user_profile = self.nonreg_user('test')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
self.assertFalse(user_profile.enable_stream_desktop_notifications)

View File

@@ -102,6 +102,10 @@ def generate_all_emails(request: HttpRequest) -> HttpResponse:
user_profile.email = registered_email
user_profile.save(update_fields=['email'])
# Follow up day1 day2 emails
# Follow up day1 day2 emails for normal user
enqueue_welcome_emails(user_profile)
# Follow up day1 day2 emails for admin user
enqueue_welcome_emails(get_user("iago@zulip.com", realm), realm_creation=True)
return redirect(email_page)