[Patchew-devel] [PATCH v2 08/10] search: pass user to search

Paolo Bonzini pbonzini at redhat.com
Fri Sep 28 14:45:35 UTC 2018


This will be used to support reviews.

Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
---
 api/rest.py     |  2 +-
 api/search.py   | 11 ++++++-----
 api/views.py    |  4 ++--
 mods/testing.py |  2 +-
 www/views.py    |  2 +-
 5 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/api/rest.py b/api/rest.py
index 9a8ec1e..8789e25 100644
--- a/api/rest.py
+++ b/api/rest.py
@@ -344,7 +344,7 @@ class PatchewSearchFilter(filters.BaseFilterBackend):
         search = request.query_params.get(self.search_param) or ''
         terms = [x.strip() for x in search.split(" ") if x]
         se = SearchEngine()
-        query = se.search_series(queryset=queryset, *terms)
+        query = se.search_series(queryset=queryset, user=request.user, *terms)
         return query
 
     def to_html(self, request, queryset, view):
diff --git a/api/search.py b/api/search.py
index a2644c5..cf3c145 100644
--- a/api/search.py
+++ b/api/search.py
@@ -219,7 +219,7 @@ Search text keyword in the email message. Example:
             return Q(is_merged=True)
         return None
 
-    def _make_filter(self, term):
+    def _make_filter(self, term, user):
         if term.startswith("age:"):
             cond = term[term.find(":") + 1:]
             return self._make_filter_age(cond)
@@ -268,7 +268,7 @@ Search text keyword in the email message. Example:
         # Keyword in subject is the default
         return self._make_filter_keywords(term)
 
-    def _process_term(self, term):
+    def _process_term(self, term, user):
         """ Return a Q object that will be applied to the query """
         is_plusminus = neg = False
         if term[0] in "+-!":
@@ -279,7 +279,7 @@ Search text keyword in the email message. Example:
         if is_plusminus and ":" not in term:
             q = self._make_filter_is(term) or self._make_filter_keywords(term)
         else:
-            q = self._make_filter(term)
+            q = self._make_filter(term, user)
         if neg:
             return ~q
         else:
@@ -291,11 +291,12 @@ Search text keyword in the email message. Example:
     def project(self):
         return next(iter(self._projects)) if len(self._projects) == 1 else None
 
-    def search_series(self, *terms, queryset=None):
+    def search_series(self, *terms, user=None, queryset=None):
         self._last_keywords = []
         self._projects = set()
         q = reduce(lambda x, y: x & y,
-                map(lambda t: self._process_term(t), terms), Q())
+                map(lambda t: self._process_term(t, user), terms),
+                Q())
         if queryset is None:
             queryset = Message.objects.series_heads()
         return queryset.filter(q)
diff --git a/api/views.py b/api/views.py
index f2262b6..32bceab 100644
--- a/api/views.py
+++ b/api/views.py
@@ -185,7 +185,7 @@ class SearchView(APIView):
 
     def handle(self, request, terms, fields=None):
         se = SearchEngine()
-        r = se.search_series(*terms)
+        r = se.search_series(user=request.user, *terms)
         return [prepare_series(request, x, fields) for x in r]
 
 class ImportView(APILoginRequiredView):
@@ -211,7 +211,7 @@ class DeleteView(APILoginRequiredView):
             Message.objects.all().delete()
         else:
             se = SearchEngine()
-            for r in se.search_series(*terms):
+            for r in se.search_series(user=request.user, *terms):
                 Message.objects.delete_subthread(r)
 
 class Logout(APIView):
diff --git a/mods/testing.py b/mods/testing.py
index 58f9de7..2fd7d1e 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -517,6 +517,6 @@ class UntestView(APILoginRequiredView):
 
     def handle(self, request, terms):
         se = SearchEngine()
-        q = se.search_series(*terms)
+        q = se.search_series(user=request.user, *terms)
         for s in q:
             _instance.clear_and_start_testing(s)
diff --git a/www/views.py b/www/views.py
index d7c60dd..1259a8e 100644
--- a/www/views.py
+++ b/www/views.py
@@ -224,7 +224,7 @@ def view_search(request):
     search = request.GET.get("q", "").strip()
     terms = [x.strip() for x in search.split(" ") if x]
     se = SearchEngine()
-    query = se.search_series(*terms)
+    query = se.search_series(user=request.user, *terms)
     return render_series_list_page(request, query, search=search,
                                    project=se.project(),
                                    keywords=se.last_keywords())
-- 
2.17.1





More information about the Patchew-devel mailing list