parent
22da2d4bbe
commit
6b81e3efd8
@ -70,7 +70,7 @@ class ShareUserAutocomplete(Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
if self.request.user.is_anonymous:
|
||||
return User.objects.none()
|
||||
exclude_user_ids = self.forwarded.get("users", [None])
|
||||
exclude_user_ids = self.forwarded.get("users", [])
|
||||
_exclude = {"id__in": exclude_user_ids}
|
||||
qs = User.objects.all().exclude(
|
||||
**_exclude
|
||||
@ -78,6 +78,7 @@ class ShareUserAutocomplete(Select2QuerySetView):
|
||||
"username"
|
||||
)
|
||||
if self.q:
|
||||
# Due to privacy concerns only a full username match will return the proper user entry
|
||||
qs = qs.filter(
|
||||
username=self.q
|
||||
)
|
||||
|
35
konova/tests/test_autocompletes.py
Normal file
35
konova/tests/test_autocompletes.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 14.12.21
|
||||
|
||||
"""
|
||||
import json
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from konova.tests.test_views import BaseTestCase
|
||||
from django.test.client import Client
|
||||
|
||||
|
||||
class AutocompleteTestCase(BaseTestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
super().setUpTestData()
|
||||
cls.client = Client()
|
||||
|
||||
def test_user_autocomplete(self):
|
||||
self.client.login(username=self.superuser.username, password=self.superuser_pw)
|
||||
user_autocomplete_url = reverse("share-user-autocomplete")
|
||||
username = self.user.username
|
||||
data = {
|
||||
"q": username
|
||||
}
|
||||
response = self.client.get(
|
||||
user_autocomplete_url,
|
||||
data,
|
||||
)
|
||||
content = json.loads(response.content)
|
||||
self.assertEqual(username, content["results"][0]["text"])
|
||||
self.assertEqual(str(self.user.id), content["results"][0]["id"])
|
Loading…
Reference in New Issue
Block a user