diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 08a20de7fd..ddd5dc42ca 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -180,7 +180,7 @@ run_test("user groups", (override) => { }); run_test("custom profile fields", (override) => { - const event = event_fixtures.custom_profile_fields__update; + const event = event_fixtures.custom_profile_fields; override(settings_profile_fields, "populate_profile_fields", noop); override(settings_account, "add_custom_profile_fields_to_settings", noop); dispatch(event); diff --git a/frontend_tests/node_tests/lib/events.js b/frontend_tests/node_tests/lib/events.js index bf31860b78..7045661667 100644 --- a/frontend_tests/node_tests/lib/events.js +++ b/frontend_tests/node_tests/lib/events.js @@ -111,12 +111,11 @@ exports.fixtures = { upload_space_used: 90000, }, - custom_profile_fields__update: { + custom_profile_fields: { type: "custom_profile_fields", - op: "update", fields: [ - {id: 1, name: "teams", type: 1}, - {id: 2, name: "hobbies", type: 1}, + {id: 1, name: "teams", type: 1, hint: "", field_data: "", order: 1}, + {id: 2, name: "hobbies", type: 1, hint: "", field_data: "", order: 2}, ], }, diff --git a/templates/zerver/api/changelog.md b/templates/zerver/api/changelog.md index 600ddd2032..acb8ff3b6a 100644 --- a/templates/zerver/api/changelog.md +++ b/templates/zerver/api/changelog.md @@ -10,6 +10,13 @@ below features are supported. ## Changes in Zulip 4.0 +**Feature level 45** + +* [`GET /events`](/api/get-events): Removed useless `op` field from + `custom_profile_fields` events. These events contain the full set + of configured `custom_profile_fields` for the organization + regardless of what triggered the change. + **Feature level 44** * [`POST /register`](/api/register-queue): extended the `unread_msgs` diff --git a/version.py b/version.py index 272d24c63b..d5a9c2c46b 100644 --- a/version.py +++ b/version.py @@ -30,7 +30,7 @@ DESKTOP_WARNING_VERSION = "5.2.0" # # Changes should be accompanied by documentation explaining what the # new level means in templates/zerver/api/changelog.md. -API_FEATURE_LEVEL = 44 +API_FEATURE_LEVEL = 45 # 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/lib/actions.py b/zerver/lib/actions.py index a73e618063..376a7b35aa 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -6715,9 +6715,9 @@ def check_attachment_reference_change(message: Message) -> bool: return message.attachment_set.exists() -def notify_realm_custom_profile_fields(realm: Realm, operation: str) -> None: +def notify_realm_custom_profile_fields(realm: Realm) -> None: fields = custom_profile_fields_for_realm(realm.id) - event = dict(type="custom_profile_fields", op=operation, fields=[f.as_dict() for f in fields]) + event = dict(type="custom_profile_fields", fields=[f.as_dict() for f in fields]) send_event(realm, event, active_user_ids(realm.id)) @@ -6735,7 +6735,7 @@ def try_add_realm_default_custom_profile_field( field.save() field.order = field.id field.save(update_fields=["order"]) - notify_realm_custom_profile_fields(realm, "add") + notify_realm_custom_profile_fields(realm) return field @@ -6757,7 +6757,7 @@ def try_add_realm_custom_profile_field( field.save() field.order = field.id field.save(update_fields=["order"]) - notify_realm_custom_profile_fields(realm, "add") + notify_realm_custom_profile_fields(realm) return field @@ -6767,7 +6767,7 @@ def do_remove_realm_custom_profile_field(realm: Realm, field: CustomProfileField associated with it in CustomProfileFieldValue model. """ field.delete() - notify_realm_custom_profile_fields(realm, "delete") + notify_realm_custom_profile_fields(realm) def do_remove_realm_custom_profile_fields(realm: Realm) -> None: @@ -6789,7 +6789,7 @@ def try_update_realm_custom_profile_field( ): field.field_data = orjson.dumps(field_data or {}).decode() field.save() - notify_realm_custom_profile_fields(realm, "update") + notify_realm_custom_profile_fields(realm) def try_reorder_realm_custom_profile_fields(realm: Realm, order: List[int]) -> None: @@ -6801,7 +6801,7 @@ def try_reorder_realm_custom_profile_fields(realm: Realm, order: List[int]) -> N for field in fields: field.order = order_mapping[field.id] field.save(update_fields=["order"]) - notify_realm_custom_profile_fields(realm, "update") + notify_realm_custom_profile_fields(realm) def notify_user_update_custom_profile_data( diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py index 3e471aa3b4..35d9ee9f61 100644 --- a/zerver/lib/event_schema.py +++ b/zerver/lib/event_schema.py @@ -184,7 +184,6 @@ custom_profile_field_type = DictType( custom_profile_fields_event = event_dict_type( required_keys=[ ("type", Equals("custom_profile_fields")), - ("op", Equals("add")), ("fields", ListType(custom_profile_field_type)), ] ) diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index db526abaf7..9b71e01efe 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -1390,10 +1390,6 @@ paths: - $ref: "#/components/schemas/EventTypeSchema" - enum: - custom_profile_fields - op: - type: string - enum: - - add fields: type: array description: | @@ -1405,7 +1401,6 @@ paths: example: { "type": "custom_profile_fields", - "op": "add", "fields": [ { diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index e0aad2112f..757776d885 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -65,6 +65,7 @@ from zerver.lib.actions import ( do_remove_default_stream, do_remove_default_stream_group, do_remove_reaction, + do_remove_realm_custom_profile_field, do_remove_realm_domain, do_remove_realm_emoji, do_remove_realm_filter, @@ -92,6 +93,7 @@ from zerver.lib.actions import ( lookup_default_stream_groups, notify_realm_custom_profile_fields, remove_members_from_user_group, + try_add_realm_custom_profile_field, try_update_realm_custom_profile_field, ) from zerver.lib.event_schema import ( @@ -165,6 +167,7 @@ from zerver.lib.test_helpers import ( from zerver.lib.topic import TOPIC_NAME from zerver.models import ( Attachment, + CustomProfileField, Message, MultiuseInvite, PreregistrationUser, @@ -694,20 +697,32 @@ class NormalActionsTest(BaseAction): check_typing_stop("events[0]", events[0]) def test_custom_profile_fields_events(self) -> None: + realm = self.user_profile.realm + try_add_realm_custom_profile_field( + realm=realm, name="Expertise", field_type=CustomProfileField.LONG_TEXT + ) + events = self.verify_action( - lambda: notify_realm_custom_profile_fields(self.user_profile.realm, "add"), + lambda: notify_realm_custom_profile_fields(self.user_profile.realm), state_change_expected=False, ) check_custom_profile_fields("events[0]", events[0]) - realm = self.user_profile.realm field = realm.customprofilefield_set.get(realm=realm, name="Biography") name = field.name hint = "Biography of the user" try_update_realm_custom_profile_field(realm, field, name, hint=hint) events = self.verify_action( - lambda: notify_realm_custom_profile_fields(self.user_profile.realm, "add"), + lambda: notify_realm_custom_profile_fields(self.user_profile.realm), + state_change_expected=False, + ) + check_custom_profile_fields("events[0]", events[0]) + + do_remove_realm_custom_profile_field(realm, field) + + events = self.verify_action( + lambda: notify_realm_custom_profile_fields(self.user_profile.realm), state_change_expected=False, ) check_custom_profile_fields("events[0]", events[0])