mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
[manual] API add_subscriptions: Change arguments to support options.
Since in the future we might want requests to add subscriptions to include things like colors, in_home_view, etc., we're changing the data format for the add_subscriptions API call to pass each stream as a dictionary, giving a convenient place to put any added options. The manual step required here is updating the API version in AFS available for use with the zephyr_mirror.py system. (imported from commit 364960cca582a0658f0d334668822045c001b92c)
This commit is contained in:
@@ -48,4 +48,5 @@ if options.streams == "":
|
|||||||
print >>sys.stderr, "Usage:", parser.usage
|
print >>sys.stderr, "Usage:", parser.usage
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print client.add_subscriptions(options.streams.split())
|
print client.add_subscriptions([{"name": stream_name} for stream_name in
|
||||||
|
options.streams.split()])
|
||||||
|
|||||||
@@ -675,7 +675,7 @@ def add_humbug_subscriptions(verbose):
|
|||||||
zephyr_subscriptions.add(cls)
|
zephyr_subscriptions.add(cls)
|
||||||
|
|
||||||
if len(zephyr_subscriptions) != 0:
|
if len(zephyr_subscriptions) != 0:
|
||||||
res = humbug_client.add_subscriptions(list(zephyr_subscriptions))
|
res = humbug_client.add_subscriptions(list({"name": stream} for stream in zephyr_subscriptions))
|
||||||
if res.get("result") != "success":
|
if res.get("result") != "success":
|
||||||
logger.error("Error subscribing to streams:\n%s" % (res["msg"],))
|
logger.error("Error subscribing to streams:\n%s" % (res["msg"],))
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -640,7 +640,7 @@ function ajaxSubscribe(stream) {
|
|||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/json/subscriptions/add",
|
url: "/json/subscriptions/add",
|
||||||
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.
|
||||||
data: {"subscriptions": JSON.stringify([stream]) },
|
data: {"subscriptions": JSON.stringify([{"name": stream}]) },
|
||||||
success: function (resp, statusText, xhr, form) {
|
success: function (resp, statusText, xhr, form) {
|
||||||
$("#create_stream_name").val("");
|
$("#create_stream_name").val("");
|
||||||
|
|
||||||
@@ -684,7 +684,7 @@ function ajaxSubscribeForCreation(stream, principals, invite_only) {
|
|||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/json/subscriptions/add",
|
url: "/json/subscriptions/add",
|
||||||
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.
|
||||||
data: {"subscriptions": JSON.stringify([stream]),
|
data: {"subscriptions": JSON.stringify([{"name": stream}]),
|
||||||
"principals": JSON.stringify(principals),
|
"principals": JSON.stringify(principals),
|
||||||
"invite_only": JSON.stringify(invite_only)
|
"invite_only": JSON.stringify(invite_only)
|
||||||
},
|
},
|
||||||
@@ -853,7 +853,7 @@ $(function () {
|
|||||||
type: "POST",
|
type: "POST",
|
||||||
url: "/json/subscriptions/add",
|
url: "/json/subscriptions/add",
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: {"subscriptions": JSON.stringify([stream]),
|
data: {"subscriptions": JSON.stringify([{"name": stream}]),
|
||||||
"principals": JSON.stringify([principal])},
|
"principals": JSON.stringify([principal])},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
text_box.val('');
|
text_box.val('');
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ class AuthedTestCase(TestCase):
|
|||||||
|
|
||||||
post_data = {'email': email,
|
post_data = {'email': email,
|
||||||
'api-key': api_key,
|
'api-key': api_key,
|
||||||
'subscriptions': ujson.dumps(streams),
|
'subscriptions': ujson.dumps([{"name": stream} for stream in streams]),
|
||||||
'invite_only': ujson.dumps(invite_only)}
|
'invite_only': ujson.dumps(invite_only)}
|
||||||
post_data.update(extra_post_data)
|
post_data.update(extra_post_data)
|
||||||
|
|
||||||
|
|||||||
@@ -1255,8 +1255,10 @@ def add_subscriptions_backend(request, user_profile,
|
|||||||
principals = REQ('principals', json_to_list, default=None),):
|
principals = REQ('principals', json_to_list, default=None),):
|
||||||
|
|
||||||
stream_names = []
|
stream_names = []
|
||||||
for stream_name in streams_raw:
|
for stream in streams_raw:
|
||||||
stream_name = stream_name.strip()
|
if not isinstance(stream, dict):
|
||||||
|
return json_error("Malformed request")
|
||||||
|
stream_name = stream["name"].strip()
|
||||||
if len(stream_name) > Stream.MAX_NAME_LENGTH:
|
if len(stream_name) > Stream.MAX_NAME_LENGTH:
|
||||||
return json_error("Stream name (%s) too long." % (stream_name,))
|
return json_error("Stream name (%s) too long." % (stream_name,))
|
||||||
if not valid_stream_name(stream_name):
|
if not valid_stream_name(stream_name):
|
||||||
@@ -1268,7 +1270,7 @@ def add_subscriptions_backend(request, user_profile,
|
|||||||
else:
|
else:
|
||||||
subscribers = [user_profile]
|
subscribers = [user_profile]
|
||||||
|
|
||||||
streams = list_to_streams(streams_raw, user_profile, autocreate=True, invite_only=invite_only)
|
streams = list_to_streams(stream_names, user_profile, autocreate=True, invite_only=invite_only)
|
||||||
private_streams = {}
|
private_streams = {}
|
||||||
result = dict(subscribed=[], already_subscribed=[])
|
result = dict(subscribed=[], already_subscribed=[])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user