custom_profile_field: Add "Pronouns" custom field type.

This commit adds "Pronouns" custom profile field type. We also
add "Pronouns" type field in the development environment
This commit is contained in:
Sahil Batra 2022-10-01 15:46:11 +05:30 committed by Tim Abbott
parent ab9c5ae482
commit 2bf70fe4db
9 changed files with 79 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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,
),
),
]

View File

@ -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]

View File

@ -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)

View File

@ -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: |

View File

@ -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] = []

View File

@ -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:

View File

@ -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("hamlet@zulip.com", 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: