Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
custom_profile_fields: Display_in_profile_summary optional for update.
Shubham Padia8c30b612014e
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex e5e5bf225e0..5e6a667f023 100644--- a/api_docs/changelog.md+++ b/api_docs/changelog.md@@ -22,10 +22,10 @@ format used by the Zulip server that they are interacting with.**Feature level 252**-* `PATCH /realm/profile_fields/{field_id}`: `name`, `hint` and `field_data` fields are- now optional during an update. Previously we required the clients to populate- the fields in the PATCH request even if there was no change to those fields'- values.+* `PATCH /realm/profile_fields/{field_id}`: `name`, `hint`, `display_in_profile_summary`+ and `field_data` fields are now optional during an update. Previously we required+ the clients to populate the fields in the PATCH request even if there was no+ change to those fields' values.**Feature level 251**diff --git a/zerver/actions/custom_profile_fields.py b/zerver/actions/custom_profile_fields.pyindex e17fec2ad68..f3e694c1fff 100644--- a/zerver/actions/custom_profile_fields.py+++ b/zerver/actions/custom_profile_fields.py@@ -104,7 +104,7 @@ def try_update_realm_custom_profile_field(name: Optional[str] = None,hint: Optional[str] = None,field_data: Optional[ProfileFieldData] = None,- display_in_profile_summary: bool = False,+ display_in_profile_summary: Optional[bool] = None,required: bool = False,) -> None:if name is not None:@@ -112,8 +112,9 @@ def try_update_realm_custom_profile_field(if hint is not None:field.hint = hint- field.display_in_profile_summary = display_in_profile_summaryfield.required = required+ if display_in_profile_summary is not None:+ field.display_in_profile_summary = display_in_profile_summaryif field.field_type in (CustomProfileField.SELECT,diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.pyindex 2205c9ecdc9..e5a3e087167 100644--- a/zerver/tests/test_custom_profile_data.py+++ b/zerver/tests/test_custom_profile_data.py@@ -581,6 +581,18 @@ class UpdateCustomProfileFieldTest(CustomProfileFieldTestCase):)self.assert_json_success(result)+ # Not sending display_in_profile_summary should not set it to false.+ result = self.client_patch(+ f"/json/realm/profile_fields/{field.id}",+ info={+ "hint": "Fav editor",+ },+ )+ field.refresh_from_db()+ self.assertEqual(field.hint, "Fav editor")+ self.assertEqual(field.display_in_profile_summary, True)+ self.assert_json_success(result)+field = CustomProfileField.objects.get(name="Birthday", realm=realm)result = self.client_patch(f"/json/realm/profile_fields/{field.id}",diff --git a/zerver/views/custom_profile_fields.py b/zerver/views/custom_profile_fields.pyindex 5abbbf30b28..364af2cb928 100644--- a/zerver/views/custom_profile_fields.py+++ b/zerver/views/custom_profile_fields.py@@ -118,7 +118,7 @@ def validate_custom_profile_field(def validate_custom_profile_field_update(field: CustomProfileField,- display_in_profile_summary: bool,+ display_in_profile_summary: Optional[bool] = None,field_data: Optional[ProfileFieldData] = None,name: Optional[str] = None,hint: Optional[str] = None,@@ -134,6 +134,8 @@ def validate_custom_profile_field_update(field_data = {}else:field_data = orjson.loads(field.field_data)+ if display_in_profile_summary is None:+ display_in_profile_summary = field.display_in_profile_summaryassert field_data is not Nonevalidate_custom_profile_field(@@ -245,8 +247,8 @@ def update_realm_custom_profile_field(field_data: Optional[ProfileFieldData] = REQ(default=None, json_validator=check_profile_field_data),- display_in_profile_summary: bool = REQ(default=False, json_validator=check_bool),required: bool = REQ(default=False, json_validator=check_bool),+ display_in_profile_summary: Optional[bool] = REQ(default=None, json_validator=check_bool),) -> HttpResponse:realm = user_profile.realmtry: