mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
Use "stream" as our type for updates to Stream.name.
(imported from commit 2eedbff5fac77b9e654ba88900167048573e4056)
This commit is contained in:
@@ -884,6 +884,12 @@ function get_updates_success(data) {
|
|||||||
update_person(event.person);
|
update_person(event.person);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'stream':
|
||||||
|
if (event.op === 'update') {
|
||||||
|
// Legacy: Stream properties are still managed by subs.js on the client side.
|
||||||
|
subs.update_subscription_properties(event.name, event.property, event.value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'subscriptions':
|
case 'subscriptions':
|
||||||
if (event.op === 'add') {
|
if (event.op === 'add') {
|
||||||
_.each(event.subscriptions, function (subscription) {
|
_.each(event.subscriptions, function (subscription) {
|
||||||
|
|||||||
@@ -1248,9 +1248,16 @@ def do_rename_stream(realm, old_name, new_name, log=True):
|
|||||||
cache_delete_many(
|
cache_delete_many(
|
||||||
to_dict_cache_key_id(message.id, False) for message in messages)
|
to_dict_cache_key_id(message.id, False) for message in messages)
|
||||||
|
|
||||||
notice = dict(event=dict(type="subscriptions", op="update", property="name",
|
# We will tell our users to essentially
|
||||||
name=old_name, value=new_name),
|
# update stream.name = new_name where name = old_name
|
||||||
users=active_user_ids(realm))
|
event = dict(
|
||||||
|
op="update",
|
||||||
|
type="stream",
|
||||||
|
property="name",
|
||||||
|
value=new_name,
|
||||||
|
name=old_name
|
||||||
|
)
|
||||||
|
notice = dict(event=event, users=active_user_ids(realm))
|
||||||
|
|
||||||
tornado_callbacks.send_notification(notice)
|
tornado_callbacks.send_notification(notice)
|
||||||
|
|
||||||
@@ -1902,7 +1909,13 @@ def apply_events(state, events):
|
|||||||
for p in state['realm_users']:
|
for p in state['realm_users']:
|
||||||
if our_person(p):
|
if our_person(p):
|
||||||
p.update(person)
|
p.update(person)
|
||||||
|
elif event['type'] == 'stream':
|
||||||
|
if event['op'] == 'update':
|
||||||
|
# For legacy reasons, we call stream data 'subscriptions' in
|
||||||
|
# the state var here, for the benefit of the JS code.
|
||||||
|
for obj in state['subscriptions']:
|
||||||
|
if obj['name'].lower() == event['name'].lower():
|
||||||
|
obj[event['property']] = event['value']
|
||||||
elif event['type'] == "subscriptions":
|
elif event['type'] == "subscriptions":
|
||||||
if event['op'] in ["add"]:
|
if event['op'] in ["add"]:
|
||||||
# Convert the user_profile IDs to emails since that's what register() returns
|
# Convert the user_profile IDs to emails since that's what register() returns
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ from zerver.lib.actions import check_send_message, gather_subscriptions, \
|
|||||||
create_stream_if_needed, do_add_subscription, compute_mit_user_fullname, \
|
create_stream_if_needed, do_add_subscription, compute_mit_user_fullname, \
|
||||||
do_add_realm_emoji, do_remove_realm_emoji, check_message, do_create_user, \
|
do_add_realm_emoji, do_remove_realm_emoji, check_message, do_create_user, \
|
||||||
set_default_streams, get_emails_from_user_ids, one_click_unsubscribe_link, \
|
set_default_streams, get_emails_from_user_ids, one_click_unsubscribe_link, \
|
||||||
do_deactivate_user, do_reactivate_user, enqueue_welcome_emails, do_change_is_admin
|
do_deactivate_user, do_reactivate_user, enqueue_welcome_emails, do_change_is_admin, \
|
||||||
|
do_rename_stream
|
||||||
from zerver.lib.rate_limiter import add_ratelimit_rule, remove_ratelimit_rule
|
from zerver.lib.rate_limiter import add_ratelimit_rule, remove_ratelimit_rule
|
||||||
from zerver.lib import bugdown
|
from zerver.lib import bugdown
|
||||||
from zerver.lib import cache
|
from zerver.lib import cache
|
||||||
@@ -602,9 +603,20 @@ class StreamAdminTest(AuthedTestCase):
|
|||||||
do_add_subscription(user_profile, stream, no_log=True)
|
do_add_subscription(user_profile, stream, no_log=True)
|
||||||
do_change_is_admin(user_profile, True)
|
do_change_is_admin(user_profile, True)
|
||||||
|
|
||||||
result = self.client.post('/json/rename_stream?old_name=stream_name1&new_name=stream_name2')
|
events = []
|
||||||
|
with tornado_redirected_to_list(events):
|
||||||
|
result = self.client.post('/json/rename_stream?old_name=stream_name1&new_name=stream_name2')
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
|
event = events[0]['event']
|
||||||
|
self.assertEqual(event, dict(
|
||||||
|
op='update',
|
||||||
|
type='stream',
|
||||||
|
property='name',
|
||||||
|
value='stream_name2',
|
||||||
|
name='stream_name1'
|
||||||
|
))
|
||||||
|
|
||||||
stream_name1_exists = Stream.objects.filter(
|
stream_name1_exists = Stream.objects.filter(
|
||||||
name='stream_name1',
|
name='stream_name1',
|
||||||
realm=realm,
|
realm=realm,
|
||||||
@@ -3600,6 +3612,12 @@ class EventsRegisterTest(AuthedTestCase):
|
|||||||
"https://realm.com/my_realm_filter/%(id)s"))
|
"https://realm.com/my_realm_filter/%(id)s"))
|
||||||
self.do_test(lambda: do_remove_realm_filter(get_realm("zulip.com"), "#[123]"))
|
self.do_test(lambda: do_remove_realm_filter(get_realm("zulip.com"), "#[123]"))
|
||||||
|
|
||||||
|
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'
|
||||||
|
self.do_test(lambda: do_rename_stream(realm, stream.name, new_name))
|
||||||
|
|
||||||
def test_subscribe_events(self):
|
def test_subscribe_events(self):
|
||||||
self.do_test(lambda: self.subscribe_to_stream("hamlet@zulip.com", "test_stream"),
|
self.do_test(lambda: self.subscribe_to_stream("hamlet@zulip.com", "test_stream"),
|
||||||
matcher=lambda a, b: self.match_with_reorder(a, b, "subscriptions"))
|
matcher=lambda a, b: self.match_with_reorder(a, b, "subscriptions"))
|
||||||
|
|||||||
Reference in New Issue
Block a user