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_field: Add "Pronouns" custom field type.

Sahil Batra2bf70fe4dbe8
diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md
index fec5904a2c4..2e0e1100b7b 100644
--- a/templates/zerver/api/changelog.md
+++ b/templates/zerver/api/changelog.md
@@ -20,6 +20,13 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 6.0
+**Feature level 151**
+
+* [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events),
+ [`POST /realm/profile_fields`](/api/create-custom-profile-field),
+ [`GET /realm/profile_fields`](/api/get-custom-profile-fields): Added
+ pronouns custom profile field type.
+
**Feature level 150**
* [`GET /events`](/api/get-events): Separate events are now sent on changing
diff --git a/version.py b/version.py
index d5258c1bafb..a71df0414a1 100644
--- a/version.py
+++ b/version.py
@@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.4.3"
# Changes should be accompanied by documentation explaining what the
# new level means in templates/zerver/api/changelog.md, as well as
# "**Changes**" entries in the endpoint's documentation in `zulip.yaml`.
-API_FEATURE_LEVEL = 150
+API_FEATURE_LEVEL = 151
# Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump
diff --git a/zerver/migrations/0417_alter_customprofilefield_field_type.py b/zerver/migrations/0417_alter_customprofilefield_field_type.py
new file mode 100644
index 00000000000..8a411713783
--- /dev/null
+++ b/zerver/migrations/0417_alter_customprofilefield_field_type.py
@@ -0,0 +1,30 @@
+# Generated by Django 4.0.7 on 2022-10-04 13:59
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("zerver", "0416_set_default_emoji_style"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="customprofilefield",
+ name="field_type",
+ field=models.PositiveSmallIntegerField(
+ choices=[
+ (1, "Short text"),
+ (2, "Long text"),
+ (4, "Date picker"),
+ (5, "Link"),
+ (7, "External account"),
+ (8, "Pronouns"),
+ (3, "List of options"),
+ (6, "Person picker"),
+ ],
+ default=1,
+ ),
+ ),
+ ]
diff --git a/zerver/models.py b/zerver/models.py
index 686e0b85234..6f044e242ed 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -4479,6 +4479,7 @@ class CustomProfileField(models.Model):
URL = 5
USER = 6
EXTERNAL_ACCOUNT = 7
+ PRONOUNS = 8
# These are the fields whose validators require more than var_name
# and value argument. i.e. SELECT require field_data, USER require
@@ -4510,6 +4511,7 @@ class CustomProfileField(models.Model):
str,
"EXTERNAL_ACCOUNT",
),
+ (PRONOUNS, gettext_lazy("Pronouns"), check_short_string, str, "PRONOUNS"),
]
ALL_FIELD_TYPES = [*FIELD_TYPE_DATA, *SELECT_FIELD_TYPE_DATA, *USER_FIELD_TYPE_DATA]
diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.py
index 90ab39f53cb..681824409c4 100644
--- a/zerver/openapi/python_examples.py
+++ b/zerver/openapi/python_examples.py
@@ -417,7 +417,7 @@ def get_realm_profile_fields(client: Client) -> None:
def reorder_realm_profile_fields(client: Client) -> None:
# {code_example|start}
# Reorder the custom profile fields in the user's organization.
- order = [8, 7, 6, 5, 4, 3, 2, 1]
+ order = [9, 8, 7, 6, 5, 4, 3, 2, 1]
request = {"order": json.dumps(order)}
result = client.call_endpoint(url="/realm/profile_fields", method="PATCH", request=request)
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index f9e8c984e95..933ee7ef803 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -8301,6 +8301,13 @@ paths:
"field_data": '{"subtype":"github"}',
"order": 8,
},
+ {
+ "id": 9,
+ "name": "Pronouns",
+ "type": 8,
+ "hint": "What pronouns should people use to refer to you?",
+ "order": 9,
+ },
],
}
patch:
@@ -8328,7 +8335,7 @@ paths:
type: array
items:
type: integer
- example: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
+ example: [11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
required: true
responses:
"200":
@@ -8372,6 +8379,9 @@ paths:
- **5**: Link
- **6**: Person picker
- **7**: External account
+ - **8**: Pronouns
+
+ **Changes**: Field type `8` added in Zulip 6.0 (feature level 151).
schema:
type: integer
example: 3
@@ -9787,6 +9797,9 @@ paths:
- `URL` for links.
- `EXTERNAL_ACCOUNT` for external accounts.
- `USER` for selecting a user for the field.
+ - `PRONOUNS` for a short text field with convenient typeahead for one's preferred pronouns.
+
+ **Changes**: `PRONOUNS` type added in Zulip 6.0 (feature level 151).
additionalProperties: false
properties:
id:
@@ -15484,6 +15497,9 @@ components:
- **5**: Link
- **6**: Person picker
- **7**: External account
+ - **8**: Pronouns
+
+ **Changes**: Field type `8` added in Zulip 6.0 (feature level 151).
order:
type: integer
description: |
diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.py
index ab38708f79e..5762f9d48ea 100644
--- a/zerver/tests/test_custom_profile_data.py
+++ b/zerver/tests/test_custom_profile_data.py
@@ -366,6 +366,16 @@ class CreateCustomProfileFieldTest(CustomProfileFieldTestCase):
result = self.client_post("/json/realm/profile_fields", info=data)
self.assert_json_success(result)
+ def test_create_field_of_type_pronouns(self) -> None:
+ self.login("iago")
+ data = {
+ "name": "Pronouns for you",
+ "hint": "What pronouns should people use to refer to you?",
+ "field_type": CustomProfileField.PRONOUNS,
+ }
+ result = self.client_post("/json/realm/profile_fields", info=data)
+ self.assert_json_success(result)
+
def test_not_realm_admin(self) -> None:
self.login("hamlet")
result = self.client_post("/json/realm/profile_fields")
@@ -657,6 +667,7 @@ class UpdateCustomProfileFieldTest(CustomProfileFieldTestCase):
("Favorite website", "https://zulip.com"),
("Mentor", [self.example_user("cordelia").id]),
("GitHub username", "zulip-mobile"),
+ ("Pronouns", "he/him"),
]
data: List[ProfileDataElementUpdateDict] = []
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index 5dda4447318..9c91435ef5c 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -614,6 +614,7 @@ class PermissionTest(ZulipTestCase):
"Favorite website": "https://zulip.com",
"Mentor": [cordelia.id],
"GitHub username": "timabbott",
+ "Pronouns": "she/her",
}
for field_name in fields:
@@ -722,6 +723,7 @@ class PermissionTest(ZulipTestCase):
"Favorite website": "https://zulip.github.io",
"Mentor": [hamlet.id],
"GitHub username": "timabbott",
+ "Pronouns": None,
}
new_profile_data = []
for field_name in fields:
diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py
index 5cd221d0625..d5d10eb962c 100644
--- a/zilencer/management/commands/populate_db.py
+++ b/zilencer/management/commands/populate_db.py
@@ -725,6 +725,12 @@ class Command(BaseCommand):
zulip_realm, "Mentor", CustomProfileField.USER
)
github_profile = try_add_realm_default_custom_profile_field(zulip_realm, "github")
+ pronouns = try_add_realm_custom_profile_field(
+ zulip_realm,
+ "Pronouns",
+ CustomProfileField.PRONOUNS,
+ hint="What pronouns should people use to refer to you?",
+ )
# Fill in values for Iago and Hamlet
hamlet = get_user_by_delivery_email("[email protected]", zulip_realm)
@@ -739,6 +745,7 @@ class Command(BaseCommand):
{"id": favorite_website.id, "value": "https://zulip.readthedocs.io/en/latest/"},
{"id": mentor.id, "value": [hamlet.id]},
{"id": github_profile.id, "value": "zulip"},
+ {"id": pronouns.id, "value": "he/him"},
],
)
do_update_user_custom_profile_data_if_changed(
@@ -755,6 +762,7 @@ class Command(BaseCommand):
{"id": favorite_website.id, "value": "https://blog.zulig.org"},
{"id": mentor.id, "value": [iago.id]},
{"id": github_profile.id, "value": "zulipbot"},
+ {"id": pronouns.id, "value": "he/him"},
],
)
else: