Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

narrow: Support underscore version of "pm-with" and "group-pm-with".

Lauryn Menard52801f3cd239
diff --git a/zerver/lib/narrow.py b/zerver/lib/narrow.py
index 3d2ffd963a5..2edf9ca8549 100644
--- a/zerver/lib/narrow.py
+++ b/zerver/lib/narrow.py
@@ -269,6 +269,13 @@ class NarrowBuilder:
"search": self.by_search,
"pm-with": self.by_pm_with,
"group-pm-with": self.by_group_pm_with,
+ # TODO/compatibility: Prior to commit a9b3a9c, the server implementation
+ # for documented search operators with dashes, also implicitly supported
+ # clients sending those same operators with underscores. We can remove
+ # support for the below operators when support for the associated dashed
+ # operator is removed.
+ "pm_with": self.by_pm_with,
+ "group_pm_with": self.by_group_pm_with,
}
def add_term(self, query: Select, term: Dict[str, Any]) -> Select:
diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.py
index 2cd9aac904f..d6a69a63618 100644
--- a/zerver/tests/test_message_fetch.py
+++ b/zerver/tests/test_message_fetch.py
@@ -521,6 +521,18 @@ class NarrowBuilderTest(ZulipTestCase):
self.assertRaises(BadNarrowOperatorError, _build_query, term)
+ # Test that the underscore version of "pm-with" works.
+ def test_add_term_using_underscore_version_of_pm_with_operator(self) -> None:
+ term = dict(operator="pm_with", operand=self.hamlet_email)
+ self._do_add_term_test(
+ term, "WHERE sender_id = %(sender_id_1)s AND recipient_id = %(recipient_id_1)s"
+ )
+
+ # Test that the underscore version of "group-pm-with" works.
+ def test_add_term_using_underscore_version_of_group_pm_with_operator(self) -> None:
+ term = dict(operator="group_pm_with", operand=self.othello_email)
+ self._do_add_term_test(term, "WHERE recipient_id IN (__[POSTCOMPILE_recipient_id_1])")
+
def _do_add_term_test(
self, term: Dict[str, Any], where_clause: str, params: Optional[Dict[str, Any]] = None
) -> None: