diff --git a/api_docs/changelog.md b/api_docs/changelog.md index 5e6a667f02..2f556d42e2 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.py index af78fb5c16..426847660d 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. Bump diff --git a/zerver/actions/custom_profile_fields.py b/zerver/actions/custom_profile_fields.py index f3e694c1ff..8bf0242f5a 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 = name if hint is not None: field.hint = hint - - field.required = required + if required is not None: + field.required = required if display_in_profile_summary is not None: field.display_in_profile_summary = display_in_profile_summary diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.py index e5a3e08716..0afcff6de3 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.py index 364af2cb92..498f648296 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