mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
rename_stream: Pass a stream object to do_rename_stream.
This commit is contained in:
@@ -2057,23 +2057,15 @@ def do_change_stream_invite_only(stream, invite_only):
|
||||
stream.invite_only = invite_only
|
||||
stream.save(update_fields=['invite_only'])
|
||||
|
||||
def do_rename_stream(realm, old_name, new_name, log=True):
|
||||
# type: (Realm, Text, Text, bool) -> Dict[str, Text]
|
||||
old_name = old_name
|
||||
new_name = new_name
|
||||
|
||||
stream = get_stream(old_name, realm)
|
||||
|
||||
if not stream:
|
||||
raise JsonableError(_('Unknown stream "%s"') % (old_name,))
|
||||
|
||||
def do_rename_stream(stream, new_name, log=True):
|
||||
# type: (Stream, Text, bool) -> Dict[str, Text]
|
||||
old_name = stream.name
|
||||
stream.name = new_name
|
||||
stream.save(update_fields=["name"])
|
||||
|
||||
if log:
|
||||
log_event({'type': 'stream_name_change',
|
||||
'domain': realm.domain,
|
||||
'domain': stream.realm.domain,
|
||||
'new_name': new_name})
|
||||
|
||||
recipient = get_recipient(Recipient.STREAM, stream.id)
|
||||
@@ -2081,8 +2073,8 @@ def do_rename_stream(realm, old_name, new_name, log=True):
|
||||
|
||||
# Update the display recipient and stream, which are easy single
|
||||
# items to set.
|
||||
old_cache_key = get_stream_cache_key(old_name, realm)
|
||||
new_cache_key = get_stream_cache_key(stream.name, realm)
|
||||
old_cache_key = get_stream_cache_key(old_name, stream.realm)
|
||||
new_cache_key = get_stream_cache_key(stream.name, stream.realm)
|
||||
if old_cache_key != new_cache_key:
|
||||
cache_delete(old_cache_key)
|
||||
cache_set(new_cache_key, stream)
|
||||
|
||||
@@ -8,7 +8,7 @@ from django.core.management.base import BaseCommand
|
||||
|
||||
from zerver.lib.actions import do_rename_stream
|
||||
from zerver.lib.str_utils import force_text
|
||||
from zerver.models import Realm, get_realm
|
||||
from zerver.models import Realm, get_realm, get_stream
|
||||
|
||||
import sys
|
||||
|
||||
@@ -36,5 +36,5 @@ class Command(BaseCommand):
|
||||
print("Unknown subdomain or string_id %s" % (string_id,))
|
||||
exit(1)
|
||||
|
||||
do_rename_stream(realm, force_text(old_name, encoding),
|
||||
force_text(new_name, encoding))
|
||||
stream = get_stream(force_text(old_name, encoding), realm)
|
||||
do_rename_stream(stream, force_text(new_name, encoding))
|
||||
|
||||
@@ -916,12 +916,11 @@ class EventsRegisterTest(ZulipTestCase):
|
||||
|
||||
def test_rename_stream(self):
|
||||
# type: () -> None
|
||||
realm = get_realm('zulip')
|
||||
stream = self.make_stream('old_name')
|
||||
new_name = u'stream with a brand new name'
|
||||
self.subscribe_to_stream(self.user_profile.email, stream.name)
|
||||
|
||||
action = lambda: do_rename_stream(realm, stream.name, new_name)
|
||||
action = lambda: do_rename_stream(stream, new_name)
|
||||
events = self.do_test(action)
|
||||
|
||||
schema_checker = check_dict([
|
||||
|
||||
@@ -102,7 +102,7 @@ def update_stream_backend(request, user_profile, stream_id,
|
||||
return json_error(_("Stream already has that name!"))
|
||||
if get_stream(new_name, user_profile.realm) is not None:
|
||||
raise JsonableError(_('Stream name "%s" is already taken') % (new_name,))
|
||||
do_rename_stream(user_profile.realm, stream.name, new_name)
|
||||
do_rename_stream(stream, new_name)
|
||||
if is_private is not None:
|
||||
do_change_stream_invite_only(stream, is_private)
|
||||
return json_success()
|
||||
|
||||
Reference in New Issue
Block a user