mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-11 09:45:27 +00:00
Merge pull request #2949 from bookwyrm-social/user-search
Allow searching for local users when logged out
This commit is contained in:
commit
e4ba09178f
2 changed files with 8 additions and 6 deletions
|
@ -156,7 +156,7 @@ class Views(TestCase):
|
||||||
response = view(request)
|
response = view(request)
|
||||||
|
|
||||||
validate_html(response.render())
|
validate_html(response.render())
|
||||||
self.assertFalse("results" in response.context_data)
|
self.assertTrue("results" in response.context_data)
|
||||||
|
|
||||||
def test_search_lists(self):
|
def test_search_lists(self):
|
||||||
"""searches remote connectors"""
|
"""searches remote connectors"""
|
||||||
|
|
|
@ -91,18 +91,15 @@ def book_search(request):
|
||||||
|
|
||||||
|
|
||||||
def user_search(request):
|
def user_search(request):
|
||||||
"""cool kids members only user search"""
|
"""user search: search for a user"""
|
||||||
viewer = request.user
|
viewer = request.user
|
||||||
query = request.GET.get("q")
|
query = request.GET.get("q")
|
||||||
query = query.strip()
|
query = query.strip()
|
||||||
data = {"type": "user", "query": query}
|
data = {"type": "user", "query": query}
|
||||||
# logged out viewers can't search users
|
|
||||||
if not viewer.is_authenticated:
|
|
||||||
return TemplateResponse(request, "search/user.html", data)
|
|
||||||
|
|
||||||
# use webfinger for mastodon style account@domain.com username to load the user if
|
# use webfinger for mastodon style account@domain.com username to load the user if
|
||||||
# they don't exist locally (handle_remote_webfinger will check the db)
|
# they don't exist locally (handle_remote_webfinger will check the db)
|
||||||
if re.match(regex.FULL_USERNAME, query):
|
if re.match(regex.FULL_USERNAME, query) and viewer.is_authenticated:
|
||||||
handle_remote_webfinger(query)
|
handle_remote_webfinger(query)
|
||||||
|
|
||||||
results = (
|
results = (
|
||||||
|
@ -118,6 +115,11 @@ def user_search(request):
|
||||||
)
|
)
|
||||||
.order_by("-similarity")
|
.order_by("-similarity")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# don't expose remote users
|
||||||
|
if not viewer.is_authenticated:
|
||||||
|
results = results.filter(local=True)
|
||||||
|
|
||||||
paginated = Paginator(results, PAGE_LENGTH)
|
paginated = Paginator(results, PAGE_LENGTH)
|
||||||
page = paginated.get_page(request.GET.get("page"))
|
page = paginated.get_page(request.GET.get("page"))
|
||||||
data["results"] = page
|
data["results"] = page
|
||||||
|
|
Loading…
Reference in a new issue