mirror of https://github.com/zulip/zulip.git
api: Remove encoding of string in update_user endpoint.
* Remove unnecessary json_validator for full_name parameter. * Update frontend to pass the right parameter. * Update documentation and note the change. Fixes #18409.
This commit is contained in:
parent
37d977f8f1
commit
1c1a1e2cad
|
@ -574,7 +574,7 @@ function handle_human_form(tbody, status_field) {
|
|||
|
||||
const url = "/json/users/" + encodeURIComponent(user_id);
|
||||
const data = {
|
||||
full_name: JSON.stringify(full_name.val()),
|
||||
full_name: full_name.val(),
|
||||
role: JSON.stringify(role),
|
||||
profile_data: JSON.stringify(profile_data),
|
||||
};
|
||||
|
|
|
@ -11,6 +11,11 @@ below features are supported.
|
|||
|
||||
## Changes in Zulip 5.0
|
||||
|
||||
**Feature level 106**
|
||||
|
||||
* [`PATCH /user/{user_id}`](/api/update-user): Removed unnecessary JSON-encoding of string
|
||||
parameter `full_name`.
|
||||
|
||||
**Feature level 105**
|
||||
|
||||
* [`POST /register`](/api/register-queue), [`PATCH
|
||||
|
|
|
@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3"
|
|||
# Changes should be accompanied by documentation explaining what the
|
||||
# new level means in templates/zerver/api/changelog.md, as well as
|
||||
# "**Changes**" entries in the endpoint's documentation in `zulip.yaml`.
|
||||
API_FEATURE_LEVEL = 105
|
||||
API_FEATURE_LEVEL = 106
|
||||
|
||||
# Bump the minor PROVISION_VERSION to indicate that folks should provision
|
||||
# only when going from an old version of the code to a newer version. Bump
|
||||
|
|
|
@ -8277,11 +8277,12 @@ paths:
|
|||
in: query
|
||||
description: |
|
||||
The user's full name.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
example: NewName
|
||||
|
||||
**Changes**: Removed unnecessary JSON-encoding of this parameter in
|
||||
Zulip 5.0 (feature level 106).
|
||||
schema:
|
||||
type: string
|
||||
example: NewName
|
||||
required: false
|
||||
- name: role
|
||||
in: query
|
||||
|
|
|
@ -206,7 +206,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
|||
start = timezone_now()
|
||||
new_name = "George Hamletovich"
|
||||
self.login("iago")
|
||||
req = dict(full_name=orjson.dumps(new_name).decode())
|
||||
req = dict(full_name=new_name)
|
||||
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||
self.assertTrue(result.status_code == 200)
|
||||
query = RealmAuditLog.objects.filter(
|
||||
|
|
|
@ -377,7 +377,7 @@ class PermissionTest(ZulipTestCase):
|
|||
new_name = "new name"
|
||||
self.login("iago")
|
||||
hamlet = self.example_user("hamlet")
|
||||
req = dict(full_name=orjson.dumps(new_name).decode())
|
||||
req = dict(full_name=new_name)
|
||||
result = self.client_patch(f"/json/users/{hamlet.id}", req)
|
||||
self.assert_json_success(result)
|
||||
hamlet = self.example_user("hamlet")
|
||||
|
@ -385,21 +385,21 @@ class PermissionTest(ZulipTestCase):
|
|||
|
||||
def test_non_admin_cannot_change_full_name(self) -> None:
|
||||
self.login("hamlet")
|
||||
req = dict(full_name=orjson.dumps("new name").decode())
|
||||
req = dict(full_name="new name")
|
||||
result = self.client_patch("/json/users/{}".format(self.example_user("othello").id), req)
|
||||
self.assert_json_error(result, "Insufficient permission")
|
||||
|
||||
def test_admin_cannot_set_long_full_name(self) -> None:
|
||||
new_name = "a" * (UserProfile.MAX_NAME_LENGTH + 1)
|
||||
self.login("iago")
|
||||
req = dict(full_name=orjson.dumps(new_name).decode())
|
||||
req = dict(full_name=new_name)
|
||||
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||
self.assert_json_error(result, "Name too long!")
|
||||
|
||||
def test_admin_cannot_set_short_full_name(self) -> None:
|
||||
new_name = "a"
|
||||
self.login("iago")
|
||||
req = dict(full_name=orjson.dumps(new_name).decode())
|
||||
req = dict(full_name=new_name)
|
||||
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||
self.assert_json_error(result, "Name too short!")
|
||||
|
||||
|
@ -407,7 +407,7 @@ class PermissionTest(ZulipTestCase):
|
|||
# Name of format "Alice|999" breaks in Markdown
|
||||
new_name = "iago|72"
|
||||
self.login("iago")
|
||||
req = dict(full_name=orjson.dumps(new_name).decode())
|
||||
req = dict(full_name=new_name)
|
||||
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||
self.assert_json_error(result, "Invalid format!")
|
||||
|
||||
|
@ -415,21 +415,21 @@ class PermissionTest(ZulipTestCase):
|
|||
# Adding characters after r'|d+' doesn't break Markdown
|
||||
new_name = "Hello- 12iago|72k"
|
||||
self.login("iago")
|
||||
req = dict(full_name=orjson.dumps(new_name).decode())
|
||||
req = dict(full_name=new_name)
|
||||
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||
self.assert_json_success(result)
|
||||
|
||||
def test_not_allowed_format_complex(self) -> None:
|
||||
new_name = "Hello- 12iago|72"
|
||||
self.login("iago")
|
||||
req = dict(full_name=orjson.dumps(new_name).decode())
|
||||
req = dict(full_name=new_name)
|
||||
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||
self.assert_json_error(result, "Invalid format!")
|
||||
|
||||
def test_admin_cannot_set_full_name_with_invalid_characters(self) -> None:
|
||||
new_name = "Opheli*"
|
||||
self.login("iago")
|
||||
req = dict(full_name=orjson.dumps(new_name).decode())
|
||||
req = dict(full_name=new_name)
|
||||
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||
self.assert_json_error(result, "Invalid characters in name!")
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ def update_user_backend(
|
|||
request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
user_id: int,
|
||||
full_name: Optional[str] = REQ(default=None, json_validator=check_string),
|
||||
full_name: Optional[str] = REQ(default=None),
|
||||
role: Optional[int] = REQ(
|
||||
default=None,
|
||||
json_validator=check_int_in(
|
||||
|
|
Loading…
Reference in New Issue