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 url = "/json/users/" + encodeURIComponent(user_id);
|
||||||
const data = {
|
const data = {
|
||||||
full_name: JSON.stringify(full_name.val()),
|
full_name: full_name.val(),
|
||||||
role: JSON.stringify(role),
|
role: JSON.stringify(role),
|
||||||
profile_data: JSON.stringify(profile_data),
|
profile_data: JSON.stringify(profile_data),
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,11 @@ below features are supported.
|
||||||
|
|
||||||
## Changes in Zulip 5.0
|
## 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**
|
**Feature level 105**
|
||||||
|
|
||||||
* [`POST /register`](/api/register-queue), [`PATCH
|
* [`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
|
# Changes should be accompanied by documentation explaining what the
|
||||||
# new level means in templates/zerver/api/changelog.md, as well as
|
# new level means in templates/zerver/api/changelog.md, as well as
|
||||||
# "**Changes**" entries in the endpoint's documentation in `zulip.yaml`.
|
# "**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
|
# 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
|
# only when going from an old version of the code to a newer version. Bump
|
||||||
|
|
|
@ -8277,11 +8277,12 @@ paths:
|
||||||
in: query
|
in: query
|
||||||
description: |
|
description: |
|
||||||
The user's full name.
|
The user's full name.
|
||||||
content:
|
|
||||||
application/json:
|
**Changes**: Removed unnecessary JSON-encoding of this parameter in
|
||||||
schema:
|
Zulip 5.0 (feature level 106).
|
||||||
type: string
|
schema:
|
||||||
example: NewName
|
type: string
|
||||||
|
example: NewName
|
||||||
required: false
|
required: false
|
||||||
- name: role
|
- name: role
|
||||||
in: query
|
in: query
|
||||||
|
|
|
@ -206,7 +206,7 @@ class TestRealmAuditLog(ZulipTestCase):
|
||||||
start = timezone_now()
|
start = timezone_now()
|
||||||
new_name = "George Hamletovich"
|
new_name = "George Hamletovich"
|
||||||
self.login("iago")
|
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)
|
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||||
self.assertTrue(result.status_code == 200)
|
self.assertTrue(result.status_code == 200)
|
||||||
query = RealmAuditLog.objects.filter(
|
query = RealmAuditLog.objects.filter(
|
||||||
|
|
|
@ -377,7 +377,7 @@ class PermissionTest(ZulipTestCase):
|
||||||
new_name = "new name"
|
new_name = "new name"
|
||||||
self.login("iago")
|
self.login("iago")
|
||||||
hamlet = self.example_user("hamlet")
|
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)
|
result = self.client_patch(f"/json/users/{hamlet.id}", req)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
hamlet = self.example_user("hamlet")
|
hamlet = self.example_user("hamlet")
|
||||||
|
@ -385,21 +385,21 @@ class PermissionTest(ZulipTestCase):
|
||||||
|
|
||||||
def test_non_admin_cannot_change_full_name(self) -> None:
|
def test_non_admin_cannot_change_full_name(self) -> None:
|
||||||
self.login("hamlet")
|
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)
|
result = self.client_patch("/json/users/{}".format(self.example_user("othello").id), req)
|
||||||
self.assert_json_error(result, "Insufficient permission")
|
self.assert_json_error(result, "Insufficient permission")
|
||||||
|
|
||||||
def test_admin_cannot_set_long_full_name(self) -> None:
|
def test_admin_cannot_set_long_full_name(self) -> None:
|
||||||
new_name = "a" * (UserProfile.MAX_NAME_LENGTH + 1)
|
new_name = "a" * (UserProfile.MAX_NAME_LENGTH + 1)
|
||||||
self.login("iago")
|
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)
|
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||||
self.assert_json_error(result, "Name too long!")
|
self.assert_json_error(result, "Name too long!")
|
||||||
|
|
||||||
def test_admin_cannot_set_short_full_name(self) -> None:
|
def test_admin_cannot_set_short_full_name(self) -> None:
|
||||||
new_name = "a"
|
new_name = "a"
|
||||||
self.login("iago")
|
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)
|
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||||
self.assert_json_error(result, "Name too short!")
|
self.assert_json_error(result, "Name too short!")
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ class PermissionTest(ZulipTestCase):
|
||||||
# Name of format "Alice|999" breaks in Markdown
|
# Name of format "Alice|999" breaks in Markdown
|
||||||
new_name = "iago|72"
|
new_name = "iago|72"
|
||||||
self.login("iago")
|
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)
|
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||||
self.assert_json_error(result, "Invalid format!")
|
self.assert_json_error(result, "Invalid format!")
|
||||||
|
|
||||||
|
@ -415,21 +415,21 @@ class PermissionTest(ZulipTestCase):
|
||||||
# Adding characters after r'|d+' doesn't break Markdown
|
# Adding characters after r'|d+' doesn't break Markdown
|
||||||
new_name = "Hello- 12iago|72k"
|
new_name = "Hello- 12iago|72k"
|
||||||
self.login("iago")
|
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)
|
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
def test_not_allowed_format_complex(self) -> None:
|
def test_not_allowed_format_complex(self) -> None:
|
||||||
new_name = "Hello- 12iago|72"
|
new_name = "Hello- 12iago|72"
|
||||||
self.login("iago")
|
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)
|
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||||
self.assert_json_error(result, "Invalid format!")
|
self.assert_json_error(result, "Invalid format!")
|
||||||
|
|
||||||
def test_admin_cannot_set_full_name_with_invalid_characters(self) -> None:
|
def test_admin_cannot_set_full_name_with_invalid_characters(self) -> None:
|
||||||
new_name = "Opheli*"
|
new_name = "Opheli*"
|
||||||
self.login("iago")
|
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)
|
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
|
||||||
self.assert_json_error(result, "Invalid characters in name!")
|
self.assert_json_error(result, "Invalid characters in name!")
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,7 @@ def update_user_backend(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
user_profile: UserProfile,
|
user_profile: UserProfile,
|
||||||
user_id: int,
|
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(
|
role: Optional[int] = REQ(
|
||||||
default=None,
|
default=None,
|
||||||
json_validator=check_int_in(
|
json_validator=check_int_in(
|
||||||
|
|
Loading…
Reference in New Issue