From 7f4c7962499ac3a2c0fc17b15e093f4eb5bb54e4 Mon Sep 17 00:00:00 2001 From: Jean-Roman Garnier Date: Fri, 6 Dec 2019 13:24:09 +0000 Subject: [PATCH] Tweak filtering for users and clubs in search to better handle user-defined filters --- search/views.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/search/views.py b/search/views.py index d6f7feeb..c95d131f 100644 --- a/search/views.py +++ b/search/views.py @@ -5,6 +5,7 @@ # Copyright © 2017 Gabriel Détraz # Copyright © 2017 Lara Kermarec # Copyright © 2017 Augustin Lemesle +# Copyright © 2019 Jean-Romain Garnier # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -109,17 +110,22 @@ def search_single_word(word, filters, user, start, end, user_state, aff): # Users if "0" in aff: - filter_users = ( + filter_clubs = ( Q(surname__icontains=word) | Q(pseudo__icontains=word) | Q(room__name__icontains=word) | Q(email__icontains=word) | Q(telephone__icontains=word) - ) & Q(state__in=user_state) + ) + filter_users = (filter_clubs | Q(name__icontains=word)) + if not User.can_view_all(user)[0]: + filter_clubs &= Q(id=user.id) filter_users &= Q(id=user.id) - filter_clubs = filter_users - filter_users |= Q(name__icontains=word) + + filter_clubs &= Q(state__in=user_state) + filter_users &= Q(state__in=user_state) + filters["users"] |= filter_users filters["clubs"] |= filter_clubs