custom_profile_fields: Make required field optional during update.

This commit is contained in:
Shubham Padia 2024-03-30 17:42:18 +05:30 committed by Tim Abbott
parent 8c30b61201
commit 1abd356a91
5 changed files with 22 additions and 11 deletions

View File

@ -22,10 +22,10 @@ format used by the Zulip server that they are interacting with.
**Feature level 252** **Feature level 252**
* `PATCH /realm/profile_fields/{field_id}`: `name`, `hint`, `display_in_profile_summary` * `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 `required` and `field_data` fields are now optional during an update. Previously we
the clients to populate the fields in the PATCH request even if there was no required the clients to populate the fields in the PATCH request even if there was
change to those fields' values. no change to those fields' values.
**Feature level 251** **Feature level 251**

View File

@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# Changes should be accompanied by documentation explaining what the # Changes should be accompanied by documentation explaining what the
# new level means in api_docs/changelog.md, as well as "**Changes**" # new level means in api_docs/changelog.md, as well as "**Changes**"
# entries in the endpoint's documentation in `zulip.yaml`. # 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 # 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

View File

@ -105,14 +105,14 @@ def try_update_realm_custom_profile_field(
hint: Optional[str] = None, hint: Optional[str] = None,
field_data: Optional[ProfileFieldData] = None, field_data: Optional[ProfileFieldData] = None,
display_in_profile_summary: Optional[bool] = None, display_in_profile_summary: Optional[bool] = None,
required: bool = False, required: Optional[bool] = None,
) -> None: ) -> None:
if name is not None: if name is not None:
field.name = name field.name = name
if hint is not None: if hint is not None:
field.hint = hint field.hint = hint
if required is not None:
field.required = required field.required = required
if display_in_profile_summary is not None: if display_in_profile_summary is not None:
field.display_in_profile_summary = display_in_profile_summary field.display_in_profile_summary = display_in_profile_summary

View File

@ -528,8 +528,7 @@ class UpdateCustomProfileFieldTest(CustomProfileFieldTestCase):
}, },
) )
self.assert_json_success(result) self.assert_json_success(result)
field.refresh_from_db()
field = CustomProfileField.objects.get(id=field.id, realm=realm)
self.assertEqual(CustomProfileField.objects.count(), self.original_count) self.assertEqual(CustomProfileField.objects.count(), self.original_count)
self.assertEqual(field.name, "New phone number") self.assertEqual(field.name, "New phone number")
self.assertEqual(field.hint, "New contact 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.display_in_profile_summary, True)
self.assertEqual(field.required, 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( result = self.client_patch(
f"/json/realm/profile_fields/{field.id}", f"/json/realm/profile_fields/{field.id}",
info={"name": "Name ", "display_in_profile_summary": "true"}, info={"name": "Name ", "display_in_profile_summary": "true"},

View File

@ -247,7 +247,7 @@ def update_realm_custom_profile_field(
field_data: Optional[ProfileFieldData] = REQ( field_data: Optional[ProfileFieldData] = REQ(
default=None, json_validator=check_profile_field_data 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), display_in_profile_summary: Optional[bool] = REQ(default=None, json_validator=check_bool),
) -> HttpResponse: ) -> HttpResponse:
realm = user_profile.realm realm = user_profile.realm