Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
spectators: Rename is_web_public_compatible functions.
Aman Agrawal34a37f55d6ee
diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.jsindex 7845621e6c0..00ef2592da1 100644--- a/frontend_tests/node_tests/filter.js+++ b/frontend_tests/node_tests/filter.js@@ -1615,38 +1615,36 @@ test("error_cases", ({override}) => {assert.ok(!predicate({type: "private"}));});-run_test("is_web_public_compatible", () => {- // tests same as test_is_web_public_compatible from test_message_fetch.py- assert.ok(Filter.is_web_public_compatible([]));- assert.ok(Filter.is_web_public_compatible([{operator: "has", operand: "attachment"}]));- assert.ok(Filter.is_web_public_compatible([{operator: "has", operand: "image"}]));- assert.ok(Filter.is_web_public_compatible([{operator: "search", operand: "magic"}]));- assert.ok(Filter.is_web_public_compatible([{operator: "near", operand: "15"}]));+run_test("is_spectator_compatible", () => {+ // tests same as test_is_spectator_compatible from test_message_fetch.py+ assert.ok(Filter.is_spectator_compatible([]));+ assert.ok(Filter.is_spectator_compatible([{operator: "has", operand: "attachment"}]));+ assert.ok(Filter.is_spectator_compatible([{operator: "has", operand: "image"}]));+ assert.ok(Filter.is_spectator_compatible([{operator: "search", operand: "magic"}]));+ assert.ok(Filter.is_spectator_compatible([{operator: "near", operand: "15"}]));assert.ok(- Filter.is_web_public_compatible([+ Filter.is_spectator_compatible([{operator: "id", operand: "15"},{operator: "has", operand: "attachment"},]),);- assert.ok(Filter.is_web_public_compatible([{operator: "sender", operand: "[email protected]"}]));+ assert.ok(Filter.is_spectator_compatible([{operator: "sender", operand: "[email protected]"}]));assert.ok(- !Filter.is_web_public_compatible([{operator: "pm-with", operand: "[email protected]"}]),+ !Filter.is_spectator_compatible([{operator: "pm-with", operand: "[email protected]"}]),);assert.ok(- !Filter.is_web_public_compatible([- {operator: "group-pm-with", operand: "[email protected]"},- ]),+ !Filter.is_spectator_compatible([{operator: "group-pm-with", operand: "[email protected]"}]),);- assert.ok(Filter.is_web_public_compatible([{operator: "stream", operand: "Denmark"}]));+ assert.ok(Filter.is_spectator_compatible([{operator: "stream", operand: "Denmark"}]));assert.ok(- Filter.is_web_public_compatible([+ Filter.is_spectator_compatible([{operator: "stream", operand: "Denmark"},{operator: "topic", operand: "logic"},]),);- assert.ok(!Filter.is_web_public_compatible([{operator: "is", operand: "starred"}]));- assert.ok(!Filter.is_web_public_compatible([{operator: "is", operand: "private"}]));- assert.ok(Filter.is_web_public_compatible([{operator: "streams", operand: "public"}]));+ assert.ok(!Filter.is_spectator_compatible([{operator: "is", operand: "starred"}]));+ assert.ok(!Filter.is_spectator_compatible([{operator: "is", operand: "private"}]));+ assert.ok(Filter.is_spectator_compatible([{operator: "streams", operand: "public"}]));// Malformed input not allowed- assert.ok(!Filter.is_web_public_compatible([{operator: "has"}]));+ assert.ok(!Filter.is_spectator_compatible([{operator: "has"}]));});diff --git a/static/js/browser_history.js b/static/js/browser_history.jsindex 0e925e5def2..654c80825a3 100644--- a/static/js/browser_history.js+++ b/static/js/browser_history.js@@ -11,7 +11,7 @@ export const state = {// so that we can take user back to the allowed hash.// TODO: Store #narrow old hashes. Currently they are not stored here since, the #narrow// hashes are changed without calling `hashchanged` in many ways.- spectator_old_hash: hash_util.is_web_public_compatible(window.location.hash)+ spectator_old_hash: hash_util.is_spectator_compatible(window.location.hash)? window.location.hash: "#",};diff --git a/static/js/filter.js b/static/js/filter.jsindex 97405ccdf1b..08b97e15ae7 100644--- a/static/js/filter.js+++ b/static/js/filter.js@@ -1007,7 +1007,7 @@ export class Filter {return Handlebars.Utils.escapeExpression(Filter.describe_unescaped(operators));}- static is_web_public_compatible(ops) {+ static is_spectator_compatible(ops) {for (const op of ops) {if (op.operand === undefined) {return false;diff --git a/static/js/hash_util.js b/static/js/hash_util.jsindex cf550c64467..6b99cc524f8 100644--- a/static/js/hash_util.js+++ b/static/js/hash_util.js@@ -282,12 +282,12 @@ export const allowed_web_public_narrows = ["id",];-export function is_web_public_compatible(hash) {+export function is_spectator_compatible(hash) {// Defines which views are supported for spectators.// This implementation should agree with the similar function in zerver/lib/narrow.py.const web_public_allowed_hashes = ["",- "narrow", // full #narrow hash handled in narrow.is_web_public_compatible+ "narrow", // full #narrow hash handled in narrow.is_spectator_compatible"recent_topics","keyboard-shortcuts","message-formatting",diff --git a/static/js/hashchange.js b/static/js/hashchange.jsindex 239ff37dcf1..cf505b29422 100644--- a/static/js/hashchange.js+++ b/static/js/hashchange.js@@ -318,7 +318,7 @@ function hashchanged(from_reload, e) {const was_internal_change = browser_history.save_old_hash();- const is_hash_web_public_compatible = hash_util.is_web_public_compatible(current_hash);+ const is_hash_web_public_compatible = hash_util.is_spectator_compatible(current_hash);if (is_hash_web_public_compatible) {browser_history.state.spectator_old_hash = current_hash;}diff --git a/zerver/lib/narrow.py b/zerver/lib/narrow.pyindex 6cbe5b5e404..442babc1493 100644--- a/zerver/lib/narrow.py+++ b/zerver/lib/narrow.py@@ -29,7 +29,7 @@ def check_supported_events_narrow_filter(narrow: Iterable[Sequence[str]]) -> Nonraise JsonableError(_("Operator {} not supported.").format(operator))-def is_web_public_compatible(narrow: Iterable[Dict[str, Any]]) -> bool:+def is_spectator_compatible(narrow: Iterable[Dict[str, Any]]) -> bool:# This implementation should agree with the similar function in static/js/hash_utl.js.for element in narrow:operator = element["operator"]diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.pyindex 1df155b2901..1fad464a5d4 100644--- a/zerver/tests/test_message_fetch.py+++ b/zerver/tests/test_message_fetch.py@@ -29,7 +29,7 @@ from zerver.lib.message import (render_markdown,update_first_visible_message_id,)-from zerver.lib.narrow import build_narrow_filter, is_web_public_compatible+from zerver.lib.narrow import build_narrow_filter, is_spectator_compatiblefrom zerver.lib.sqlalchemy_utils import get_sqlalchemy_connectionfrom zerver.lib.streams import StreamDict, create_streams_if_needed, get_public_streams_querysetfrom zerver.lib.test_classes import ZulipTestCase@@ -550,40 +550,40 @@ class NarrowLibraryTest(ZulipTestCase):with self.assertRaises(JsonableError):build_narrow_filter(["invalid_operator", "operand"])- def test_is_web_public_compatible(self) -> None:- self.assertTrue(is_web_public_compatible([]))- self.assertTrue(is_web_public_compatible([{"operator": "has", "operand": "attachment"}]))- self.assertTrue(is_web_public_compatible([{"operator": "has", "operand": "image"}]))- self.assertTrue(is_web_public_compatible([{"operator": "search", "operand": "magic"}]))- self.assertTrue(is_web_public_compatible([{"operator": "near", "operand": "15"}]))+ def test_is_spectator_compatible(self) -> None:+ self.assertTrue(is_spectator_compatible([]))+ self.assertTrue(is_spectator_compatible([{"operator": "has", "operand": "attachment"}]))+ self.assertTrue(is_spectator_compatible([{"operator": "has", "operand": "image"}]))+ self.assertTrue(is_spectator_compatible([{"operator": "search", "operand": "magic"}]))+ self.assertTrue(is_spectator_compatible([{"operator": "near", "operand": "15"}]))self.assertTrue(- is_web_public_compatible(+ is_spectator_compatible([{"operator": "id", "operand": "15"}, {"operator": "has", "operand": "attachment"}]))self.assertTrue(- is_web_public_compatible([{"operator": "sender", "operand": "[email protected]"}])+ is_spectator_compatible([{"operator": "sender", "operand": "[email protected]"}]))self.assertFalse(- is_web_public_compatible([{"operator": "pm-with", "operand": "[email protected]"}])+ is_spectator_compatible([{"operator": "pm-with", "operand": "[email protected]"}]))self.assertFalse(- is_web_public_compatible([{"operator": "group-pm-with", "operand": "[email protected]"}])+ is_spectator_compatible([{"operator": "group-pm-with", "operand": "[email protected]"}]))- self.assertTrue(is_web_public_compatible([{"operator": "stream", "operand": "Denmark"}]))+ self.assertTrue(is_spectator_compatible([{"operator": "stream", "operand": "Denmark"}]))self.assertTrue(- is_web_public_compatible(+ is_spectator_compatible([{"operator": "stream", "operand": "Denmark"},{"operator": "topic", "operand": "logic"},]))- self.assertFalse(is_web_public_compatible([{"operator": "is", "operand": "starred"}]))- self.assertFalse(is_web_public_compatible([{"operator": "is", "operand": "private"}]))- self.assertTrue(is_web_public_compatible([{"operator": "streams", "operand": "public"}]))+ self.assertFalse(is_spectator_compatible([{"operator": "is", "operand": "starred"}]))+ self.assertFalse(is_spectator_compatible([{"operator": "is", "operand": "private"}]))+ self.assertTrue(is_spectator_compatible([{"operator": "streams", "operand": "public"}]))# Malformed input not allowed- self.assertFalse(is_web_public_compatible([{"operator": "has"}]))+ self.assertFalse(is_spectator_compatible([{"operator": "has"}]))class IncludeHistoryTest(ZulipTestCase):@@ -1521,7 +1521,7 @@ class GetOldMessagesTest(ZulipTestCase):"anchor": 1,"num_before": 1,"num_after": 1,- # "is:private" is not a is_web_public_compatible narrow.+ # "is:private" is not a is_spectator_compatible narrow."narrow": orjson.dumps([dict(operator="streams", operand="web-public"),diff --git a/zerver/views/message_fetch.py b/zerver/views/message_fetch.pyindex 69c14fb390a..ac4dcefa8a9 100644--- a/zerver/views/message_fetch.py+++ b/zerver/views/message_fetch.py@@ -36,7 +36,7 @@ from zerver.lib.actions import recipient_for_user_profilesfrom zerver.lib.addressee import get_user_profiles, get_user_profiles_by_idsfrom zerver.lib.exceptions import ErrorCode, JsonableError, MissingAuthenticationErrorfrom zerver.lib.message import get_first_visible_message_id, messages_for_ids-from zerver.lib.narrow import is_web_public_compatible, is_web_public_narrow+from zerver.lib.narrow import is_spectator_compatible, is_web_public_narrowfrom zerver.lib.request import REQ, RequestNotes, has_request_variablesfrom zerver.lib.response import json_successfrom zerver.lib.sqlalchemy_utils import get_sqlalchemy_connection@@ -968,7 +968,7 @@ def get_messages_backend(if not is_web_public_narrow(narrow):raise MissingAuthenticationError()assert narrow is not None- if not is_web_public_compatible(narrow):+ if not is_spectator_compatible(narrow):raise MissingAuthenticationError()realm = get_valid_realm_from_request(request)