From fbb475b16ae1cbb68a17337198b83c28d0338db2 Mon Sep 17 00:00:00 2001 From: m-e-l-u-h-a-n Date: Sat, 14 Jan 2023 11:59:50 +0530 Subject: [PATCH] streams: Fix hash redirect for deleted/invalid stream ids. The logic for hash redirects for stream settings did not check for deleted or non-existent streams. Thus a hash of the form `/#streams/{invalid_stream_id}/*` gave gave a blueslip error. This change fixes that logic to treat such hashes equivalent to streams whose settings cannot be accessed by that user and redirects such invalid hashes to `/#streams/subscribed/`. --- static/js/stream_settings_ui.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/static/js/stream_settings_ui.js b/static/js/stream_settings_ui.js index 56e9924e52..3b6b53212c 100644 --- a/static/js/stream_settings_ui.js +++ b/static/js/stream_settings_ui.js @@ -746,10 +746,16 @@ export function change_state(section) { // if the section is a valid number. if (/\d+/.test(section)) { const stream_id = Number.parseInt(section, 10); - // Guest users can not access unsubscribed streams - // So redirect guest users to 'subscribed' tab - // for any unsubscribed stream settings hash - if (page_params.is_guest && !stream_data.is_subscribed(stream_id)) { + const sub = sub_store.get(stream_id); + // There are a few situations where we can't display stream settings: + // 1. This is a stream that's been archived. (sub=undefined) + // 2. The stream ID is invalid. (sub=undefined) + // 3. The current user is a guest, and was unsubscribed from the stream + // stream in the current session. (In future sessions, the stream will + // not be in sub_store). + // + // In all these cases we redirect the user to 'subscribed' tab. + if (!sub || (page_params.is_guest && !stream_data.is_subscribed(stream_id))) { toggler.goto("subscribed"); } else { show_right_section();