From f07c4e8bf7a514d80f152ad929a01eb852da0fc5 Mon Sep 17 00:00:00 2001 From: Nick Ross Date: Mon, 30 Oct 2023 07:43:00 +0000 Subject: [PATCH] feat: if no match for an email exists widen the search (#2821) This is to work around the fact that users can have either @trade or @businessandtrade emails currently. We are at whim of the SSO service as to which one a user has. This change allows us to search for a @trade user but if no user is found, return an @businessandtrade user --- .../dataworkspace/apps/datasets/views.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/dataworkspace/dataworkspace/apps/datasets/views.py b/dataworkspace/dataworkspace/apps/datasets/views.py index db92137232..db50e02f3e 100644 --- a/dataworkspace/dataworkspace/apps/datasets/views.py +++ b/dataworkspace/dataworkspace/apps/datasets/views.py @@ -1711,21 +1711,18 @@ def get_context_data(self, **kwargs): context["non_matches"] = non_email_matches else: - email_filter = Q(email__icontains=search_query.strip()) - name_filter = Q(first_name__icontains=search_query.strip()) | Q( - last_name__icontains=search_query.strip() + search_query = search_query.strip() + email_filter = Q(email__icontains=search_query) + name_filter = Q(first_name__icontains=search_query) | Q( + last_name__icontains=search_query ) users = get_user_model().objects.filter(Q(email_filter | name_filter)) + if not users.exists() and len(search_query.split("@")) != 1: + users = get_user_model().objects.filter( + email__istartswith=search_query.split("@")[0] + ) context["search_results"] = users context["search_query"] = search_query - try: - search_query = self.request.session.pop( - f"search-query--edit-dataset-permissions--{self.obj.pk}--{self.summary.id}" - if self.summary - else f"search-query--edit-dataset-permissions--{self.obj.pk}" - ) - except KeyError: - search_query = None context["obj"] = self.obj context["obj_edit_url"] = ( reverse("datasets:edit_dataset", args=[self.obj.pk])