mirror of https://github.com/zulip/zulip.git
profile: Send operation in the event.
This allows us to show a useful message in the handler when the event is received.
This commit is contained in:
parent
d8cfb499c0
commit
f6fb88549f
|
@ -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:
|
||||
|
|
|
@ -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])
|
||||
|
|
Loading…
Reference in New Issue