Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
custom_profile_fields: Make required field optional during update.
Shubham Padia1abd356a910a
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex 5e6a667f023..2f556d42e24 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`, `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.+* `PATCH /realm/profile_fields/{field_id}`: `name`, `hint`, `display_in_profile_summary`,+ `required` 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/version.py b/version.pyindex af78fb5c162..426847660d0 100644--- a/version.py+++ b/version.py@@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"# Changes should be accompanied by documentation explaining what the# new level means in api_docs/changelog.md, as well as "**Changes**"# entries in the endpoint's documentation in `zulip.yaml`.-API_FEATURE_LEVEL = 251+API_FEATURE_LEVEL = 252# 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. Bumpdiff --git a/zerver/actions/custom_profile_fields.py b/zerver/actions/custom_profile_fields.pyindex f3e694c1fff..8bf0242f5ae 100644--- a/zerver/actions/custom_profile_fields.py+++ b/zerver/actions/custom_profile_fields.py@@ -105,14 +105,14 @@ def try_update_realm_custom_profile_field(hint: Optional[str] = None,field_data: Optional[ProfileFieldData] = None,display_in_profile_summary: Optional[bool] = None,- required: bool = False,+ required: Optional[bool] = None,) -> None:if name is not None:field.name = nameif hint is not None:field.hint = hint-- field.required = required+ if required is not None:+ field.required = requiredif display_in_profile_summary is not None:field.display_in_profile_summary = display_in_profile_summarydiff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.pyindex e5a3e087167..0afcff6de3b 100644--- a/zerver/tests/test_custom_profile_data.py+++ b/zerver/tests/test_custom_profile_data.py@@ -528,8 +528,7 @@ class UpdateCustomProfileFieldTest(CustomProfileFieldTestCase):},)self.assert_json_success(result)-- field = CustomProfileField.objects.get(id=field.id, realm=realm)+ field.refresh_from_db()self.assertEqual(CustomProfileField.objects.count(), self.original_count)self.assertEqual(field.name, "New phone number")self.assertEqual(field.hint, "New contact number")@@ -537,6 +536,18 @@ class UpdateCustomProfileFieldTest(CustomProfileFieldTestCase):self.assertEqual(field.display_in_profile_summary, True)self.assertEqual(field.required, True)+ # Not sending required should not set it to false.+ result = self.client_patch(+ f"/json/realm/profile_fields/{field.id}",+ info={+ "hint": "New hint",+ },+ )+ self.assert_json_success(result)+ field.refresh_from_db()+ self.assertEqual(field.hint, "New hint")+ self.assertEqual(field.required, True)+result = self.client_patch(f"/json/realm/profile_fields/{field.id}",info={"name": "Name ", "display_in_profile_summary": "true"},diff --git a/zerver/views/custom_profile_fields.py b/zerver/views/custom_profile_fields.pyindex 364af2cb928..498f6482969 100644--- a/zerver/views/custom_profile_fields.py+++ b/zerver/views/custom_profile_fields.py@@ -247,7 +247,7 @@ def update_realm_custom_profile_field(field_data: Optional[ProfileFieldData] = REQ(default=None, json_validator=check_profile_field_data),- required: bool = REQ(default=False, json_validator=check_bool),+ required: Optional[bool] = REQ(default=None, json_validator=check_bool),display_in_profile_summary: Optional[bool] = REQ(default=None, json_validator=check_bool),) -> HttpResponse:realm = user_profile.realm