api: Move notifications_stream into the register_ret API.

While we're at it, we at least fix the API to use a stream ID, not a
stream name, to refer to the notifications stream.
This commit is contained in:
Tim Abbott 2017-05-16 18:48:47 -07:00
parent 8c172063e0
commit cab908b664
4 changed files with 16 additions and 8 deletions

View File

@ -445,6 +445,15 @@ exports.initialize_from_page_params = function () {
populate_subscriptions(page_params.unsubscribed, false);
populate_subscriptions(page_params.never_subscribed, false);
// Migrate the notifications stream from the new API structure to
// what the frontend expects.
if (page_params.realm_notifications_stream_id !== -1) {
page_params.notifications_stream =
exports.get_sub_by_id(page_params.realm_notifications_stream_id).name;
} else {
page_params.notifications_stream = "";
}
// Garbage collect data structures that were only used for initialization.
delete page_params.subscriptions;
delete page_params.unsubscribed;

View File

@ -110,6 +110,11 @@ def fetch_initial_state_data(user_profile, event_types, queue_id,
state['realm_show_digest_email'] = user_profile.realm.show_digest_email
state['realm_is_zephyr_mirror_realm'] = user_profile.realm.is_zephyr_mirror_realm
state['realm_password_auth_enabled'] = password_auth_enabled(user_profile.realm)
if user_profile.realm.notifications_stream and not user_profile.realm.notifications_stream.deactivated:
notifications_stream = user_profile.realm.notifications_stream
state['realm_notifications_stream_id'] = notifications_stream.id
else:
state['realm_notifications_stream_id'] = -1
if want('realm_domains'):
state['realm_domains'] = get_realm_domains(user_profile.realm)

View File

@ -89,7 +89,6 @@ class HomeTest(ZulipTestCase):
"narrow_stream",
"needs_tutorial",
"never_subscribed",
"notifications_stream",
"pm_content_in_desktop_notifications",
"pointer",
"poll_timeout",
@ -121,6 +120,7 @@ class HomeTest(ZulipTestCase):
"realm_message_retention_days",
"realm_name",
"realm_name_changes_disabled",
"realm_notifications_stream_id",
"realm_password_auth_enabled",
"realm_presence_disabled",
"realm_restricted_to_domain",
@ -309,7 +309,7 @@ class HomeTest(ZulipTestCase):
self.login(email)
result = self._get_home_page()
page_params = self._get_page_params(result)
self.assertEqual(page_params['notifications_stream'], 'Denmark')
self.assertEqual(page_params['realm_notifications_stream_id'], get_stream('Denmark', realm).id)
def test_people(self):
# type: () -> None

View File

@ -172,11 +172,6 @@ def home_real(request):
logging.warning("%s has invalid pointer %s" % (user_profile.email, user_profile.pointer))
latest_read = None
if user_profile.realm.notifications_stream:
notifications_stream = user_profile.realm.notifications_stream.name
else:
notifications_stream = ""
# Set default language and make it persist
default_language = register_ret['default_language']
url_lang = '/{}'.format(request.LANGUAGE_CODE)
@ -213,7 +208,6 @@ def home_real(request):
needs_tutorial = needs_tutorial,
first_in_realm = first_in_realm,
prompt_for_invites = prompt_for_invites,
notifications_stream = notifications_stream,
cross_realm_bots = list(get_cross_realm_dicts()),
unread_count = approximate_unread_count(user_profile),
furthest_read_time = sent_time_in_epoch_seconds(latest_read),