Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

custom profile fields: Rename "CHOICE" to "SELECT" in backend.

tushar912b220d29fedea
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index afdfa4c809f..285cf0b443d 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -6748,7 +6748,7 @@ def try_add_realm_custom_profile_field(
field = CustomProfileField(realm=realm, name=name, field_type=field_type)
field.hint = hint
if (
- field.field_type == CustomProfileField.CHOICE
+ field.field_type == CustomProfileField.SELECT
or field.field_type == CustomProfileField.EXTERNAL_ACCOUNT
):
field.field_data = orjson.dumps(field_data or {}).decode()
@@ -6783,7 +6783,7 @@ def try_update_realm_custom_profile_field(
field.name = name
field.hint = hint
if (
- field.field_type == CustomProfileField.CHOICE
+ field.field_type == CustomProfileField.SELECT
or field.field_type == CustomProfileField.EXTERNAL_ACCOUNT
):
field.field_data = orjson.dumps(field_data or {}).decode()
diff --git a/zerver/lib/users.py b/zerver/lib/users.py
index 3d52c189a2c..3fa103be275 100644
--- a/zerver/lib/users.py
+++ b/zerver/lib/users.py
@@ -309,8 +309,8 @@ def validate_user_custom_profile_field(
if field_type in validators:
validator = validators[field_type]
return validator(var_name, value)
- elif field_type == CustomProfileField.CHOICE:
- choice_field_validator = CustomProfileField.CHOICE_FIELD_VALIDATORS[field_type]
+ elif field_type == CustomProfileField.SELECT:
+ choice_field_validator = CustomProfileField.SELECT_FIELD_VALIDATORS[field_type]
field_data = field.field_data
# Put an assertion so that mypy doesn't complain.
assert field_data is not None
diff --git a/zerver/models.py b/zerver/models.py
index 3dc99d14e7c..60cf3f67b64 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -3298,24 +3298,24 @@ class CustomProfileField(models.Model):
SHORT_TEXT = 1
LONG_TEXT = 2
- CHOICE = 3
+ SELECT = 3
DATE = 4
URL = 5
USER = 6
EXTERNAL_ACCOUNT = 7
# These are the fields whose validators require more than var_name
- # and value argument. i.e. CHOICE require field_data, USER require
+ # and value argument. i.e. SELECT require field_data, USER require
# realm as argument.
- CHOICE_FIELD_TYPE_DATA: List[ExtendedFieldElement] = [
- (CHOICE, ugettext_lazy("List of options"), validate_choice_field, str, "CHOICE"),
+ SELECT_FIELD_TYPE_DATA: List[ExtendedFieldElement] = [
+ (SELECT, ugettext_lazy("List of options"), validate_choice_field, str, "SELECT"),
]
USER_FIELD_TYPE_DATA: List[UserFieldElement] = [
(USER, ugettext_lazy("Person picker"), check_valid_user_ids, ast.literal_eval, "USER"),
]
- CHOICE_FIELD_VALIDATORS: Dict[int, ExtendedValidator] = {
- item[0]: item[2] for item in CHOICE_FIELD_TYPE_DATA
+ SELECT_FIELD_VALIDATORS: Dict[int, ExtendedValidator] = {
+ item[0]: item[2] for item in SELECT_FIELD_TYPE_DATA
}
USER_FIELD_VALIDATORS: Dict[int, RealmUserValidator] = {
item[0]: item[2] for item in USER_FIELD_TYPE_DATA
@@ -3336,7 +3336,7 @@ class CustomProfileField(models.Model):
),
]
- ALL_FIELD_TYPES = [*FIELD_TYPE_DATA, *CHOICE_FIELD_TYPE_DATA, *USER_FIELD_TYPE_DATA]
+ ALL_FIELD_TYPES = [*FIELD_TYPE_DATA, *SELECT_FIELD_TYPE_DATA, *USER_FIELD_TYPE_DATA]
FIELD_VALIDATORS: Dict[int, Validator[Union[int, str, List[int]]]] = {
item[0]: item[2] for item in FIELD_TYPE_DATA
@@ -3355,7 +3355,7 @@ class CustomProfileField(models.Model):
# type/name/hint.
#
# The format depends on the type. Field types SHORT_TEXT, LONG_TEXT,
- # DATE, URL, and USER leave this null. Fields of type CHOICE store the
+ # DATE, URL, and USER leave this null. Fields of type SELECT store the
# choices' descriptions.
#
# Note: There is no performance overhead of using TextField in PostgreSQL.
diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.py
index 74b69393135..6a4b4d9d20f 100644
--- a/zerver/tests/test_custom_profile_data.py
+++ b/zerver/tests/test_custom_profile_data.py
@@ -87,7 +87,7 @@ class CreateCustomProfileFieldTest(CustomProfileFieldTestCase):
self.login("iago")
data: Dict[str, Union[str, int]] = {}
data["name"] = "Favorite programming language"
- data["field_type"] = CustomProfileField.CHOICE
+ data["field_type"] = CustomProfileField.SELECT
data["field_data"] = "invalid"
result = self.client_post("/json/realm/profile_fields", info=data)
diff --git a/zerver/views/custom_profile_fields.py b/zerver/views/custom_profile_fields.py
index 1e6fffd31aa..61b9b72c351 100644
--- a/zerver/views/custom_profile_fields.py
+++ b/zerver/views/custom_profile_fields.py
@@ -58,7 +58,7 @@ def validate_field_name_and_hint(name: str, hint: str) -> None:
def validate_custom_field_data(field_type: int, field_data: ProfileFieldData) -> None:
try:
- if field_type == CustomProfileField.CHOICE:
+ if field_type == CustomProfileField.SELECT:
# Choice type field must have at least have one choice
if len(field_data) < 1:
raise JsonableError(_("Field must have at least one choice."))
diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py
index e91ad56aaee..3e8c534647e 100644
--- a/zilencer/management/commands/populate_db.py
+++ b/zilencer/management/commands/populate_db.py
@@ -607,7 +607,7 @@ class Command(BaseCommand):
"emacs": {"text": "Emacs", "order": "2"},
}
favorite_editor = try_add_realm_custom_profile_field(
- zulip_realm, "Favorite editor", CustomProfileField.CHOICE, field_data=field_data
+ zulip_realm, "Favorite editor", CustomProfileField.SELECT, field_data=field_data
)
birthday = try_add_realm_custom_profile_field(
zulip_realm, "Birthday", CustomProfileField.DATE