Skip to content

Commit

Permalink
feat: add username query to filter
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinan029 committed Sep 12, 2024
1 parent 2ac5dae commit 74828a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Unreleased
----------
* nothing unreleased

[4.25.10]
----------
* feat: add username query to enterprise customer user query

[4.25.9]
----------
* fix: send LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED from the correct place.
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.25.9"
__version__ = "4.25.10"
6 changes: 4 additions & 2 deletions enterprise/api/v1/views/enterprise_customer_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def filter_queryset_by_user_query(self, queryset, is_pending_user=False):

if user_query:
if not is_pending_user:
queryset = queryset.filter(
user_id__in=User.objects.filter(Q(email__icontains=user_query))
queryset = models.EnterpriseCustomerUser.objects.filter(
user_id__in=User.objects.filter(
Q(email__icontains=user_query) | Q(username__icontains=user_query)
)
)
else:
queryset = queryset.filter(user_email=user_query)
Expand Down
13 changes: 11 additions & 2 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9725,8 +9725,17 @@ def test_list_users_filtered(self):
'role_assignments': [ENTERPRISE_LEARNER_ROLE],
'is_admin': False
}]
user_query_string = f'?user_query={enterprise_customer_user.user_email}'
url = reverse(self.ECS_ENDPOINT, kwargs={self.ECS_KWARG: enterprise_customer.uuid}) + user_query_string
# search by email
user_query_email = f'?user_query={enterprise_customer_user.user_email}'
url = reverse(self.ECS_ENDPOINT, kwargs={self.ECS_KWARG: enterprise_customer.uuid}) + user_query_email
response = self.client.get(settings.TEST_SERVER + url)

assert expected_json == response.json().get('results')
assert response.json().get('count') == 1

# search by username
user_query_username = f'?user_query={enterprise_customer_user.username}'
url = reverse(self.ECS_ENDPOINT, kwargs={self.ECS_KWARG: enterprise_customer.uuid}) + user_query_username
response = self.client.get(settings.TEST_SERVER + url)

assert expected_json == response.json().get('results')
Expand Down

0 comments on commit 74828a5

Please sign in to comment.