diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index ce58446d83..193ad000b9 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -4507,16 +4507,17 @@ def check_attachment_reference_change(prev_content: Text, message: Message) -> N if len(to_add) > 0: do_claim_attachments(message) -def notify_realm_custom_profile_fields(realm: Realm) -> None: +def notify_realm_custom_profile_fields(realm: Realm, operation: str) -> 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]) send_event(event, active_user_ids(realm.id)) def try_add_realm_custom_profile_field(realm: Realm, name: Text, field_type: int) -> CustomProfileField: field = CustomProfileField(realm=realm, name=name, field_type=field_type) field.save() - notify_realm_custom_profile_fields(realm) + notify_realm_custom_profile_fields(realm, 'add') return field def do_remove_realm_custom_profile_field(realm: Realm, field: CustomProfileField) -> None: @@ -4525,13 +4526,13 @@ 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) + notify_realm_custom_profile_fields(realm, 'delete') def try_update_realm_custom_profile_field(realm: Realm, field: CustomProfileField, name: Text) -> None: field.name = name field.save(update_fields=['name']) - notify_realm_custom_profile_fields(realm) + notify_realm_custom_profile_fields(realm, 'update') def do_update_user_custom_profile_data(user_profile: UserProfile, data: List[Dict[str, Union[int, Text]]]) -> None: diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 48f553ea61..9f20ecb91e 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -910,6 +910,7 @@ class EventsRegisterTest(ZulipTestCase): def test_custom_profile_fields_events(self) -> None: schema_checker = self.check_events_dict([ ('type', equals('custom_profile_fields')), + ('op', equals('add')), ('fields', check_list(check_dict_only([ ('id', check_int), ('type', check_int), @@ -919,7 +920,7 @@ class EventsRegisterTest(ZulipTestCase): events = self.do_test( lambda: notify_realm_custom_profile_fields( - self.user_profile.realm), + self.user_profile.realm, 'add'), state_change_expected=False, ) error = schema_checker('events[0]', events[0])