api: Fix encoding of strings in display settings endpoint.

* Remove unnecessary json validator for string validator.
* Update frontend to pass right validator.
* Update zulip.yaml to pass right parameter for curl request
  in openapi.
* Update python_examples to pass right paramater.

Fixes part of #18035.
This commit is contained in:
Gaurav Pandey 2021-05-08 21:06:47 +05:30 committed by Tim Abbott
parent 544bbd5398
commit 9abe1cafbe
5 changed files with 12 additions and 12 deletions

View File

@ -126,7 +126,7 @@ export function set_up() {
});
$("#default_view").on("change", function () {
const data = {default_view: JSON.stringify(this.value)};
const data = {default_view: this.value};
change_display_setting(data, "#display-settings-status");
});
@ -140,12 +140,12 @@ export function set_up() {
});
$("#user_timezone").on("change", function () {
const data = {timezone: JSON.stringify(this.value)};
const data = {timezone: this.value};
change_display_setting(data, "#time-settings-status");
});
$(".emojiset_choice").on("click", function () {
const data = {emojiset: JSON.stringify($(this).val())};
const current_emojiset = JSON.stringify(page_params.emojiset);
const data = {emojiset: $(this).val()};
const current_emojiset = page_params.emojiset;
if (current_emojiset === data.emojiset) {
return;
}

View File

@ -1131,7 +1131,7 @@ def update_display_settings(client: Client) -> None:
# Change emoji set used for display to Google modern.
request = {
"left_side_userlist": True,
"emojiset": '"google"',
"emojiset": "google",
}
result = client.call_endpoint("settings/display", method="PATCH", request=request)
# {code_example|end}

View File

@ -9636,7 +9636,7 @@ paths:
* "text" - Plain text
schema:
type: string
example: '"google"'
example: "google"
- name: demote_inactive_streams
in: query
description: |

View File

@ -354,7 +354,7 @@ class ChangeSettingsTest(ZulipTestCase):
else:
invalid_value = "invalid_" + setting_name
if setting_name == "default_language":
if setting_name not in ["demote_inactive_streams", "color_scheme"]:
data = {setting_name: test_value}
else:
data = {setting_name: orjson.dumps(test_value).decode()}
@ -366,7 +366,7 @@ class ChangeSettingsTest(ZulipTestCase):
# Test to make sure invalid settings are not accepted
# and saved in the db.
if setting_name == "default_language":
if setting_name not in ["demote_inactive_streams", "color_scheme"]:
data = {setting_name: invalid_value}
else:
data = {setting_name: orjson.dumps(invalid_value).decode()}
@ -389,7 +389,7 @@ class ChangeSettingsTest(ZulipTestCase):
def do_change_emojiset(self, emojiset: str) -> HttpResponse:
self.login("hamlet")
data = {"emojiset": orjson.dumps(emojiset).decode()}
data = {"emojiset": emojiset}
result = self.client_patch("/json/settings/display", data)
return result

View File

@ -199,15 +199,15 @@ def update_display_settings_backend(
translate_emoticons: Optional[bool] = REQ(json_validator=check_bool, default=None),
default_language: Optional[str] = REQ(default=None),
default_view: Optional[str] = REQ(
json_validator=check_string_in(default_view_options), default=None
str_validator=check_string_in(default_view_options), default=None
),
left_side_userlist: Optional[bool] = REQ(json_validator=check_bool, default=None),
emojiset: Optional[str] = REQ(json_validator=check_string_in(emojiset_choices), default=None),
emojiset: Optional[str] = REQ(str_validator=check_string_in(emojiset_choices), default=None),
demote_inactive_streams: Optional[int] = REQ(
json_validator=check_int_in(UserProfile.DEMOTE_STREAMS_CHOICES), default=None
),
timezone: Optional[str] = REQ(
json_validator=check_string_in(pytz.all_timezones_set), default=None
str_validator=check_string_in(pytz.all_timezones_set), default=None
),
) -> HttpResponse: