mirror of https://github.com/zulip/zulip.git
[manual] send_message: Rename recipient/stream fields to 'to'.
This commit changes APIs and requires and update of all zephyr mirroring bots to deploy properly. (imported from commit 2672d2d07269379f7a865644aaeb6796d54183e1)
This commit is contained in:
parent
6f10d27f3b
commit
411a7f6b4f
|
@ -59,14 +59,14 @@ if child_pid == 0:
|
||||||
humbug_client.send_message({
|
humbug_client.send_message({
|
||||||
"type": "private",
|
"type": "private",
|
||||||
"content": str(hzkey1),
|
"content": str(hzkey1),
|
||||||
"recipient": humbug_user,
|
"to": humbug_user,
|
||||||
});
|
});
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
humbug_client.send_message({
|
humbug_client.send_message({
|
||||||
"type": "stream",
|
"type": "stream",
|
||||||
"subject": "test",
|
"subject": "test",
|
||||||
"content": str(hzkey2),
|
"content": str(hzkey2),
|
||||||
"stream": "tabbott-nagios-test",
|
"to": "tabbott-nagios-test",
|
||||||
});
|
});
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print "Sent Humbug messages!"
|
print "Sent Humbug messages!"
|
||||||
|
|
|
@ -19,7 +19,7 @@ def forward_message(message):
|
||||||
return
|
return
|
||||||
forwarded_message = {
|
forwarded_message = {
|
||||||
"type": "stream",
|
"type": "stream",
|
||||||
"stream": "support",
|
"to": "support",
|
||||||
"subject": "feedback from %s" % message["sender_email"],
|
"subject": "feedback from %s" % message["sender_email"],
|
||||||
"content": message["content"],
|
"content": message["content"],
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ def send_reminders():
|
||||||
|
|
||||||
humbug.send_message(dict(
|
humbug.send_message(dict(
|
||||||
type = 'private',
|
type = 'private',
|
||||||
recipient = options.user,
|
to = options.user,
|
||||||
content = message))
|
content = message))
|
||||||
|
|
||||||
sent |= keys
|
sent |= keys
|
||||||
|
|
|
@ -41,7 +41,7 @@ def trac_subject(ticket):
|
||||||
def send_update(ticket, content):
|
def send_update(ticket, content):
|
||||||
client.send_message({
|
client.send_message({
|
||||||
"type": "stream",
|
"type": "stream",
|
||||||
"stream": "trac",
|
"to": "trac",
|
||||||
"content": content,
|
"content": content,
|
||||||
"subject": trac_subject(ticket)
|
"subject": trac_subject(ticket)
|
||||||
})
|
})
|
||||||
|
|
|
@ -89,15 +89,15 @@ def send_humbug(zeph):
|
||||||
if zeph['type'] == 'stream':
|
if zeph['type'] == 'stream':
|
||||||
# Forward messages sent to -c foo -i bar to stream bar subject "instance"
|
# Forward messages sent to -c foo -i bar to stream bar subject "instance"
|
||||||
if zeph["stream"] == "message":
|
if zeph["stream"] == "message":
|
||||||
message['stream'] = zeph['subject'].lower()
|
message['to'] = zeph['subject'].lower()
|
||||||
message['subject'] = "instance %s" % (zeph['subject'],)
|
message['subject'] = "instance %s" % (zeph['subject'],)
|
||||||
elif zeph["stream"] == "tabbott-test5":
|
elif zeph["stream"] == "tabbott-test5":
|
||||||
message['stream'] = zeph['subject'].lower()
|
message['to'] = zeph['subject'].lower()
|
||||||
message['subject'] = "test instance %s" % (zeph['subject'],)
|
message['subject'] = "test instance %s" % (zeph['subject'],)
|
||||||
else:
|
else:
|
||||||
message["stream"] = zeph["stream"]
|
message["to"] = zeph["stream"]
|
||||||
else:
|
else:
|
||||||
message["recipient"] = zeph["recipient"]
|
message["to"] = zeph["recipient"]
|
||||||
message['content'] = unwrap_lines(zeph['content'])
|
message['content'] = unwrap_lines(zeph['content'])
|
||||||
|
|
||||||
if options.test_mode and options.site == DEFAULT_SITE:
|
if options.test_mode and options.site == DEFAULT_SITE:
|
||||||
|
@ -109,7 +109,7 @@ def send_humbug(zeph):
|
||||||
def send_error_humbug(error_msg):
|
def send_error_humbug(error_msg):
|
||||||
humbug = {"type": "private",
|
humbug = {"type": "private",
|
||||||
"sender": options.user + "@mit.edu",
|
"sender": options.user + "@mit.edu",
|
||||||
"recipient": options.user + "@mit.edu",
|
"to": options.user + "@mit.edu",
|
||||||
"content": error_msg,
|
"content": error_msg,
|
||||||
}
|
}
|
||||||
humbug_client.send_message(humbug)
|
humbug_client.send_message(humbug)
|
||||||
|
|
|
@ -5,7 +5,7 @@ curl https://humbughq.com/api/v1/send_message \
|
||||||
-d "api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
|
-d "api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
|
||||||
-d "email=tabbott@humbughq.com" \
|
-d "email=tabbott@humbughq.com" \
|
||||||
-d "type=private" -d "content=test" \
|
-d "type=private" -d "content=test" \
|
||||||
-d "recipient=tabbott@humbughq.com"
|
-d "to=tabbott@humbughq.com"
|
||||||
|
|
||||||
curl https://humbughq.com/api/v1/get_messages \
|
curl https://humbughq.com/api/v1/get_messages \
|
||||||
-d "api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
|
-d "api-key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
|
||||||
|
|
|
@ -40,6 +40,6 @@ client = api.common.HumbugAPI(email=options.sender,
|
||||||
message_data = {
|
message_data = {
|
||||||
"type": "private",
|
"type": "private",
|
||||||
"content": "test",
|
"content": "test",
|
||||||
"recipient": args[0]
|
"to": args[0],
|
||||||
}
|
}
|
||||||
print client.send_message(message_data)
|
print client.send_message(message_data)
|
||||||
|
|
|
@ -80,10 +80,9 @@ def send_bot_message(oldrev, newrev, refname):
|
||||||
|
|
||||||
message_data = {
|
message_data = {
|
||||||
"type": "stream",
|
"type": "stream",
|
||||||
"stream": "test" if refname == "refs/heads/test-post-receive" else "devel",
|
"to": "test" if refname == "refs/heads/test-post-receive" else "devel",
|
||||||
"subject": u"deploy \u21D2 " + branch,
|
"subject": u"deploy \u21D2 " + branch,
|
||||||
"content": message,
|
"content": message,
|
||||||
"recipient": "tabbott@humbughq.com",
|
|
||||||
}
|
}
|
||||||
# Sleep a bit to give time for the server to restart.
|
# Sleep a bit to give time for the server to restart.
|
||||||
# TODO: Make this work without the sleep
|
# TODO: Make this work without the sleep
|
||||||
|
|
|
@ -52,10 +52,13 @@ function send_message() {
|
||||||
|
|
||||||
var request = {client: 'website',
|
var request = {client: 'website',
|
||||||
type: compose.composing(),
|
type: compose.composing(),
|
||||||
stream: compose.stream_name(),
|
|
||||||
subject: compose.subject(),
|
subject: compose.subject(),
|
||||||
recipient: JSON.stringify(recipients),
|
|
||||||
content: compose.message_content()};
|
content: compose.message_content()};
|
||||||
|
if (request.type === "private") {
|
||||||
|
request.to = JSON.stringify(recipients);
|
||||||
|
} else {
|
||||||
|
request.to = compose.stream_name();
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
dataType: 'json', // This seems to be ignored. We still get back an xhr.
|
||||||
|
|
|
@ -350,7 +350,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||||
"""
|
"""
|
||||||
self.login("hamlet@humbughq.com")
|
self.login("hamlet@humbughq.com")
|
||||||
result = self.client.post("/json/send_message", {"type": "stream",
|
result = self.client.post("/json/send_message", {"type": "stream",
|
||||||
"stream": "Verona",
|
"to": "Verona",
|
||||||
"client": "test suite",
|
"client": "test suite",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
"subject": "Test subject"})
|
"subject": "Test subject"})
|
||||||
|
@ -363,7 +363,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||||
email = "hamlet@humbughq.com"
|
email = "hamlet@humbughq.com"
|
||||||
api_key = self.get_api_key(email)
|
api_key = self.get_api_key(email)
|
||||||
result = self.client.post("/api/v1/send_message", {"type": "stream",
|
result = self.client.post("/api/v1/send_message", {"type": "stream",
|
||||||
"stream": "Verona",
|
"to": "Verona",
|
||||||
"client": "test suite",
|
"client": "test suite",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
"subject": "Test subject",
|
"subject": "Test subject",
|
||||||
|
@ -378,7 +378,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||||
self.login("hamlet@humbughq.com")
|
self.login("hamlet@humbughq.com")
|
||||||
self.assertFalse(Stream.objects.filter(name="nonexistent_stream"))
|
self.assertFalse(Stream.objects.filter(name="nonexistent_stream"))
|
||||||
result = self.client.post("/json/send_message", {"type": "stream",
|
result = self.client.post("/json/send_message", {"type": "stream",
|
||||||
"stream": "nonexistent_stream",
|
"to": "nonexistent_stream",
|
||||||
"client": "test suite",
|
"client": "test suite",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
"subject": "Test subject"})
|
"subject": "Test subject"})
|
||||||
|
@ -392,7 +392,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||||
result = self.client.post("/json/send_message", {"type": "private",
|
result = self.client.post("/json/send_message", {"type": "private",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
"client": "test suite",
|
"client": "test suite",
|
||||||
"recipient": "othello@humbughq.com"})
|
"to": "othello@humbughq.com"})
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
def test_personal_message_to_nonexistent_user(self):
|
def test_personal_message_to_nonexistent_user(self):
|
||||||
|
@ -403,7 +403,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||||
result = self.client.post("/json/send_message", {"type": "private",
|
result = self.client.post("/json/send_message", {"type": "private",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
"client": "test suite",
|
"client": "test suite",
|
||||||
"recipient": "nonexistent"})
|
"to": "nonexistent"})
|
||||||
self.assert_json_error(result, "Invalid email 'nonexistent'")
|
self.assert_json_error(result, "Invalid email 'nonexistent'")
|
||||||
|
|
||||||
def test_invalid_type(self):
|
def test_invalid_type(self):
|
||||||
|
@ -414,7 +414,7 @@ class MessagePOSTTest(AuthedTestCase):
|
||||||
result = self.client.post("/json/send_message", {"type": "invalid type",
|
result = self.client.post("/json/send_message", {"type": "invalid type",
|
||||||
"content": "Test message",
|
"content": "Test message",
|
||||||
"client": "test suite",
|
"client": "test suite",
|
||||||
"recipient": "othello@humbughq.com"})
|
"to": "othello@humbughq.com"})
|
||||||
self.assert_json_error(result, "Invalid message type")
|
self.assert_json_error(result, "Invalid message type")
|
||||||
|
|
||||||
class DummyHandler(object):
|
class DummyHandler(object):
|
||||||
|
|
|
@ -465,7 +465,7 @@ def same_realm_email(user_profile, email):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def extract_recipients(request):
|
def extract_recipients(request):
|
||||||
raw_recipient = request.POST.get("recipient")
|
raw_recipient = request.POST.get("to")
|
||||||
try:
|
try:
|
||||||
recipients = simplejson.loads(raw_recipient)
|
recipients = simplejson.loads(raw_recipient)
|
||||||
except simplejson.decoder.JSONDecodeError:
|
except simplejson.decoder.JSONDecodeError:
|
||||||
|
@ -484,7 +484,7 @@ def create_mirrored_message_users(request, user_profile):
|
||||||
|
|
||||||
pm_recipients = []
|
pm_recipients = []
|
||||||
if request.POST['type'] == 'private':
|
if request.POST['type'] == 'private':
|
||||||
if "recipient" not in request.POST:
|
if "to" not in request.POST:
|
||||||
return (False, None)
|
return (False, None)
|
||||||
pm_recipients = extract_recipients(request)
|
pm_recipients = extract_recipients(request)
|
||||||
|
|
||||||
|
@ -509,6 +509,7 @@ def create_mirrored_message_users(request, user_profile):
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
def send_message_backend(request, user_profile, client_name,
|
def send_message_backend(request, user_profile, client_name,
|
||||||
message_type_name = POST('type'),
|
message_type_name = POST('type'),
|
||||||
|
message_to = POST('to'),
|
||||||
message_content = POST('content')):
|
message_content = POST('content')):
|
||||||
forged = "forged" in request.POST
|
forged = "forged" in request.POST
|
||||||
is_super_user = is_super_user_api(request)
|
is_super_user = is_super_user_api(request)
|
||||||
|
@ -540,11 +541,9 @@ def send_message_backend(request, user_profile, client_name,
|
||||||
sender = user_profile
|
sender = user_profile
|
||||||
|
|
||||||
if message_type_name == 'stream':
|
if message_type_name == 'stream':
|
||||||
if "stream" not in request.POST:
|
|
||||||
return json_error("Missing stream")
|
|
||||||
if "subject" not in request.POST:
|
if "subject" not in request.POST:
|
||||||
return json_error("Missing subject")
|
return json_error("Missing subject")
|
||||||
stream_name = request.POST['stream'].strip()
|
stream_name = message_to.strip()
|
||||||
subject_name = request.POST['subject'].strip()
|
subject_name = request.POST['subject'].strip()
|
||||||
if stream_name == "":
|
if stream_name == "":
|
||||||
return json_error("Stream can't be empty")
|
return json_error("Stream can't be empty")
|
||||||
|
@ -567,8 +566,6 @@ def send_message_backend(request, user_profile, client_name,
|
||||||
return json_error("Stream does not exist")
|
return json_error("Stream does not exist")
|
||||||
recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
|
recipient = Recipient.objects.get(type_id=stream.id, type=Recipient.STREAM)
|
||||||
elif message_type_name == 'private':
|
elif message_type_name == 'private':
|
||||||
if "recipient" not in request.POST:
|
|
||||||
return json_error("Missing recipients")
|
|
||||||
pm_recipients = extract_recipients(request)
|
pm_recipients = extract_recipients(request)
|
||||||
if client_name == "zephyr_mirror":
|
if client_name == "zephyr_mirror":
|
||||||
if user_profile.user.email not in pm_recipients and not forged:
|
if user_profile.user.email not in pm_recipients and not forged:
|
||||||
|
|
Loading…
Reference in New Issue