mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
parent
00178d114b
commit
47fcb27e39
@ -2279,10 +2279,6 @@ button.topic_edit_cancel {
|
||||
max-height: 300px;
|
||||
}
|
||||
|
||||
#invite-user #custom_invite_body {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#invite-user .overlay-content {
|
||||
position: relative;
|
||||
width: 500px;
|
||||
|
||||
@ -5,25 +5,22 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p>Hi there,
|
||||
</p>
|
||||
<p>
|
||||
{{ referrer.full_name }} ({{ referrer.email }}) wants you to join
|
||||
them on Zulip — the team communication tool designed for
|
||||
productivity.
|
||||
</p>
|
||||
{% if custom_body %}
|
||||
<p>Message from {{ referrer.full_name }}: {{ custom_body }}</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
To get started, please click here:
|
||||
<a class="button" href="{{ activate_url }}">Complete registration</a>
|
||||
</p>
|
||||
<p>
|
||||
Feel free to give us a shout at <a href="mailto:{{ support_email }}">{{ support_email }}</a>, if you have any questions.
|
||||
</p>
|
||||
<p>
|
||||
Cheers,<br />
|
||||
Team Zulip
|
||||
</p>
|
||||
<p>Hi there,
|
||||
</p>
|
||||
<p>
|
||||
{{ referrer.full_name }} ({{ referrer.email }}) wants you to join
|
||||
them on Zulip — the team communication tool designed for
|
||||
productivity.
|
||||
</p>
|
||||
<p>
|
||||
To get started, please click here:
|
||||
<a class="button" href="{{ activate_url }}">Complete registration</a>
|
||||
</p>
|
||||
<p>
|
||||
Feel free to give us a shout at <a href="mailto:{{ support_email }}">{{ support_email }}</a>, if you have any questions.
|
||||
</p>
|
||||
<p>
|
||||
Cheers,<br />
|
||||
Team Zulip
|
||||
</p>
|
||||
{% endblock %}
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
Hi there,
|
||||
|
||||
{{ referrer.full_name }} ({{ referrer.email }}) wants you to join them on Zulip -- the team communication tool designed for productivity.
|
||||
{% if custom_body %}
|
||||
Message from {{ referrer.full_name }}: {{ custom_body }}
|
||||
{% endif %}
|
||||
|
||||
To get started, visit the link below:
|
||||
<{{ activate_url }}>
|
||||
|
||||
|
||||
@ -14,10 +14,6 @@
|
||||
<div class="controls">
|
||||
<textarea rows="2" id="invitee_emails" name="invitee_emails" placeholder="{{ _('One or more email addresses...') }}"></textarea>
|
||||
</div>
|
||||
<label class="control-label" for="custom_invite_body">{{ _('Custom invitation message (if you want to add one)') }}</label>
|
||||
<div class="controls">
|
||||
<textarea rows="2" id="custom_invite_body" name="custom_body" placeholder="{{ _('Custom message') }}"></textarea>
|
||||
</div>
|
||||
{% if is_admin %}
|
||||
<label class="control-label" id="invite_as_admin" for"invite_as_admin">{{ _('User(s) join as') }}</label>
|
||||
<div class="controls">
|
||||
|
||||
@ -3856,8 +3856,7 @@ def get_cross_realm_dicts() -> List[Dict[str, Any]]:
|
||||
if user.realm.string_id == settings.SYSTEM_BOT_REALM]
|
||||
|
||||
def do_send_confirmation_email(invitee: PreregistrationUser,
|
||||
referrer: UserProfile,
|
||||
body: Optional[str]) -> None:
|
||||
referrer: UserProfile) -> None:
|
||||
"""
|
||||
Send the confirmation/welcome e-mail to an invited user.
|
||||
|
||||
@ -3865,7 +3864,7 @@ def do_send_confirmation_email(invitee: PreregistrationUser,
|
||||
`referrer` is a UserProfile.
|
||||
"""
|
||||
activation_url = create_confirmation_link(invitee, referrer.realm.host, Confirmation.INVITATION)
|
||||
context = {'referrer': referrer, 'custom_body': body, 'activate_url': activation_url,
|
||||
context = {'referrer': referrer, 'activate_url': activation_url,
|
||||
'referrer_realm_name': referrer.realm.name}
|
||||
from_name = u"%s (via Zulip)" % (referrer.full_name,)
|
||||
send_email('zerver/emails/invitation', to_email=invitee.email, from_name=from_name,
|
||||
@ -3950,8 +3949,7 @@ def check_invite_limit(user: UserProfile, num_invitees: int) -> None:
|
||||
def do_invite_users(user_profile: UserProfile,
|
||||
invitee_emails: SizedTextIterable,
|
||||
streams: Iterable[Stream],
|
||||
invite_as_admin: Optional[bool]=False,
|
||||
body: Optional[str]=None) -> None:
|
||||
invite_as_admin: Optional[bool]=False) -> None:
|
||||
|
||||
check_invite_limit(user_profile, len(invitee_emails))
|
||||
|
||||
@ -3996,7 +3994,7 @@ def do_invite_users(user_profile: UserProfile,
|
||||
stream_ids = [stream.id for stream in streams]
|
||||
prereg_user.streams.set(stream_ids)
|
||||
|
||||
event = {"prereg_id": prereg_user.id, "referrer_id": user_profile.id, "email_body": body}
|
||||
event = {"prereg_id": prereg_user.id, "referrer_id": user_profile.id}
|
||||
queue_json_publish("invites", event)
|
||||
|
||||
if skipped:
|
||||
|
||||
@ -208,14 +208,6 @@ def find_key_by_email(address: Text) -> Optional[Text]:
|
||||
return key_regex.search(message.body).groups()[0]
|
||||
return None # nocoverage -- in theory a test might want this case, but none do
|
||||
|
||||
def find_pattern_in_email(address: Text, pattern: Text) -> Optional[Text]:
|
||||
from django.core.mail import outbox
|
||||
key_regex = re.compile(pattern)
|
||||
for message in reversed(outbox):
|
||||
if address in message.to:
|
||||
return key_regex.search(message.body).group(0)
|
||||
return None # nocoverage -- in theory a test might want this case, but none do
|
||||
|
||||
def message_stream_count(user_profile: UserProfile) -> int:
|
||||
return UserMessage.objects. \
|
||||
select_related("message"). \
|
||||
|
||||
@ -49,7 +49,7 @@ from zerver.lib.mobile_auth_otp import xor_hex_strings, ascii_to_hex, \
|
||||
from zerver.lib.notifications import enqueue_welcome_emails, \
|
||||
one_click_unsubscribe_link
|
||||
from zerver.lib.subdomains import is_root_domain_available
|
||||
from zerver.lib.test_helpers import find_pattern_in_email, find_key_by_email, queries_captured, \
|
||||
from zerver.lib.test_helpers import find_key_by_email, queries_captured, \
|
||||
HostRequestMock, load_subdomain_token
|
||||
from zerver.lib.test_classes import (
|
||||
ZulipTestCase,
|
||||
@ -446,7 +446,6 @@ class LoginTest(ZulipTestCase):
|
||||
|
||||
class InviteUserBase(ZulipTestCase):
|
||||
def check_sent_emails(self, correct_recipients: List[Text],
|
||||
custom_body: Optional[str]=None,
|
||||
custom_from_name: Optional[str]=None) -> None:
|
||||
from django.core.mail import outbox
|
||||
self.assertEqual(len(outbox), len(correct_recipients))
|
||||
@ -455,12 +454,6 @@ class InviteUserBase(ZulipTestCase):
|
||||
if len(outbox) == 0:
|
||||
return
|
||||
|
||||
if custom_body is None:
|
||||
self.assertNotIn("Message from", outbox[0].body)
|
||||
else:
|
||||
self.assertIn("Message from ", outbox[0].body)
|
||||
self.assertIn(custom_body, outbox[0].body)
|
||||
|
||||
if custom_from_name is not None:
|
||||
self.assertIn(custom_from_name, outbox[0].from_email)
|
||||
|
||||
@ -480,8 +473,7 @@ class InviteUserBase(ZulipTestCase):
|
||||
return self.client_post("/json/invites",
|
||||
{"invitee_emails": users,
|
||||
"stream": streams,
|
||||
"invite_as_admin": invite_as_admin,
|
||||
"custom_body": body})
|
||||
"invite_as_admin": invite_as_admin})
|
||||
|
||||
class InviteUserTest(InviteUserBase):
|
||||
def test_successful_invite_user(self) -> None:
|
||||
@ -519,18 +511,6 @@ class InviteUserTest(InviteUserBase):
|
||||
response = self.invite(invitee, ["Denmark"], invite_as_admin="true")
|
||||
self.assert_json_error(response, "Must be a realm administrator")
|
||||
|
||||
def test_successful_invite_user_with_custom_body(self) -> None:
|
||||
"""
|
||||
A call to /json/invites with valid parameters causes an invitation
|
||||
email to be sent.
|
||||
"""
|
||||
self.login(self.example_email("hamlet"))
|
||||
invitee = "alice-test@zulip.com"
|
||||
body = "Custom Text."
|
||||
self.assert_json_success(self.invite(invitee, ["Denmark"], body))
|
||||
self.assertTrue(find_pattern_in_email(invitee, body))
|
||||
self.check_sent_emails([invitee], custom_body=body, custom_from_name="Hamlet")
|
||||
|
||||
def test_successful_invite_user_with_name(self) -> None:
|
||||
"""
|
||||
A call to /json/invites with valid parameters causes an invitation
|
||||
@ -671,15 +651,13 @@ earl-test@zulip.com""", ["Denmark"]))
|
||||
self.login(self.example_email("iago"))
|
||||
self.client_post("/json/invites",
|
||||
{"invitee_emails": "1@zulip.com, 2@zulip.com",
|
||||
"stream": ["Denmark"],
|
||||
"custom_body": ''}),
|
||||
"stream": ["Denmark"]}),
|
||||
|
||||
self.assert_json_error(
|
||||
self.client_post("/json/invites",
|
||||
{"invitee_emails": ", ".join(
|
||||
[str(i) for i in range(get_realm("zulip").max_invites - 1)]),
|
||||
"stream": ["Denmark"],
|
||||
"custom_body": ''}),
|
||||
"stream": ["Denmark"]}),
|
||||
"You do not have enough remaining invites. "
|
||||
"Please contact zulip-admin@example.com to have your limit raised. "
|
||||
"No invitations were sent.")
|
||||
@ -691,8 +669,7 @@ earl-test@zulip.com""", ["Denmark"]))
|
||||
self.login(self.example_email("hamlet"))
|
||||
self.assert_json_error(
|
||||
self.client_post("/json/invites",
|
||||
{"invitee_emails": "foo@zulip.com",
|
||||
"custom_body": ''}),
|
||||
{"invitee_emails": "foo@zulip.com"}),
|
||||
"You must specify at least one stream for invitees to join.")
|
||||
|
||||
for address in ("noatsign.com", "outsideyourdomain@example.net"):
|
||||
@ -723,8 +700,7 @@ earl-test@zulip.com""", ["Denmark"]))
|
||||
self.assert_json_error(
|
||||
self.client_post("/json/invites",
|
||||
{"invitee_emails": self.example_email("hamlet"),
|
||||
"stream": ["Denmark"],
|
||||
"custom_body": ''}),
|
||||
"stream": ["Denmark"]}),
|
||||
"We weren't able to invite anyone.")
|
||||
self.assertRaises(PreregistrationUser.DoesNotExist,
|
||||
lambda: PreregistrationUser.objects.get(
|
||||
@ -742,8 +718,7 @@ earl-test@zulip.com""", ["Denmark"]))
|
||||
|
||||
result = self.client_post("/json/invites",
|
||||
{"invitee_emails": "\n".join(existing + new),
|
||||
"stream": ["Denmark"],
|
||||
"custom_body": ''})
|
||||
"stream": ["Denmark"]})
|
||||
self.assert_json_error(result,
|
||||
"Some of those addresses are already using Zulip, \
|
||||
so we didn't send them an invitation. We did send invitations to everyone else!")
|
||||
|
||||
@ -69,7 +69,7 @@ def generate_all_emails(request: HttpRequest) -> HttpResponse:
|
||||
|
||||
# New user invite and reminder emails
|
||||
result = client.post("/json/invites",
|
||||
{"invitee_emails": unregistered_email_2, "stream": ["Denmark"], "custom_body": ""},
|
||||
{"invitee_emails": unregistered_email_2, "stream": ["Denmark"]},
|
||||
**host_kwargs)
|
||||
assert result.status_code == 200
|
||||
|
||||
|
||||
@ -19,9 +19,8 @@ import re
|
||||
@has_request_variables
|
||||
def invite_users_backend(request, user_profile,
|
||||
invitee_emails_raw=REQ("invitee_emails"),
|
||||
invite_as_admin=REQ(validator=check_bool, default=False),
|
||||
body=REQ("custom_body", default=None)):
|
||||
# type: (HttpRequest, UserProfile, str, Optional[bool], Optional[str]) -> HttpResponse
|
||||
invite_as_admin=REQ(validator=check_bool, default=False)):
|
||||
# type: (HttpRequest, UserProfile, str, Optional[bool]) -> HttpResponse
|
||||
|
||||
if user_profile.realm.invite_by_admins_only and not user_profile.is_realm_admin:
|
||||
return json_error(_("Must be a realm administrator"))
|
||||
@ -29,8 +28,6 @@ def invite_users_backend(request, user_profile,
|
||||
return json_error(_("Must be a realm administrator"))
|
||||
if not invitee_emails_raw:
|
||||
return json_error(_("You must specify at least one email address."))
|
||||
if body == '':
|
||||
body = None
|
||||
|
||||
invitee_emails = get_invitee_emails_set(invitee_emails_raw)
|
||||
|
||||
@ -52,7 +49,7 @@ def invite_users_backend(request, user_profile,
|
||||
return json_error(_("Stream does not exist: %s. No invites were sent.") % (stream_name,))
|
||||
streams.append(stream)
|
||||
|
||||
do_invite_users(user_profile, invitee_emails, streams, invite_as_admin, body)
|
||||
do_invite_users(user_profile, invitee_emails, streams, invite_as_admin)
|
||||
return json_success()
|
||||
|
||||
def get_invitee_emails_set(invitee_emails_raw: str) -> Set[str]:
|
||||
|
||||
@ -232,9 +232,8 @@ class ConfirmationEmailWorker(QueueProcessingWorker):
|
||||
return
|
||||
|
||||
referrer = get_user_profile_by_id(data["referrer_id"])
|
||||
body = data["email_body"]
|
||||
logging.info("Sending invitation for realm %s to %s" % (referrer.realm.string_id, invitee.email))
|
||||
do_send_confirmation_email(invitee, referrer, body)
|
||||
do_send_confirmation_email(invitee, referrer)
|
||||
|
||||
# queue invitation reminder for two days from now.
|
||||
link = create_confirmation_link(invitee, referrer.realm.host, Confirmation.INVITATION)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user