mirror of https://github.com/zulip/zulip.git
add_default_stream: use access_stream_by_name.
This commit is contained in:
parent
de3f539f58
commit
19eaa92059
|
@ -2382,12 +2382,11 @@ def notify_default_streams(realm):
|
|||
)
|
||||
send_event(event, active_user_ids(realm))
|
||||
|
||||
def do_add_default_stream(realm, stream_name):
|
||||
# type: (Realm, Text) -> None
|
||||
stream, _ = create_stream_if_needed(realm, stream_name)
|
||||
if not DefaultStream.objects.filter(realm=realm, stream=stream).exists():
|
||||
DefaultStream.objects.create(realm=realm, stream=stream)
|
||||
notify_default_streams(realm)
|
||||
def do_add_default_stream(stream):
|
||||
# type: (Stream) -> None
|
||||
if not DefaultStream.objects.filter(realm=stream.realm, stream=stream).exists():
|
||||
DefaultStream.objects.create(realm=stream.realm, stream=stream)
|
||||
notify_default_streams(stream.realm)
|
||||
|
||||
def do_remove_default_stream(realm, stream_name):
|
||||
# type: (Realm, Text) -> None
|
||||
|
|
|
@ -442,7 +442,8 @@ class EventsRegisterTest(ZulipTestCase):
|
|||
]))),
|
||||
])
|
||||
|
||||
events = self.do_test(lambda: do_add_default_stream(self.user_profile.realm, "Scotland"))
|
||||
stream = get_stream("Scotland", self.user_profile.realm)
|
||||
events = self.do_test(lambda: do_add_default_stream(stream))
|
||||
error = default_streams_checker('events[0]', events[0])
|
||||
self.assert_on_error(error)
|
||||
|
||||
|
|
|
@ -704,13 +704,14 @@ class DefaultStreamTest(ZulipTestCase):
|
|||
def test_add_and_remove_default_stream(self):
|
||||
# type: () -> None
|
||||
realm = get_realm("zulip")
|
||||
(stream, _) = create_stream_if_needed(realm, "Added Stream")
|
||||
orig_stream_names = self.get_default_stream_names(realm)
|
||||
do_add_default_stream(realm, 'Added Stream')
|
||||
do_add_default_stream(stream)
|
||||
new_stream_names = self.get_default_stream_names(realm)
|
||||
added_stream_names = new_stream_names - orig_stream_names
|
||||
self.assertEqual(added_stream_names, set(['Added Stream']))
|
||||
# idempotentcy--2nd call to add_default_stream should be a noop
|
||||
do_add_default_stream(realm, 'Added Stream')
|
||||
do_add_default_stream(stream)
|
||||
self.assertEqual(self.get_default_stream_names(realm), new_stream_names)
|
||||
|
||||
# start removing
|
||||
|
@ -726,6 +727,7 @@ class DefaultStreamTest(ZulipTestCase):
|
|||
user_profile = get_user_profile_by_email('hamlet@zulip.com')
|
||||
do_change_is_admin(user_profile, True)
|
||||
stream_name = 'stream ADDED via api'
|
||||
(stream, _) = create_stream_if_needed(user_profile.realm, stream_name)
|
||||
result = self.client_post('/json/default_streams', dict(stream_name=stream_name))
|
||||
self.assert_json_success(result)
|
||||
self.assertTrue(stream_name in self.get_default_stream_names(user_profile.realm))
|
||||
|
|
|
@ -73,7 +73,8 @@ def deactivate_stream_backend(request, user_profile, stream_id):
|
|||
@has_request_variables
|
||||
def add_default_stream(request, user_profile, stream_name=REQ()):
|
||||
# type: (HttpRequest, UserProfile, Text) -> HttpResponse
|
||||
do_add_default_stream(user_profile.realm, stream_name)
|
||||
(stream, recipient, sub) = access_stream_by_name(user_profile, stream_name)
|
||||
do_add_default_stream(stream)
|
||||
return json_success()
|
||||
|
||||
@require_realm_admin
|
||||
|
|
Loading…
Reference in New Issue