mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
custom profile field: Add at-least-one-choice validation for choice field.
Add validation at-least-one-choice required for every choice type field in backend.
This commit is contained in:
committed by
Tim Abbott
parent
a9c8d9b3d9
commit
2a73b2b805
@@ -125,6 +125,10 @@ class CustomProfileFieldTest(ZulipTestCase):
|
||||
result = self.client_post("/json/realm/profile_fields", info=data)
|
||||
self.assert_json_error(result, 'field_data["order"] is not a string')
|
||||
|
||||
data["field_data"] = ujson.dumps({})
|
||||
result = self.client_post("/json/realm/profile_fields", info=data)
|
||||
self.assert_json_error(result, 'Field must have at least one choice.')
|
||||
|
||||
data["field_data"] = ujson.dumps({
|
||||
'python': {'text': 'Python', 'order': '1'},
|
||||
'java': {'text': 'Java', 'order': '2'},
|
||||
|
||||
@@ -49,6 +49,10 @@ def create_realm_custom_profile_field(request: HttpRequest,
|
||||
if field_type not in field_types:
|
||||
return json_error(_("Invalid field type."))
|
||||
|
||||
# Choice type field must have at least have one choice
|
||||
if field_type == CustomProfileField.CHOICE and len(field_data) < 1:
|
||||
return json_error(_("Field must have at least one choice."))
|
||||
|
||||
error = validate_field_data(field_data)
|
||||
if error:
|
||||
return json_error(error)
|
||||
|
||||
Reference in New Issue
Block a user