user-groups: Send delete user group event.

Fixes #7380
This commit is contained in:
Umair Khan 2017-11-15 12:09:49 +05:00 committed by Tim Abbott
parent cc76f7deac
commit 98be0cc502
3 changed files with 21 additions and 0 deletions

View File

@ -4362,6 +4362,13 @@ def remove_members_from_user_group(user_group, user_profiles):
user_ids = [up.id for up in user_profiles]
do_send_user_group_members_update_event('remove_members', user_group, user_ids)
def do_send_delete_user_group_event(user_group_id: int, realm_id: int) -> None:
event = dict(type="user_group",
op="remove",
group_id=user_group_id)
send_event(event, active_user_ids(realm_id))
def check_delete_user_group(user_group_id: int, realm: Realm) -> None:
user_group = access_user_group_by_id(user_group_id, realm)
user_group.delete()
do_send_delete_user_group_event(user_group_id, realm.id)

View File

@ -571,6 +571,9 @@ def apply_event(state, event, user_profile, client_gravatar, include_subscribers
members = set(user_group['members'])
user_group['members'] = list(members - set(event['user_ids']))
user_group['members'].sort()
elif event['op'] == 'remove':
state['realm_user_groups'] = [ug for ug in state['realm_user_groups']
if ug['id'] != event['group_id']]
else:
raise AssertionError("Unexpected event type %s" % (event['type'],))

View File

@ -80,6 +80,7 @@ from zerver.lib.actions import (
do_update_user_group_description,
bulk_add_members_to_user_group,
remove_members_from_user_group,
check_delete_user_group,
)
from zerver.lib.events import (
apply_events,
@ -1061,6 +1062,16 @@ class EventsRegisterTest(ZulipTestCase):
error = user_group_remove_member_checker('events[0]', events[0])
self.assert_on_error(error)
# Test delete event
user_group_remove_checker = self.check_events_dict([
('type', equals('user_group')),
('op', equals('remove')),
('group_id', check_int),
])
events = self.do_test(lambda: check_delete_user_group(backend.id, backend.realm))
error = user_group_remove_checker('events[0]', events[0])
self.assert_on_error(error)
def test_default_stream_groups_events(self):
# type: () -> None
default_stream_groups_checker = self.check_events_dict([