Repository: zulip/zulip

Issue:
Fix encoding of `full_name` parameter under `update_user` endpoint to not use `json_validator`.
The `update_user_backend` view has `full_name` parameter which uses `json_validator` for validating string inputs. This is not necessary and hence can be removed on the lines of similar changes made in #18356. For reference, see: https://chat.zulip.org/#narrow/stream/3-backend/topic/API.20format.20cleanup . We want this to be done most preferably after zulip/python-zulip-api#683.


Discussion:
@zulipbot add "area: api"
Hello @zulip/server-api members, this issue was labeled with the "area: api" label, so you may want to check it out!

<!-- areaLabelAddition -->
This is part of the bigger issue #18035 major part of which is already completed through #18356.

Resolving patch:
diff --git a/version.py b/version.py
--- a/version.py
+++ b/version.py
@@ -33,7 +33,7 @@
 # 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
@@ -48,4 +48,4 @@
 #   historical commits sharing the same major version, in which case a
 #   minor version bump suffices.
 
-PROVISION_VERSION = "163.0"
+PROVISION_VERSION = "164.0"
diff --git a/zerver/views/users.py b/zerver/views/users.py
--- a/zerver/views/users.py
+++ b/zerver/views/users.py
@@ -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(


Test patch:
diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py
--- a/zerver/tests/test_audit_log.py
+++ b/zerver/tests/test_audit_log.py
@@ -206,7 +206,7 @@ def test_change_full_name(self) -> None:
         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(
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -377,7 +377,7 @@ def test_admin_user_can_change_full_name(self) -> None:
         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 @@ def test_admin_user_can_change_full_name(self) -> None:
 
     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 @@ def test_not_allowed_format(self) -> None:
         # 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 @@ def test_allowed_format_complex(self) -> None:
         # 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!")