mirror of https://github.com/zulip/zulip.git
spectators: Rename is_web_public_compatible functions.
This commit is contained in:
parent
f5e4dca8f2
commit
34a37f55d6
|
@ -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: "hamlet@zulip.com"}]));
|
||||
assert.ok(Filter.is_spectator_compatible([{operator: "sender", operand: "hamlet@zulip.com"}]));
|
||||
assert.ok(
|
||||
!Filter.is_web_public_compatible([{operator: "pm-with", operand: "hamlet@zulip.com"}]),
|
||||
!Filter.is_spectator_compatible([{operator: "pm-with", operand: "hamlet@zulip.com"}]),
|
||||
);
|
||||
assert.ok(
|
||||
!Filter.is_web_public_compatible([
|
||||
{operator: "group-pm-with", operand: "hamlet@zulip.com"},
|
||||
]),
|
||||
!Filter.is_spectator_compatible([{operator: "group-pm-with", operand: "hamlet@zulip.com"}]),
|
||||
);
|
||||
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"}]));
|
||||
});
|
||||
|
|
|
@ -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
|
||||
: "#",
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ def check_supported_events_narrow_filter(narrow: Iterable[Sequence[str]]) -> Non
|
|||
raise 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"]
|
||||
|
|
|
@ -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_compatible
|
||||
from zerver.lib.sqlalchemy_utils import get_sqlalchemy_connection
|
||||
from zerver.lib.streams import StreamDict, create_streams_if_needed, get_public_streams_queryset
|
||||
from 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": "hamlet@zulip.com"}])
|
||||
is_spectator_compatible([{"operator": "sender", "operand": "hamlet@zulip.com"}])
|
||||
)
|
||||
self.assertFalse(
|
||||
is_web_public_compatible([{"operator": "pm-with", "operand": "hamlet@zulip.com"}])
|
||||
is_spectator_compatible([{"operator": "pm-with", "operand": "hamlet@zulip.com"}])
|
||||
)
|
||||
self.assertFalse(
|
||||
is_web_public_compatible([{"operator": "group-pm-with", "operand": "hamlet@zulip.com"}])
|
||||
is_spectator_compatible([{"operator": "group-pm-with", "operand": "hamlet@zulip.com"}])
|
||||
)
|
||||
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"),
|
||||
|
|
|
@ -36,7 +36,7 @@ from zerver.lib.actions import recipient_for_user_profiles
|
|||
from zerver.lib.addressee import get_user_profiles, get_user_profiles_by_ids
|
||||
from zerver.lib.exceptions import ErrorCode, JsonableError, MissingAuthenticationError
|
||||
from 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_narrow
|
||||
from zerver.lib.request import REQ, RequestNotes, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from 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)
|
||||
|
|
Loading…
Reference in New Issue