[Patchew-devel] [PATCH 4/6] search: pass user to search
Paolo Bonzini
pbonzini at redhat.com
Thu Aug 23 20:00:53 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 | 10 +++++-----
api/views.py | 4 ++--
mods/testing.py | 2 +-
www/views.py | 2 +-
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/api/rest.py b/api/rest.py
index 9c2497b..6c10edb 100644
--- a/api/rest.py
+++ b/api/rest.py
@@ -322,7 +322,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 7e11da4..aa77f22 100644
--- a/api/search.py
+++ b/api/search.py
@@ -202,7 +202,7 @@ Search text keyword in the email message. Example:
def _make_filter_result(self, term, **kwargs):
return Q(results__name=term, **kwargs) | Q(results__name__startswith=term+'.', **kwargs)
- 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)
@@ -248,7 +248,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, query, term, neg=False):
+ def _process_term(self, query, term, user, neg=False):
""" Return a Q object that will be applied to the query """
is_plusminus = False
if term[0] in "+-!":
@@ -259,7 +259,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 query.exclude(pk__in=query.filter(q))
else:
@@ -271,11 +271,11 @@ 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()
if queryset is None:
queryset = Message.objects.series_heads()
for t in terms:
- queryset = self._process_term(queryset, t)
+ queryset = self._process_term(queryset, t, user)
return queryset
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 ecd63d1..16b5c59 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -508,6 +508,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