invites: Migrate to non-legacy API format.

This has the side effect of making it possible for a bot user to
invite users with its API key, which seems useful.
This commit is contained in:
Tim Abbott 2017-07-31 11:55:57 -07:00
parent 6a50e13156
commit ed10ce70d4
7 changed files with 21 additions and 18 deletions

View File

@ -6,7 +6,7 @@
<h3 id="invite-user-label">{% trans %}Invite users to Zulip{% endtrans %}</h3>
</div>
<form id="invite_user_form" class="form-horizontal"
action="/json/invite_users" method="POST">{{ csrf_input }}
action="/json/invites" method="POST">{{ csrf_input }}
<div class="modal-body">
<div class="control-group">
<div id="invite-result"></div>

View File

@ -91,7 +91,7 @@ class JsonTranslationTestCase(ZulipTestCase):
email = self.example_email('hamlet')
self.login(email)
result = self.client_post("/json/invite_users",
result = self.client_post("/json/invites",
HTTP_ACCEPT_LANGUAGE='de')
expected_error = u"this arg is bad: 'invitee_emails' (translated to German)"

View File

@ -359,7 +359,7 @@ class InviteUserTest(ZulipTestCase):
streams should be a list of strings.
"""
return self.client_post("/json/invite_users",
return self.client_post("/json/invites",
{"invitee_emails": users,
"stream": streams,
"custom_body": body})
@ -387,7 +387,7 @@ class InviteUserTest(ZulipTestCase):
def test_successful_invite_user(self):
# type: () -> None
"""
A call to /json/invite_users with valid parameters causes an invitation
A call to /json/invites with valid parameters causes an invitation
email to be sent.
"""
self.login(self.example_email("hamlet"))
@ -399,7 +399,7 @@ class InviteUserTest(ZulipTestCase):
def test_successful_invite_user_with_custom_body(self):
# type: () -> None
"""
A call to /json/invite_users with valid parameters causes an invitation
A call to /json/invites with valid parameters causes an invitation
email to be sent.
"""
self.login(self.example_email("hamlet"))
@ -412,7 +412,7 @@ class InviteUserTest(ZulipTestCase):
def test_successful_invite_user_with_name(self):
# type: () -> None
"""
A call to /json/invite_users with valid parameters causes an invitation
A call to /json/invites with valid parameters causes an invitation
email to be sent.
"""
self.login(self.example_email("hamlet"))
@ -425,7 +425,7 @@ class InviteUserTest(ZulipTestCase):
def test_successful_invite_user_with_name_and_normal_one(self):
# type: () -> None
"""
A call to /json/invite_users with valid parameters causes an invitation
A call to /json/invites with valid parameters causes an invitation
email to be sent.
"""
self.login(self.example_email("hamlet"))
@ -463,7 +463,7 @@ class InviteUserTest(ZulipTestCase):
def test_successful_invite_user_with_notifications_stream(self):
# type: () -> None
"""
A call to /json/invite_users with valid parameters unconditionally
A call to /json/invites with valid parameters unconditionally
subscribes the invitee to the notifications stream if it exists and is
public.
"""
@ -533,8 +533,9 @@ earl-test@zulip.com""", ["Denmark"]))
"""
self.login(self.example_email("hamlet"))
self.assert_json_error(
self.client_post("/json/invite_users", {"invitee_emails": "foo@zulip.com",
"custom_body": ''}),
self.client_post("/json/invites",
{"invitee_emails": "foo@zulip.com",
"custom_body": ''}),
"You must specify at least one stream for invitees to join.")
for address in ("noatsign.com", "outsideyourdomain@example.net"):
@ -565,7 +566,7 @@ earl-test@zulip.com""", ["Denmark"]))
"""
self.login(self.example_email("hamlet"))
self.assert_json_error(
self.client_post("/json/invite_users",
self.client_post("/json/invites",
{"invitee_emails": self.example_email("hamlet"),
"stream": ["Denmark"],
"custom_body": ''}),
@ -585,7 +586,7 @@ earl-test@zulip.com""", ["Denmark"]))
existing = [self.example_email("hamlet"), u"othello@zulip.com"]
new = [u"foo-test@zulip.com", u"bar-test@zulip.com"]
result = self.client_post("/json/invite_users",
result = self.client_post("/json/invites",
{"invitee_emails": "\n".join(existing + new),
"stream": ["Denmark"],
"custom_body": ''})

View File

@ -64,7 +64,7 @@ class PublicURLTest(ZulipTestCase):
post_urls = {200: ["/accounts/login/"],
302: ["/accounts/logout/"],
401: ["/json/messages",
"/json/invite_users",
"/json/invites",
"/json/subscriptions/exists",
"/api/v1/users/me/subscriptions/properties",
"/json/fetch_api_key",

View File

@ -17,11 +17,10 @@ from zerver.models import PreregistrationUser, Stream, UserProfile
import re
@authenticated_json_post_view
@has_request_variables
def json_invite_users(request, user_profile,
invitee_emails_raw=REQ("invitee_emails"),
body=REQ("custom_body", default=None)):
def invite_users_backend(request, user_profile,
invitee_emails_raw=REQ("invitee_emails"),
body=REQ("custom_body", default=None)):
# type: (HttpRequest, UserProfile, str, Optional[str]) -> HttpResponse
if user_profile.realm.invite_by_admins_only and not user_profile.is_realm_admin:
return json_error(_("Must be a realm administrator"))

View File

@ -14,7 +14,6 @@ import zerver.views.muting
legacy_urls = [
# These are json format views used by the web client. They require a logged in browser.
url(r'^json/invite_users$', zerver.views.invite.json_invite_users),
# We should remove this endpoint and all code related to it.
# It returns a 404 if the stream doesn't exist, which is confusing

View File

@ -244,6 +244,10 @@ v1_api_and_json_patterns = [
{'PATCH': 'zerver.views.users.patch_bot_backend',
'DELETE': 'zerver.views.users.deactivate_bot_backend'}),
# invites -> zerver.views.invite
url(r'^invites$', rest_dispatch,
{'POST': 'zerver.views.invite.invite_users_backend'}),
# messages -> zerver.views.messages
# GET returns messages, possibly filtered, POST sends a message
url(r'^messages$', rest_dispatch,