mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
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:
@@ -4507,16 +4507,17 @@ def check_attachment_reference_change(prev_content: Text, message: Message) -> N
|
|||||||
if len(to_add) > 0:
|
if len(to_add) > 0:
|
||||||
do_claim_attachments(message)
|
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)
|
fields = custom_profile_fields_for_realm(realm.id)
|
||||||
event = dict(type="custom_profile_fields",
|
event = dict(type="custom_profile_fields",
|
||||||
|
op=operation,
|
||||||
fields=[f.as_dict() for f in fields])
|
fields=[f.as_dict() for f in fields])
|
||||||
send_event(event, active_user_ids(realm.id))
|
send_event(event, active_user_ids(realm.id))
|
||||||
|
|
||||||
def try_add_realm_custom_profile_field(realm: Realm, name: Text, field_type: int) -> CustomProfileField:
|
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 = CustomProfileField(realm=realm, name=name, field_type=field_type)
|
||||||
field.save()
|
field.save()
|
||||||
notify_realm_custom_profile_fields(realm)
|
notify_realm_custom_profile_fields(realm, 'add')
|
||||||
return field
|
return field
|
||||||
|
|
||||||
def do_remove_realm_custom_profile_field(realm: Realm, field: CustomProfileField) -> None:
|
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.
|
associated with it in CustomProfileFieldValue model.
|
||||||
"""
|
"""
|
||||||
field.delete()
|
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,
|
def try_update_realm_custom_profile_field(realm: Realm, field: CustomProfileField,
|
||||||
name: Text) -> None:
|
name: Text) -> None:
|
||||||
field.name = name
|
field.name = name
|
||||||
field.save(update_fields=['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,
|
def do_update_user_custom_profile_data(user_profile: UserProfile,
|
||||||
data: List[Dict[str, Union[int, Text]]]) -> None:
|
data: List[Dict[str, Union[int, Text]]]) -> None:
|
||||||
|
|||||||
@@ -910,6 +910,7 @@ class EventsRegisterTest(ZulipTestCase):
|
|||||||
def test_custom_profile_fields_events(self) -> None:
|
def test_custom_profile_fields_events(self) -> None:
|
||||||
schema_checker = self.check_events_dict([
|
schema_checker = self.check_events_dict([
|
||||||
('type', equals('custom_profile_fields')),
|
('type', equals('custom_profile_fields')),
|
||||||
|
('op', equals('add')),
|
||||||
('fields', check_list(check_dict_only([
|
('fields', check_list(check_dict_only([
|
||||||
('id', check_int),
|
('id', check_int),
|
||||||
('type', check_int),
|
('type', check_int),
|
||||||
@@ -919,7 +920,7 @@ class EventsRegisterTest(ZulipTestCase):
|
|||||||
|
|
||||||
events = self.do_test(
|
events = self.do_test(
|
||||||
lambda: notify_realm_custom_profile_fields(
|
lambda: notify_realm_custom_profile_fields(
|
||||||
self.user_profile.realm),
|
self.user_profile.realm, 'add'),
|
||||||
state_change_expected=False,
|
state_change_expected=False,
|
||||||
)
|
)
|
||||||
error = schema_checker('events[0]', events[0])
|
error = schema_checker('events[0]', events[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user