Allow authenticated users to remote search/fetch by exact identity
This commit is contained in:
parent
9014d53399
commit
96f863d5d8
|
@ -1,7 +1,7 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.views.generic import FormView
|
from django.views.generic import FormView
|
||||||
|
|
||||||
from users.models import Identity
|
from users.models import Domain, Identity
|
||||||
|
|
||||||
|
|
||||||
class Search(FormView):
|
class Search(FormView):
|
||||||
|
@ -15,12 +15,28 @@ class Search(FormView):
|
||||||
query = form.cleaned_data["query"].lstrip("@").lower()
|
query = form.cleaned_data["query"].lstrip("@").lower()
|
||||||
results = {"identities": set()}
|
results = {"identities": set()}
|
||||||
# Search identities
|
# Search identities
|
||||||
|
|
||||||
if "@" in query:
|
if "@" in query:
|
||||||
username, domain = query.split("@", 1)
|
username, domain = query.split("@", 1)
|
||||||
for identity in Identity.objects.filter(
|
|
||||||
domain_id=domain, username=username
|
# Resolve the domain to the display domain
|
||||||
)[:20]:
|
domain_instance = Domain.get_domain(domain)
|
||||||
|
try:
|
||||||
|
if domain_instance is None:
|
||||||
|
raise Identity.DoesNotExist()
|
||||||
|
identity = Identity.objects.get(
|
||||||
|
domain=domain_instance, username=username
|
||||||
|
)
|
||||||
|
except Identity.DoesNotExist:
|
||||||
|
if self.request.identity is not None:
|
||||||
|
# Allow authenticated users to fetch remote
|
||||||
|
identity = Identity.by_username_and_domain(
|
||||||
|
username, domain, fetch=True
|
||||||
|
)
|
||||||
|
identity = None
|
||||||
|
if identity:
|
||||||
results["identities"].add(identity)
|
results["identities"].add(identity)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for identity in Identity.objects.filter(username=query)[:20]:
|
for identity in Identity.objects.filter(username=query)[:20]:
|
||||||
results["identities"].add(identity)
|
results["identities"].add(identity)
|
||||||
|
|
Loading…
Reference in New Issue