mirror of https://github.com/zulip/zulip.git
actions: Remove deactivated stream from default stream groups.
Stream after deactivation should be removed from all the default stream groups that it belongs to. Fixes #14760.
This commit is contained in:
parent
bbf5a5efed
commit
7cfbf660e6
|
@ -851,6 +851,10 @@ def do_deactivate_stream(stream: Stream, log: bool=True) -> None:
|
|||
if DefaultStream.objects.filter(realm_id=stream.realm_id, stream_id=stream.id).exists():
|
||||
do_remove_default_stream(stream)
|
||||
|
||||
default_stream_groups_for_stream = DefaultStreamGroup.objects.filter(streams__id=stream.id)
|
||||
for group in default_stream_groups_for_stream:
|
||||
do_remove_streams_from_default_stream_group(stream.realm, group, [stream])
|
||||
|
||||
# Remove the old stream information from remote cache.
|
||||
old_cache_key = get_stream_cache_key(old_name, stream.realm_id)
|
||||
cache_delete(old_cache_key)
|
||||
|
|
|
@ -456,6 +456,31 @@ class StreamAdminTest(ZulipTestCase):
|
|||
do_deactivate_stream(stream)
|
||||
self.assertEqual(0, DefaultStream.objects.filter(stream_id=stream.id).count())
|
||||
|
||||
def test_deactivate_stream_removes_stream_from_default_stream_groups(self) -> None:
|
||||
realm = get_realm('zulip')
|
||||
streams_to_keep = []
|
||||
for stream_name in ["stream1", "stream2"]:
|
||||
stream = ensure_stream(realm, stream_name)
|
||||
streams_to_keep.append(stream)
|
||||
|
||||
streams_to_remove = []
|
||||
stream = ensure_stream(realm, "stream3")
|
||||
streams_to_remove.append(stream)
|
||||
|
||||
all_streams = streams_to_keep + streams_to_remove
|
||||
|
||||
def get_streams(group: DefaultStreamGroup) -> List[Stream]:
|
||||
return list(group.streams.all().order_by('name'))
|
||||
|
||||
group_name = "group1"
|
||||
description = "This is group1"
|
||||
do_create_default_stream_group(realm, group_name, description, all_streams)
|
||||
default_stream_groups = get_default_stream_groups(realm)
|
||||
self.assertEqual(get_streams(default_stream_groups[0]), all_streams)
|
||||
|
||||
do_deactivate_stream(streams_to_remove[0])
|
||||
self.assertEqual(get_streams(default_stream_groups[0]), streams_to_keep)
|
||||
|
||||
def test_vacate_private_stream_removes_default_stream(self) -> None:
|
||||
stream = self.make_stream('new_stream', invite_only=True)
|
||||
self.subscribe(self.example_user("hamlet"), stream.name)
|
||||
|
|
Loading…
Reference in New Issue