mirror of https://github.com/zulip/zulip.git
Fix do_rename_stream to update the stream's email address.
This change also makes it so that the test_rename_stream() test exercises the code path. We need to subscribe the user to the stream in order to generate events. (imported from commit 77f965efbf5a766eb8de23486e303fa135b2e638)
This commit is contained in:
parent
cfb2312cb6
commit
662459b9e1
|
@ -1288,21 +1288,33 @@ def do_rename_stream(realm, old_name, new_name, log=True):
|
|||
to_dict_cache_key_id(message.id, True) for message in messages)
|
||||
cache_delete_many(
|
||||
to_dict_cache_key_id(message.id, False) for message in messages)
|
||||
new_email = encode_email_address(stream)
|
||||
|
||||
# We will tell our users to essentially
|
||||
# update stream.name = new_name where name = old_name
|
||||
event = dict(
|
||||
op="update",
|
||||
type="stream",
|
||||
property="name",
|
||||
value=new_name,
|
||||
name=old_name
|
||||
)
|
||||
send_event(event, stream_user_ids(stream))
|
||||
# and update stream.email = new_email where name = old_name.
|
||||
# We could optimize this by trying to send one message, but the
|
||||
# client code really wants one property update at a time, and
|
||||
# updating stream names is a pretty infrequent operation.
|
||||
# More importantly, we want to key these updates by id, not name,
|
||||
# since id is the immutable primary key, and obviously name is not.
|
||||
data_updates = [
|
||||
['email_address', new_email],
|
||||
['name', new_name],
|
||||
]
|
||||
for property, value in data_updates:
|
||||
event = dict(
|
||||
op="update",
|
||||
type="stream",
|
||||
property=property,
|
||||
value=value,
|
||||
name=old_name
|
||||
)
|
||||
send_event(event, stream_user_ids(stream))
|
||||
|
||||
# Even though the token doesn't change, the web client needs to update the
|
||||
# email forwarding address to display the correctly-escaped new name.
|
||||
return {"email_address": encode_email_address(stream)}
|
||||
return {"email_address": new_email}
|
||||
|
||||
def do_change_stream_description(realm, stream_name, new_description):
|
||||
stream = get_stream(stream_name, realm)
|
||||
|
|
|
@ -237,7 +237,8 @@ class EventsRegisterTest(AuthedTestCase):
|
|||
def test_rename_stream(self):
|
||||
realm = get_realm('zulip.com')
|
||||
stream, _ = create_stream_if_needed(realm, 'old_name')
|
||||
new_name = 'stream with a brand new name'
|
||||
new_name = u'stream with a brand new name'
|
||||
self.subscribe_to_stream(self.user_profile.email, stream.name)
|
||||
self.do_test(lambda: do_rename_stream(realm, stream.name, new_name))
|
||||
|
||||
def test_subscribe_events(self):
|
||||
|
|
|
@ -118,7 +118,7 @@ class StreamAdminTest(AuthedTestCase):
|
|||
result = self.client.post('/json/rename_stream?old_name=stream_name1&new_name=stream_name2')
|
||||
self.assert_json_success(result)
|
||||
|
||||
event = events[0]['event']
|
||||
event = events[1]['event']
|
||||
self.assertEqual(event, dict(
|
||||
op='update',
|
||||
type='stream',
|
||||
|
@ -126,7 +126,7 @@ class StreamAdminTest(AuthedTestCase):
|
|||
value='stream_name2',
|
||||
name='stream_name1'
|
||||
))
|
||||
users = events[0]['users']
|
||||
users = events[1]['users']
|
||||
self.assertEqual(users, [user_profile.id])
|
||||
|
||||
stream_name1_exists = Stream.objects.filter(
|
||||
|
|
Loading…
Reference in New Issue