Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
custom_profile_fields: Refactor internal constants. Renames internal constants LONG_TEXT -> PARAGRAPH and SELECT -> DROPDOWN to match new UI names.
Sairam Bisoyi722604c75dec
diff --git a/web/src/custom_profile_fields_ui.ts b/web/src/custom_profile_fields_ui.tsindex 57f5141228d..db78627f9fc 100644--- a/web/src/custom_profile_fields_ui.ts+++ b/web/src/custom_profile_fields_ui.ts@@ -32,9 +32,9 @@ export function append_custom_profile_fields(element_id: string, user_id: numberconst all_field_types = realm.custom_profile_field_types;const all_field_template_types = new Map([- [all_field_types.LONG_TEXT.id, "text"],+ [all_field_types.PARAGRAPH.id, "text"],[all_field_types.SHORT_TEXT.id, "text"],- [all_field_types.SELECT.id, "select"],+ [all_field_types.DROPDOWN.id, "select"],[all_field_types.USER.id, "user"],[all_field_types.DATE.id, "date"],[all_field_types.EXTERNAL_ACCOUNT.id, "text"],@@ -48,7 +48,7 @@ export function append_custom_profile_fields(element_id: string, user_id: numberrendered_value: "",};const editable_by_user = current_user.is_admin || field.editable_by_user;- const is_select_field = field.type === all_field_types.SELECT.id;+ const is_select_field = field.type === all_field_types.DROPDOWN.id;const field_choices = [];if (is_select_field) {@@ -68,7 +68,7 @@ export function append_custom_profile_fields(element_id: string, user_id: numberfield,field_type: all_field_template_types.get(field.type),field_value,- is_long_text_field: field.type === all_field_types.LONG_TEXT.id,+ is_long_text_field: field.type === all_field_types.PARAGRAPH.id,is_user_field: field.type === all_field_types.USER.id,is_date_field: field.type === all_field_types.DATE.id,is_url_field: field.type === all_field_types.URL.id,diff --git a/web/src/settings_components.ts b/web/src/settings_components.tsindex 43c88d9d1a7..aebfe03f067 100644--- a/web/src/settings_components.ts+++ b/web/src/settings_components.ts@@ -485,7 +485,7 @@ export function read_field_data_from_form(const field_types = realm.custom_profile_field_types;// Only the following field types support associated field data.- if (field_type_id === field_types.SELECT.id) {+ if (field_type_id === field_types.DROPDOWN.id) {return read_select_field_data_from_form($profile_field_form, old_field_data);} else if (field_type_id === field_types.EXTERNAL_ACCOUNT.id) {const parsed_old_field_data = old_field_datadiff --git a/web/src/settings_profile_fields.ts b/web/src/settings_profile_fields.tsindex 898b60496af..cc1d089269e 100644--- a/web/src/settings_profile_fields.ts+++ b/web/src/settings_profile_fields.ts@@ -303,7 +303,7 @@ function update_form_for_field_type_selection(): void {$("#profile_field_hint").val(default_hint);break;}- case field_types.SELECT.id: {+ case field_types.DROPDOWN.id: {$("#profile_field_choices_row").show();}}@@ -612,7 +612,7 @@ function open_custom_profile_field_edit_form_modal(this: HTMLElement): void {field_data = JSON.parse(field.field_data);}let choices: FieldChoice[] = [];- if (field.type === field_types.SELECT.id) {+ if (field.type === field_types.DROPDOWN.id) {const select_field_data = settings_components.select_field_data_schema.parse(field_data);choices = parse_field_choices_from_field_data(select_field_data);}@@ -627,7 +627,7 @@ function open_custom_profile_field_edit_form_modal(this: HTMLElement): void {required: field.required,editable_by_user: field.editable_by_user,use_for_user_matching: field.use_for_user_matching,- is_select_field: field.type === field_types.SELECT.id,+ is_select_field: field.type === field_types.DROPDOWN.id,is_external_account_field: field.type === field_types.EXTERNAL_ACCOUNT.id,valid_to_display_in_summary: is_valid_to_display_in_summary(field.type),valid_to_use_for_user_matching: is_valid_to_use_for_user_matching(field.type),@@ -649,7 +649,7 @@ function open_custom_profile_field_edit_form_modal(this: HTMLElement): void {.addClass("display_in_profile_summary_tooltip disabled_label");}- if (field.type === field_types.SELECT.id) {+ if (field.type === field_types.DROPDOWN.id) {set_up_select_field_edit_form($profile_field_form, field);}@@ -729,7 +729,7 @@ function open_custom_profile_field_edit_form_modal(this: HTMLElement): void {dialog_widget.submit_api_request(channel.patch, url, data, opts);}- if (field.type === field_types.SELECT.id && data["field_data"] !== undefined) {+ if (field.type === field_types.DROPDOWN.id && data["field_data"] !== undefined) {const new_values = new Set(Object.keys(settings_components.select_field_data_schema.parse(@@ -874,7 +874,7 @@ export function do_populate_profile_fields(profile_fields_data: CustomProfileFie},modifier_html(profile_field) {let choices: FieldChoice[] = [];- if (profile_field.field_data && profile_field.type === field_types.SELECT.id) {+ if (profile_field.field_data && profile_field.type === field_types.DROPDOWN.id) {const field_data = settings_components.select_field_data_schema.parse(JSON.parse(profile_field.field_data),);@@ -891,7 +891,7 @@ export function do_populate_profile_fields(profile_fields_data: CustomProfileFiehint: profile_field.hint,type: field_type_id_to_string(profile_field.type),choices,- is_select_field: profile_field.type === field_types.SELECT.id,+ is_select_field: profile_field.type === field_types.DROPDOWN.id,is_external_account_field:profile_field.type === field_types.EXTERNAL_ACCOUNT.id,display_in_profile_summary,diff --git a/web/src/state_data.ts b/web/src/state_data.tsindex 4ce74ab6c5e..c6f121a0874 100644--- a/web/src/state_data.ts+++ b/web/src/state_data.ts@@ -382,9 +382,9 @@ const current_user_schema = z.object({const custom_profile_field_types_schema = z.object({SHORT_TEXT: z.object({id: z.number(), name: z.string()}),- LONG_TEXT: z.object({id: z.number(), name: z.string()}),+ PARAGRAPH: z.object({id: z.number(), name: z.string()}),DATE: z.object({id: z.number(), name: z.string()}),- SELECT: z.object({id: z.number(), name: z.string()}),+ DROPDOWN: z.object({id: z.number(), name: z.string()}),URL: z.object({id: z.number(), name: z.string()}),EXTERNAL_ACCOUNT: z.object({id: z.number(), name: z.string()}),USER: z.object({id: z.number(), name: z.string()}),diff --git a/web/src/user_profile.ts b/web/src/user_profile.tsindex 873733e99d2..65bc3ddd0b4 100644--- a/web/src/user_profile.ts+++ b/web/src/user_profile.ts@@ -489,7 +489,7 @@ export function get_custom_profile_field_data(is_user_field: false,is_link: field_type === field_types.URL.id,is_external_account: field_type === field_types.EXTERNAL_ACCOUNT.id,- is_long_text: field_type === field_types.LONG_TEXT.id,+ is_long_text: field_type === field_types.PARAGRAPH.id,type: field_type,display_in_profile_summary: field.display_in_profile_summary,required: field.required,@@ -506,7 +506,7 @@ export function get_custom_profile_field_data(profile_field.is_user_field = true;profile_field.value = field_value.value;break;- case field_types.SELECT.id: {+ case field_types.DROPDOWN.id: {const field_choice_dict = settings_components.select_field_data_schema.parse(JSON.parse(field.field_data),);@@ -514,7 +514,7 @@ export function get_custom_profile_field_data(break;}case field_types.SHORT_TEXT.id:- case field_types.LONG_TEXT.id:+ case field_types.PARAGRAPH.id:profile_field.value = field_value.value;profile_field.rendered_value = field_value.rendered_value;break;diff --git a/web/tests/settings_profile_fields.test.cjs b/web/tests/settings_profile_fields.test.cjsindex 25977d13cc4..15777fe5bba 100644--- a/web/tests/settings_profile_fields.test.cjs+++ b/web/tests/settings_profile_fields.test.cjs@@ -10,15 +10,15 @@ const loading = mock_esm("../src/loading");const SHORT_TEXT_ID = 1;-const SELECT_ID = 3;+const DROPDOWN_ID = 3;const EXTERNAL_ACCOUNT_ID = 7;-const LONG_TEXT_ID = 2;+const PARAGRAPH_ID = 2;const USER_FIELD_ID = 6;const SHORT_TEXT_NAME = "Short text";-const SELECT_NAME = "Dropdown";+const DROPDOWN_NAME = "Dropdown";const EXTERNAL_ACCOUNT_NAME = "External account";-const LONG_TEXT_NAME = "Paragraph";+const PARAGRAPH_NAME = "Paragraph";const USER_FIELD_NAME = "Person";const custom_profile_field_types = {@@ -26,17 +26,17 @@ const custom_profile_field_types = {id: SHORT_TEXT_ID,name: SHORT_TEXT_NAME,},- SELECT: {- id: SELECT_ID,- name: SELECT_NAME,+ DROPDOWN: {+ id: DROPDOWN_ID,+ name: DROPDOWN_NAME,},EXTERNAL_ACCOUNT: {id: EXTERNAL_ACCOUNT_ID,name: EXTERNAL_ACCOUNT_NAME,},- LONG_TEXT: {- id: LONG_TEXT_ID,- name: LONG_TEXT_NAME,+ PARAGRAPH: {+ id: PARAGRAPH_ID,+ name: PARAGRAPH_NAME,},USER: {id: USER_FIELD_ID,@@ -105,7 +105,7 @@ run_test("populate_profile_fields", ({mock_template, override}) => {required: false,},{- type: SELECT_ID,+ type: DROPDOWN_ID,id: 30,name: "meal",hint: "lunch",@@ -171,7 +171,7 @@ run_test("populate_profile_fields", ({mock_template, override}) => {id: 30,name: "meal",hint: "lunch",- type: SELECT_NAME,+ type: DROPDOWN_NAME,choices: [{order: "0", value: "0", text: "lunch"},{order: "1", value: "1", text: "dinner"},diff --git a/zerver/actions/custom_profile_fields.py b/zerver/actions/custom_profile_fields.pyindex f9cc1dd4a96..3366a270011 100644--- a/zerver/actions/custom_profile_fields.py+++ b/zerver/actions/custom_profile_fields.py@@ -74,7 +74,7 @@ def try_add_realm_custom_profile_field()custom_profile_field.hint = hintif custom_profile_field.field_type in (- CustomProfileField.SELECT,+ CustomProfileField.DROPDOWN,CustomProfileField.EXTERNAL_ACCOUNT,):custom_profile_field.field_data = orjson.dumps(field_data or {}).decode()@@ -137,12 +137,12 @@ def try_update_realm_custom_profile_field(field.use_for_user_matching = use_for_user_matchingif field.field_type in (- CustomProfileField.SELECT,+ CustomProfileField.DROPDOWN,CustomProfileField.EXTERNAL_ACCOUNT,):# If field_data is None, field_data is unchanged and there is no need for# comparing field_data values.- if field_data is not None and field.field_type == CustomProfileField.SELECT:+ if field_data is not None and field.field_type == CustomProfileField.DROPDOWN:remove_custom_profile_field_value_if_required(field, field_data)# If field.field_data is the default empty string, we will set field_data@@ -246,7 +246,7 @@ def get_custom_profile_field_display_value(field_value: CustomProfileFieldValue)return ""type = field_value.field.field_type- if type == CustomProfileField.SELECT:+ if type == CustomProfileField.DROPDOWN:field_data_dict = orjson.loads(field_value.field.field_data)value_key = field_value.valuereturn field_data_dict[value_key]["text"]diff --git a/zerver/lib/users.py b/zerver/lib/users.pyindex 2e54e19d254..6571ba84c28 100644--- a/zerver/lib/users.py+++ b/zerver/lib/users.py@@ -527,7 +527,7 @@ def validate_user_custom_profile_field(if field_type in validators:validator = validators[field_type]return validator(var_name, value)- elif field_type == CustomProfileField.SELECT:+ elif field_type == CustomProfileField.DROPDOWN:choice_field_validator = CustomProfileField.SELECT_FIELD_VALIDATORS[field_type]field_data = field.field_data# Put an assertion so that mypy doesn't complain.diff --git a/zerver/models/custom_profile_fields.py b/zerver/models/custom_profile_fields.pyindex fdd6da55821..ab07ee1a1e0 100644--- a/zerver/models/custom_profile_fields.py+++ b/zerver/models/custom_profile_fields.py@@ -90,8 +90,8 @@ class CustomProfileField(models.Model):editable_by_user = models.BooleanField(default=True, db_default=True)SHORT_TEXT = 1- LONG_TEXT = 2- SELECT = 3+ PARAGRAPH = 2+ DROPDOWN = 3DATE = 4URL = 5USER = 6@@ -99,10 +99,10 @@ class CustomProfileField(models.Model):PRONOUNS = 8# These are the fields whose validators require more than var_name- # and value argument. i.e. SELECT require field_data, USER require+ # and value argument. i.e. DROPDOWN require field_data, USER require# realm as argument.SELECT_FIELD_TYPE_DATA: list[ExtendedFieldElement] = [- (SELECT, gettext_lazy("Dropdown"), validate_select_field, str, "SELECT"),+ (DROPDOWN, gettext_lazy("Dropdown"), validate_select_field, str, "DROPDOWN"),]USER_FIELD_TYPE_DATA: list[UserFieldElement] = [(USER, gettext_lazy("Users"), check_valid_user_ids, orjson.loads, "USER"),@@ -118,7 +118,7 @@ class CustomProfileField(models.Model):FIELD_TYPE_DATA: list[FieldElement] = [# Type, display name, validator, converter, keyword(SHORT_TEXT, gettext_lazy("Short text"), check_short_string, str, "SHORT_TEXT"),- (LONG_TEXT, gettext_lazy("Paragraph"), check_long_string, str, "LONG_TEXT"),+ (PARAGRAPH, gettext_lazy("Paragraph"), check_long_string, str, "PARAGRAPH"),(DATE, gettext_lazy("Date"), check_date, str, "DATE"),(URL, gettext_lazy("Link"), check_url, str, "URL"),(@@ -153,8 +153,8 @@ class CustomProfileField(models.Model):# A JSON blob of any additional data needed to define the field beyond# type/name/hint.#- # The format depends on the type. Field types SHORT_TEXT, LONG_TEXT,- # DATE, URL, and USER leave this empty. Fields of type SELECT store the+ # The format depends on the type. Field types SHORT_TEXT, PARAGRAPH,+ # DATE, URL, and USER leave this empty. Fields of type DROPDOWN store the# choices' descriptions.## Note: There is no performance overhead of using TextField in PostgreSQL.@@ -187,7 +187,7 @@ class CustomProfileField(models.Model):return data_as_dictdef is_renderable(self) -> bool:- if self.field_type in [CustomProfileField.SHORT_TEXT, CustomProfileField.LONG_TEXT]:+ if self.field_type in [CustomProfileField.SHORT_TEXT, CustomProfileField.PARAGRAPH]:return Truereturn Falsediff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 41e4c9e49b4..6f0f8a66923 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -17858,9 +17858,9 @@ paths:property itself. The current supported field types are as follows:- `SHORT_TEXT`- - `LONG_TEXT`+ - `PARAGRAPH`- `DATE` for date-based fields.- - `SELECT` for a list of options.+ - `DROPDOWN` for a list of options.- `URL` for links.- `EXTERNAL_ACCOUNT` for external accounts.- `USER` for selecting a user for the field.diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.pyindex a48483fec30..11c741cc22d 100644--- a/zerver/tests/test_custom_profile_data.py+++ b/zerver/tests/test_custom_profile_data.py@@ -96,7 +96,7 @@ class CreateCustomProfileFieldTest(CustomProfileFieldTestCase):data["name"] = "Phone"data["hint"] = "Contact number"- data["field_type"] = CustomProfileField.LONG_TEXT+ data["field_type"] = CustomProfileField.PARAGRAPHdata["use_for_user_matching"] = "true"result = self.client_post("/json/realm/profile_fields", info=data)self.assert_json_error(result, "Field type not supported for use for user matching.")@@ -105,7 +105,7 @@ class CreateCustomProfileFieldTest(CustomProfileFieldTestCase):self.login("iago")data: dict[str, str | int] = {}data["name"] = "Favorite programming language"- data["field_type"] = CustomProfileField.SELECT+ data["field_type"] = CustomProfileField.DROPDOWNdata["field_data"] = "invalid"result = self.client_post("/json/realm/profile_fields", info=data)diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex 236f943234a..e1694eace3b 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -1728,7 +1728,7 @@ class NormalActionsTest(BaseAction):with self.verify_action() as events:try_add_realm_custom_profile_field(- realm=realm, name="Expertise", field_type=CustomProfileField.LONG_TEXT+ realm=realm, name="Expertise", field_type=CustomProfileField.PARAGRAPH)check_custom_profile_fields("events[0]", events[0])diff --git a/zerver/views/custom_profile_fields.py b/zerver/views/custom_profile_fields.pyindex b21b2cc6678..432527d3ab1 100644--- a/zerver/views/custom_profile_fields.py+++ b/zerver/views/custom_profile_fields.py@@ -52,7 +52,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.SELECT:+ if field_type == CustomProfileField.DROPDOWN:# Choice type field must have at least have one choiceif 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.pyindex 9f62ecbcc22..a41ebf3f3b4 100644--- a/zilencer/management/commands/populate_db.py+++ b/zilencer/management/commands/populate_db.py@@ -797,7 +797,7 @@ class Command(ZulipBaseCommand):biography = try_add_realm_custom_profile_field(zulip_realm,"Biography",- CustomProfileField.LONG_TEXT,+ CustomProfileField.PARAGRAPH,hint="What are you known for?",)favorite_food = try_add_realm_custom_profile_field(@@ -811,7 +811,7 @@ class Command(ZulipBaseCommand):"1": {"text": "Emacs", "order": "2"},}favorite_editor = try_add_realm_custom_profile_field(- zulip_realm, "Favorite editor", CustomProfileField.SELECT, field_data=field_data+ zulip_realm, "Favorite editor", CustomProfileField.DROPDOWN, field_data=field_data)birthday = try_add_realm_custom_profile_field(zulip_realm, "Birthday", CustomProfileField.DATEdiff --git a/zproject/backends.py b/zproject/backends.pyindex 3d928fec927..51e6e0f737c 100644--- a/zproject/backends.py+++ b/zproject/backends.py@@ -1781,7 +1781,7 @@ def validate_custom_profile_field_data_for_sync(# a mostly-successful sync instead of failing with an error.text_field_max_length = {CustomProfileField.SHORT_TEXT: SHORT_STRING_MAX_LENGTH,- CustomProfileField.LONG_TEXT: LONG_STRING_MAX_LENGTH,+ CustomProfileField.PARAGRAPH: LONG_STRING_MAX_LENGTH,}.get(field.field_type)if (isinstance(value, str)