Skip to content

Commit

Permalink
feat: if no match for an email exists widen the search (#2821)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
niross authored Oct 30, 2023
1 parent 402e019 commit f07c4e8
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions dataworkspace/dataworkspace/apps/datasets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit f07c4e8

Please sign in to comment.