mirror of https://github.com/zulip/zulip.git
custom_profile_fields: Don't allow leading/trailing whitespaces.
Allowing such whitespaces can lead to hard to debug issues e.g. with ldap sync.
This commit is contained in:
parent
bd61b570aa
commit
6e83bcc0d5
|
@ -70,6 +70,15 @@ class CreateCustomProfileFieldTest(CustomProfileFieldTestCase):
|
|||
field = CustomProfileField.objects.get(name="Phone", realm=realm)
|
||||
self.assertEqual(field.id, field.order)
|
||||
|
||||
data["name"] = "Name "
|
||||
data["hint"] = "Some name"
|
||||
data["field_type"] = CustomProfileField.SHORT_TEXT
|
||||
result = self.client_post("/json/realm/profile_fields", info=data)
|
||||
self.assert_json_success(result)
|
||||
|
||||
field = CustomProfileField.objects.get(name="Name", realm=realm)
|
||||
self.assertEqual(field.id, field.order)
|
||||
|
||||
result = self.client_post("/json/realm/profile_fields", info=data)
|
||||
self.assert_json_error(result,
|
||||
'A field with that label already exists.')
|
||||
|
@ -413,6 +422,15 @@ class UpdateCustomProfileFieldTest(CustomProfileFieldTestCase):
|
|||
self.assertEqual(field.hint, 'New contact number')
|
||||
self.assertEqual(field.field_type, CustomProfileField.SHORT_TEXT)
|
||||
|
||||
result = self.client_patch(
|
||||
f"/json/realm/profile_fields/{field.id}",
|
||||
info={'name': 'Name ',
|
||||
'field_type': CustomProfileField.SHORT_TEXT},
|
||||
)
|
||||
self.assert_json_success(result)
|
||||
field.refresh_from_db()
|
||||
self.assertEqual(field.name, 'Name')
|
||||
|
||||
field = CustomProfileField.objects.get(name="Favorite editor", realm=realm)
|
||||
result = self.client_patch(
|
||||
f"/json/realm/profile_fields/{field.id}",
|
||||
|
|
|
@ -90,7 +90,7 @@ def validate_custom_profile_field(name: str, hint: str, field_type: int,
|
|||
@has_request_variables
|
||||
def create_realm_custom_profile_field(request: HttpRequest,
|
||||
user_profile: UserProfile,
|
||||
name: str=REQ(default=''),
|
||||
name: str=REQ(default='', converter=lambda x: x.strip()),
|
||||
hint: str=REQ(default=''),
|
||||
field_data: ProfileFieldData=REQ(default={},
|
||||
converter=orjson.loads),
|
||||
|
@ -133,7 +133,7 @@ def delete_realm_custom_profile_field(request: HttpRequest, user_profile: UserPr
|
|||
@has_request_variables
|
||||
def update_realm_custom_profile_field(request: HttpRequest, user_profile: UserProfile,
|
||||
field_id: int,
|
||||
name: str=REQ(default=''),
|
||||
name: str=REQ(default='', converter=lambda x: x.strip()),
|
||||
hint: str=REQ(default=''),
|
||||
field_data: ProfileFieldData=REQ(default={},
|
||||
converter=orjson.loads),
|
||||
|
|
Loading…
Reference in New Issue