mirror of
https://github.com/zulip/zulip.git
synced 2026-07-12 21:04:41 +08:00
stream_exists_backend now returns a 404 if the stream is not found.
Update tests and compose.js to handle the 404. (imported from commit d9ba4fe59c34bd14d9198e3365a845888fa04f03)
This commit is contained in:
parent
825f59799a
commit
60075e596f
@ -365,16 +365,18 @@ exports.check_stream_existence = function (stream_name) {
|
||||
data: {'stream': stream_name},
|
||||
async: false,
|
||||
success: function (data) {
|
||||
if (!data.exists) {
|
||||
result = "does-not-exist";
|
||||
} else if (data.subscribed) {
|
||||
if (data.subscribed) {
|
||||
result = "subscribed";
|
||||
} else {
|
||||
result = "not-subscribed";
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
result = "error";
|
||||
if (xhr.status === 404) {
|
||||
result = "does-not-exist";
|
||||
} else {
|
||||
result = "error";
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
|
||||
@ -929,10 +929,13 @@ class SubscriptionAPITest(AuthedTestCase):
|
||||
"""
|
||||
result = self.client.post("/json/subscriptions/exists",
|
||||
{"stream": stream})
|
||||
self.assert_json_success(result)
|
||||
json = simplejson.loads(result.content)
|
||||
self.assertIn("exists", json)
|
||||
self.assertEqual(json["exists"], exists)
|
||||
if exists:
|
||||
self.assert_json_success(result)
|
||||
else:
|
||||
self.assertEquals(result.status_code, 404)
|
||||
if not subscribed is None:
|
||||
self.assertIn("subscribed", json)
|
||||
self.assertEqual(json["subscribed"], subscribed)
|
||||
|
||||
@ -37,7 +37,7 @@ from zephyr.decorator import require_post, \
|
||||
get_user_profile_by_user_id
|
||||
from zephyr.lib.query import last_n
|
||||
from zephyr.lib.avatar import gravatar_hash
|
||||
from zephyr.lib.response import json_success, json_error
|
||||
from zephyr.lib.response import json_success, json_error, json_response
|
||||
from zephyr.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp
|
||||
from zephyr.lib.cache import cache_with_key
|
||||
|
||||
@ -1022,7 +1022,8 @@ def json_stream_exists(request, user_profile, stream=POST):
|
||||
result["subscribed"] = Subscription.objects.filter(user_profile=user_profile,
|
||||
recipient=recipient,
|
||||
active=True).exists()
|
||||
return json_success(result)
|
||||
return json_success(result) # results are ignored for HEAD requests
|
||||
return json_response(data=result, status=404)
|
||||
|
||||
def get_subscription_or_die(stream_name, user_profile):
|
||||
stream = get_stream(stream_name, user_profile.realm)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user