diff --git a/static/js/settings.js b/static/js/settings.js index c97432ce4d..accd820231 100644 --- a/static/js/settings.js +++ b/static/js/settings.js @@ -432,7 +432,7 @@ function _setup_page() { } channel.patch({ - url: '/json/time_setting', + url: '/json/settings/display', data: data, success: function () { ui.report_success(i18n.t("Time will be displayed in the __format__-hour format! You will need to reload the window for your changes to take effect", context), diff --git a/zerver/tests/tests.py b/zerver/tests/tests.py index 4fd0241cd9..28b8d9b7cb 100644 --- a/zerver/tests/tests.py +++ b/zerver/tests/tests.py @@ -1530,6 +1530,8 @@ class ChangeSettingsTest(ZulipTestCase): # type: (Dict[str, Any]) -> None self.assertIn("full_name", result) + # DEPRECATED, to be deleted after all uses of check_for_toggle_param + # are converted into check_for_toggle_param_patch. def check_for_toggle_param(self, pattern, param): # type: (str, str) -> None self.login("hamlet@zulip.com") @@ -1548,6 +1550,26 @@ class ChangeSettingsTest(ZulipTestCase): user_profile = get_user_profile_by_email("hamlet@zulip.com") self.assertEqual(getattr(user_profile, param), False) + # TODO: requires method consolidation, right now, there's no alternative + # for check_for_toggle_param for PATCH. + def check_for_toggle_param_patch(self, pattern, url): + # type: (str, str) -> None + self.login("hamlet@zulip.com") + user_profile = get_user_profile_by_email("hamlet@zulip.com") + json_result = self.client_patch(pattern, + {url: ujson.dumps(True)}) + self.assert_json_success(json_result) + # refetch user_profile object to correctly handle caching + user_profile = get_user_profile_by_email("hamlet@zulip.com") + self.assertEqual(getattr(user_profile, url), True) + + json_result = self.client_patch(pattern, + {url: ujson.dumps(False)}) + self.assert_json_success(json_result) + # refetch user_profile object to correctly handle caching + user_profile = get_user_profile_by_email("hamlet@zulip.com") + self.assertEqual(getattr(user_profile, url), False) + def test_successful_change_settings(self): # type: () -> None """ @@ -1620,7 +1642,7 @@ class ChangeSettingsTest(ZulipTestCase): def test_time_setting(self): # type: () -> None - self.check_for_toggle_param("/json/time_setting", "twenty_four_hour_time") + self.check_for_toggle_param_patch("/json/settings/display", "twenty_four_hour_time") def test_enter_sends_setting(self): # type: () -> None diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.py index 4202d671d3..bf29c75185 100644 --- a/zerver/views/user_settings.py +++ b/zerver/views/user_settings.py @@ -1,5 +1,5 @@ from __future__ import absolute_import -from typing import Optional +from typing import Optional, Any from six import text_type from django.utils.translation import ugettext as _ @@ -95,19 +95,6 @@ def json_change_settings(request, user_profile, return json_success(result) -@authenticated_json_post_view -@has_request_variables -def json_time_setting(request, user_profile, twenty_four_hour_time=REQ(validator=check_bool, default=None)): - # type: (HttpRequest, UserProfile, Optional[bool]) -> HttpResponse - result = {} - if twenty_four_hour_time is not None and \ - user_profile.twenty_four_hour_time != twenty_four_hour_time: - do_change_twenty_four_hour_time(user_profile, twenty_four_hour_time) - - result['twenty_four_hour_time'] = twenty_four_hour_time - - return json_success(result) - @authenticated_json_post_view @has_request_variables def json_left_side_userlist(request, user_profile, left_side_userlist=REQ(validator=check_bool, default=None)): @@ -122,22 +109,28 @@ def json_left_side_userlist(request, user_profile, left_side_userlist=REQ(valida return json_success(result) -# TODO: Merge json_left_side_userlist and json_time_setting endpoints +# TODO: Merge json_left_side_userlist endpoint # into this one; it should be straightforward @has_request_variables def update_display_settings_backend(request, user_profile, + twenty_four_hour_time=REQ(validator=check_bool, default=None), default_language=REQ(validator=check_string, default=None)): - # type: (HttpRequest, UserProfile, Optional[str]) -> HttpResponse + # type: (HttpRequest, UserProfile, Optional[bool], Optional[str]) -> HttpResponse if (default_language is not None and default_language not in get_available_language_codes()): raise JsonableError(_("Invalid language '%s'" % (default_language,))) - result = {} + result = {} # type: Dict[str, Any] if (default_language is not None and user_profile.default_language != default_language): do_change_default_language(user_profile, default_language) result['default_language'] = default_language + elif (twenty_four_hour_time is not None and + user_profile.twenty_four_hour_time != twenty_four_hour_time): + do_change_twenty_four_hour_time(user_profile, twenty_four_hour_time) + result['twenty_four_hour_time'] = twenty_four_hour_time + return json_success(result) @authenticated_json_post_view diff --git a/zproject/legacy_urls.py b/zproject/legacy_urls.py index 5af9119416..8166d74115 100644 --- a/zproject/legacy_urls.py +++ b/zproject/legacy_urls.py @@ -42,6 +42,5 @@ legacy_urls = [ 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/set_muted_topics$', zerver.views.json_set_muted_topics), - 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), ]