mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 07:52:19 +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)
|
result = self.client_post("/json/realm/profile_fields", info=data)
|
||||||
self.assert_json_error(result, 'field_data["order"] is not a string')
|
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({
|
data["field_data"] = ujson.dumps({
|
||||||
'python': {'text': 'Python', 'order': '1'},
|
'python': {'text': 'Python', 'order': '1'},
|
||||||
'java': {'text': 'Java', 'order': '2'},
|
'java': {'text': 'Java', 'order': '2'},
|
||||||
|
|||||||
@@ -49,6 +49,10 @@ def create_realm_custom_profile_field(request: HttpRequest,
|
|||||||
if field_type not in field_types:
|
if field_type not in field_types:
|
||||||
return json_error(_("Invalid field type."))
|
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)
|
error = validate_field_data(field_data)
|
||||||
if error:
|
if error:
|
||||||
return json_error(error)
|
return json_error(error)
|
||||||
|
|||||||
Reference in New Issue
Block a user