summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Manfre2022-11-22 23:07:22 -0500
committerGitHub2022-11-22 21:07:22 -0700
commit96f863d5d8ffa2a326a889eb6b0f8c4c11efb200 (patch)
treeec261735ff212d31ebedac72547547dc09d41389
parent9014d53399b501cee48d1b80bc5e0d59c229134a (diff)
downloadtakahe-96f863d5d8ffa2a326a889eb6b0f8c4c11efb200.tar.gz
takahe-96f863d5d8ffa2a326a889eb6b0f8c4c11efb200.tar.bz2
takahe-96f863d5d8ffa2a326a889eb6b0f8c4c11efb200.zip
Allow authenticated users to remote search/fetch by exact identity
-rw-r--r--activities/views/search.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/activities/views/search.py b/activities/views/search.py
index cf62410..b175052 100644
--- a/activities/views/search.py
+++ b/activities/views/search.py
@@ -1,7 +1,7 @@
from django import forms
from django.views.generic import FormView
-from users.models import Identity
+from users.models import Domain, Identity
class Search(FormView):
@@ -15,12 +15,28 @@ class Search(FormView):
query = form.cleaned_data["query"].lstrip("@").lower()
results = {"identities": set()}
# Search identities
+
if "@" in query:
username, domain = query.split("@", 1)
- for identity in Identity.objects.filter(
- domain_id=domain, username=username
- )[:20]:
+
+ # Resolve the domain to the display domain
+ 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)
+
else:
for identity in Identity.objects.filter(username=query)[:20]:
results["identities"].add(identity)