urls: convert set_avatar from legacy URL to REST endpoint

This commit is contained in:
Sampriti Panda 2016-12-22 01:59:46 +05:30 committed by showell
parent 567fab1137
commit e72cd0b1cc
5 changed files with 11 additions and 11 deletions

View File

@ -530,8 +530,8 @@ function _setup_page() {
var spinner = $("#upload_avatar_spinner").expectOne(); var spinner = $("#upload_avatar_spinner").expectOne();
loading.make_indicator(spinner, {text: 'Uploading avatar.'}); loading.make_indicator(spinner, {text: 'Uploading avatar.'});
channel.post({ channel.put({
url: '/json/set_avatar', url: '/json/users/me/avatar',
data: form_data, data: form_data,
cache: false, cache: false,
processData: false, processData: false,

View File

@ -331,7 +331,7 @@ class AvatarTest(ZulipTestCase):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
with get_test_image_file('img.png') as fp1, \ with get_test_image_file('img.png') as fp1, \
get_test_image_file('img.png') as fp2: get_test_image_file('img.png') as fp2:
result = self.client_post("/json/set_avatar", {'f1': fp1, 'f2': fp2}) result = self.client_put_multipart("/json/users/me/avatar", {'f1': fp1, 'f2': fp2})
self.assert_json_error(result, "You must upload exactly one avatar.") self.assert_json_error(result, "You must upload exactly one avatar.")
def test_no_file_upload_failure(self): def test_no_file_upload_failure(self):
@ -341,7 +341,7 @@ class AvatarTest(ZulipTestCase):
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
result = self.client_post("/json/set_avatar") result = self.client_put_multipart("/json/users/me/avatar")
self.assert_json_error(result, "You must upload exactly one avatar.") self.assert_json_error(result, "You must upload exactly one avatar.")
correct_files = [ correct_files = [
@ -395,14 +395,14 @@ class AvatarTest(ZulipTestCase):
def test_valid_avatars(self): def test_valid_avatars(self):
# type: () -> None # type: () -> None
""" """
A call to /json/set_avatar with a valid file should return a url and actually create an avatar. A call to /json/users/me/avatar with a valid file should return a url and actually create an avatar.
""" """
for fname, rfname in self.correct_files: for fname, rfname in self.correct_files:
# TODO: use self.subTest once we're exclusively on python 3 by uncommenting the line below. # TODO: use self.subTest once we're exclusively on python 3 by uncommenting the line below.
# with self.subTest(fname=fname): # with self.subTest(fname=fname):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
with get_test_image_file(fname) as fp: with get_test_image_file(fname) as fp:
result = self.client_post("/json/set_avatar", {'file': fp}) result = self.client_put_multipart("/json/users/me/avatar", {'file': fp})
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)
@ -431,13 +431,13 @@ class AvatarTest(ZulipTestCase):
def test_invalid_avatars(self): def test_invalid_avatars(self):
# type: () -> None # type: () -> None
""" """
A call to /json/set_avatar with an invalid file should fail. A call to /json/users/me/avatar with an invalid file should fail.
""" """
for fname in self.corrupt_files: for fname in self.corrupt_files:
# with self.subTest(fname=fname): # with self.subTest(fname=fname):
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
with get_test_image_file(fname) as fp: with get_test_image_file(fname) as fp:
result = self.client_post("/json/set_avatar", {'file': fp}) result = self.client_put_multipart("/json/users/me/avatar", {'file': fp})
self.assert_json_error(result, "Could not decode avatar image; did you upload an image file?") self.assert_json_error(result, "Could not decode avatar image; did you upload an image file?")

View File

@ -207,8 +207,7 @@ def json_change_notify_settings(request, user_profile,
return json_success(result) return json_success(result)
@authenticated_json_post_view def set_avatar_backend(request, user_profile):
def json_set_avatar(request, user_profile):
# type: (HttpRequest, UserProfile) -> HttpResponse # type: (HttpRequest, UserProfile) -> HttpResponse
if len(request.FILES) != 1: if len(request.FILES) != 1:
return json_error(_("You must upload exactly one avatar.")) return json_error(_("You must upload exactly one avatar."))

View File

@ -43,7 +43,6 @@ legacy_urls = [
url(r'^json/messages_in_narrow$', zerver.views.messages.json_messages_in_narrow), url(r'^json/messages_in_narrow$', zerver.views.messages.json_messages_in_narrow),
url(r'^json/update_message$', zerver.views.messages.json_update_message), url(r'^json/update_message$', zerver.views.messages.json_update_message),
url(r'^json/set_muted_topics$', zerver.views.json_set_muted_topics), url(r'^json/set_muted_topics$', zerver.views.json_set_muted_topics),
url(r'^json/set_avatar$', zerver.views.user_settings.json_set_avatar),
url(r'^json/time_setting$', zerver.views.user_settings.json_time_setting), url(r'^json/time_setting$', zerver.views.user_settings.json_time_setting),
url(r'^json/left_side_userlist$', zerver.views.user_settings.json_left_side_userlist), url(r'^json/left_side_userlist$', zerver.views.user_settings.json_left_side_userlist),
url(r'^json/language_setting$', zerver.views.user_settings.json_language_setting), url(r'^json/language_setting$', zerver.views.user_settings.json_language_setting),

View File

@ -243,6 +243,8 @@ v1_api_and_json_patterns = [
{'POST': 'zerver.views.user_settings.regenerate_api_key'}), {'POST': 'zerver.views.user_settings.regenerate_api_key'}),
url(r'^users/me/enter-sends$', rest_dispatch, url(r'^users/me/enter-sends$', rest_dispatch,
{'POST': 'zerver.views.user_settings.change_enter_sends'}), {'POST': 'zerver.views.user_settings.change_enter_sends'}),
url(r'^users/me/avatar$', rest_dispatch,
{'PUT': 'zerver.views.user_settings.set_avatar_backend'}),
# users/me/alert_words -> zerver.views.alert_words # users/me/alert_words -> zerver.views.alert_words
url(r'^users/me/alert_words$', rest_dispatch, url(r'^users/me/alert_words$', rest_dispatch,