Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_fetch: Allow spectators to access all messages view.
Aman Agrawal5548a2898046
diff --git a/web/src/narrow.js b/web/src/narrow.jsindex cc276672d0b..619c69ef1b0 100644--- a/web/src/narrow.js+++ b/web/src/narrow.js@@ -157,6 +157,8 @@ export function activate(raw_terms, opts) {if (page_params.is_spectator &&raw_terms.length &&+ // Allow spectator to access all messages view.+ !filter.is_in_home() &&raw_terms.some((raw_term) => !hash_parser.allowed_web_public_narrows.includes(raw_term.operator),)diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.pyindex 1dbc333306b..6cd79e49191 100644--- a/zerver/views/message_fetch.py+++ b/zerver/views/message_fetch.py@@ -78,6 +78,20 @@ def get_search_fields(}+def clean_narrow_for_web_public_api(narrow: OptionalNarrowListT) -> OptionalNarrowListT:+ if narrow is None:+ return None++ # Remove {'operator': 'in', 'operand': 'home', 'negated': False} from narrow.+ # This is to allow spectators to access all messages. The narrow should still pass+ # is_web_public_narrow check after this change.+ return [+ term+ for term in narrow+ if not (term["operator"] == "in" and term["operand"] == "home" and not term["negated"])+ ]++@has_request_variablesdef get_messages_backend(request: HttpRequest,@@ -117,6 +131,7 @@ def get_messages_backend(# non-web-public stream messages) via this path.if not realm.allow_web_public_streams_access():raise MissingAuthenticationError+ narrow = clean_narrow_for_web_public_api(narrow)if not is_web_public_narrow(narrow):raise MissingAuthenticationErrorassert narrow is not None