mirror of https://github.com/zulip/zulip.git
Migrated json/subscribtions/remove to REST endpoint
This commit is contained in:
parent
3a109a56df
commit
b8ee0e91d2
|
@ -30,8 +30,8 @@ var exports = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_sub(stream_name, $status_message) {
|
function remove_sub(stream_name, $status_message) {
|
||||||
channel.post({
|
channel.del({
|
||||||
url: '/json/subscriptions/remove',
|
url: '/json/users/me/subscriptions',
|
||||||
data: {
|
data: {
|
||||||
subscriptions: JSON.stringify([stream_name])
|
subscriptions: JSON.stringify([stream_name])
|
||||||
}
|
}
|
||||||
|
|
|
@ -702,8 +702,8 @@ function ajaxSubscribe(stream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ajaxUnsubscribe(stream) {
|
function ajaxUnsubscribe(stream) {
|
||||||
return channel.post({
|
return channel.del({
|
||||||
url: "/json/subscriptions/remove",
|
url: "/json/users/me/subscriptions",
|
||||||
data: {subscriptions: JSON.stringify([stream]) },
|
data: {subscriptions: JSON.stringify([stream]) },
|
||||||
success: function () {
|
success: function () {
|
||||||
$("#subscriptions-status").hide();
|
$("#subscriptions-status").hide();
|
||||||
|
@ -785,8 +785,8 @@ exports.invite_user_to_stream = function (user_email, stream_name, success, fail
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.remove_user_from_stream = function (user_email, stream_name, success, failure) {
|
exports.remove_user_from_stream = function (user_email, stream_name, success, failure) {
|
||||||
return channel.post({
|
return channel.del({
|
||||||
url: "/json/subscriptions/remove",
|
url: "/json/users/me/subscriptions",
|
||||||
data: {subscriptions: JSON.stringify([stream_name]),
|
data: {subscriptions: JSON.stringify([stream_name]),
|
||||||
principals: JSON.stringify([user_email])},
|
principals: JSON.stringify([user_email])},
|
||||||
success: success,
|
success: success,
|
||||||
|
|
|
@ -99,7 +99,6 @@ class PublicURLTest(ZulipTestCase):
|
||||||
401: ["/json/messages",
|
401: ["/json/messages",
|
||||||
"/json/invite_users",
|
"/json/invite_users",
|
||||||
"/json/settings/change",
|
"/json/settings/change",
|
||||||
"/json/subscriptions/remove",
|
|
||||||
"/json/subscriptions/exists",
|
"/json/subscriptions/exists",
|
||||||
"/json/subscriptions/property",
|
"/json/subscriptions/property",
|
||||||
"/json/fetch_api_key",
|
"/json/fetch_api_key",
|
||||||
|
|
|
@ -496,8 +496,8 @@ class StreamAdminTest(ZulipTestCase):
|
||||||
if other_user_subbed:
|
if other_user_subbed:
|
||||||
self.subscribe_to_stream(other_user_profile.email, stream_name)
|
self.subscribe_to_stream(other_user_profile.email, stream_name)
|
||||||
|
|
||||||
result = self.client_post(
|
result = self.client_delete(
|
||||||
"/json/subscriptions/remove",
|
"/json/users/me/subscriptions",
|
||||||
{"subscriptions": ujson.dumps([stream_name]),
|
{"subscriptions": ujson.dumps([stream_name]),
|
||||||
"principals": ujson.dumps([other_email])})
|
"principals": ujson.dumps([other_email])})
|
||||||
|
|
||||||
|
@ -630,9 +630,9 @@ class StreamAdminTest(ZulipTestCase):
|
||||||
stream_name = u"hümbüǵ"
|
stream_name = u"hümbüǵ"
|
||||||
self.make_stream(stream_name)
|
self.make_stream(stream_name)
|
||||||
|
|
||||||
result = self.client_post("/json/subscriptions/remove",
|
result = self.client_delete("/json/users/me/subscriptions",
|
||||||
{"subscriptions": ujson.dumps([stream_name]),
|
{"subscriptions": ujson.dumps([stream_name]),
|
||||||
"principals": ujson.dumps(["baduser@zulip.com"])})
|
"principals": ujson.dumps(["baduser@zulip.com"])})
|
||||||
self.assert_json_error(
|
self.assert_json_error(
|
||||||
result,
|
result,
|
||||||
"User not authorized to execute queries on behalf of 'baduser@zulip.com'",
|
"User not authorized to execute queries on behalf of 'baduser@zulip.com'",
|
||||||
|
@ -1714,8 +1714,8 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||||
"removed": ["Denmark", "Scotland", "Verona"],
|
"removed": ["Denmark", "Scotland", "Verona"],
|
||||||
"not_subscribed": ["Rome"], "result": "success"}
|
"not_subscribed": ["Rome"], "result": "success"}
|
||||||
"""
|
"""
|
||||||
result = self.client_post("/json/subscriptions/remove",
|
result = self.client_delete("/json/users/me/subscriptions",
|
||||||
{"subscriptions": ujson.dumps(subscriptions)})
|
{"subscriptions": ujson.dumps(subscriptions)})
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
json = ujson.loads(result.content)
|
json = ujson.loads(result.content)
|
||||||
for key, val in six.iteritems(json_dict):
|
for key, val in six.iteritems(json_dict):
|
||||||
|
@ -1726,7 +1726,7 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||||
def test_successful_subscriptions_remove(self):
|
def test_successful_subscriptions_remove(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
"""
|
"""
|
||||||
Calling /json/subscriptions/remove should successfully remove streams,
|
Calling DELETE /json/users/me/subscriptions should successfully remove streams,
|
||||||
and should determine which were removed vs which weren't subscribed to.
|
and should determine which were removed vs which weren't subscribed to.
|
||||||
We cannot randomly generate stream names because the remove code
|
We cannot randomly generate stream names because the remove code
|
||||||
verifies whether streams exist.
|
verifies whether streams exist.
|
||||||
|
@ -1749,14 +1749,14 @@ class SubscriptionAPITest(ZulipTestCase):
|
||||||
def test_subscriptions_remove_fake_stream(self):
|
def test_subscriptions_remove_fake_stream(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
"""
|
"""
|
||||||
Calling /json/subscriptions/remove on a stream that doesn't exist
|
Calling DELETE /json/users/me/subscriptions on a stream that doesn't exist
|
||||||
should return a JSON error.
|
should return a JSON error.
|
||||||
"""
|
"""
|
||||||
random_streams = self.make_random_stream_names(self.streams)
|
random_streams = self.make_random_stream_names(self.streams)
|
||||||
self.assertNotEqual(len(random_streams), 0) # necessary for full test coverage
|
self.assertNotEqual(len(random_streams), 0) # necessary for full test coverage
|
||||||
streams_to_remove = random_streams[:1] # pick only one fake stream, to make checking the error message easy
|
streams_to_remove = random_streams[:1] # pick only one fake stream, to make checking the error message easy
|
||||||
result = self.client_post("/json/subscriptions/remove",
|
result = self.client_delete("/json/users/me/subscriptions",
|
||||||
{"subscriptions": ujson.dumps(streams_to_remove)})
|
{"subscriptions": ujson.dumps(streams_to_remove)})
|
||||||
self.assert_json_error(result, "Stream(s) (%s) do not exist" % (random_streams[0],))
|
self.assert_json_error(result, "Stream(s) (%s) do not exist" % (random_streams[0],))
|
||||||
|
|
||||||
def helper_subscriptions_exists(self, stream, exists, subscribed):
|
def helper_subscriptions_exists(self, stream, exists, subscribed):
|
||||||
|
|
|
@ -18,7 +18,6 @@ legacy_urls = [
|
||||||
url(r'^json/refer_friend$', zerver.views.invite.json_refer_friend),
|
url(r'^json/refer_friend$', zerver.views.invite.json_refer_friend),
|
||||||
url(r'^json/settings/change$', zerver.views.user_settings.json_change_settings),
|
url(r'^json/settings/change$', zerver.views.user_settings.json_change_settings),
|
||||||
url(r'^json/ui_settings/change$', zerver.views.user_settings.json_change_ui_settings),
|
url(r'^json/ui_settings/change$', zerver.views.user_settings.json_change_ui_settings),
|
||||||
url(r'^json/subscriptions/remove$', zerver.views.streams.json_remove_subscriptions),
|
|
||||||
|
|
||||||
# We should remove this endpoint and all code related to it.
|
# We should remove this endpoint and all code related to it.
|
||||||
# It returns a 404 if the stream doesn't exist, which is confusing
|
# It returns a 404 if the stream doesn't exist, which is confusing
|
||||||
|
|
|
@ -284,7 +284,8 @@ v1_api_and_json_patterns = [
|
||||||
url(r'^users/me/subscriptions$', rest_dispatch,
|
url(r'^users/me/subscriptions$', rest_dispatch,
|
||||||
{'GET': 'zerver.views.streams.list_subscriptions_backend',
|
{'GET': 'zerver.views.streams.list_subscriptions_backend',
|
||||||
'POST': 'zerver.views.streams.add_subscriptions_backend',
|
'POST': 'zerver.views.streams.add_subscriptions_backend',
|
||||||
'PATCH': 'zerver.views.streams.update_subscriptions_backend'}),
|
'PATCH': 'zerver.views.streams.update_subscriptions_backend',
|
||||||
|
'DELETE': 'zerver.views.streams.remove_subscriptions_backend'}),
|
||||||
|
|
||||||
# used to register for an event queue in tornado
|
# used to register for an event queue in tornado
|
||||||
url(r'^register$', rest_dispatch,
|
url(r'^register$', rest_dispatch,
|
||||||
|
|
Loading…
Reference in New Issue