mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-10-31 22:19:00 +00:00
Merge branch 'main' into production
This commit is contained in:
commit
5b397c42f6
3 changed files with 57 additions and 26 deletions
|
@ -63,33 +63,45 @@
|
|||
<div class="navbar-end">
|
||||
{% if request.user.is_authenticated %}
|
||||
<div class="navbar-item has-dropdown is-hoverable">
|
||||
<div class="navbar-link"><p>
|
||||
<div class="navbar-link" role="button" aria-expanded=false" onmouseover="toggleMenu(this)" tabindex="0" aria-haspopup="true" aria-controls="navbar-dropdown"><p>
|
||||
{% include 'snippets/avatar.html' with user=request.user %}
|
||||
{% include 'snippets/username.html' with user=request.user %}
|
||||
</p></div>
|
||||
<div class="navbar-dropdown">
|
||||
<a href="/direct-messages" class="navbar-item">
|
||||
Direct messages
|
||||
</a>
|
||||
<a href="/user/{{request.user.localname}}" class="navbar-item">
|
||||
Profile
|
||||
</a>
|
||||
<a href="/user-edit" class="navbar-item">
|
||||
Settings
|
||||
</a>
|
||||
<a href="/import" class="navbar-item">
|
||||
Import books
|
||||
</a>
|
||||
<ul class="navbar-dropdown" id="navbar-dropdown">
|
||||
<li>
|
||||
<a href="/direct-messages" class="navbar-item">
|
||||
Direct messages
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/user/{{request.user.localname}}" class="navbar-item">
|
||||
Profile
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/user-edit" class="navbar-item">
|
||||
Settings
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/import" class="navbar-item">
|
||||
Import books
|
||||
</a>
|
||||
</li>
|
||||
{% if perms.bookwyrm.create_invites %}
|
||||
<a href="/invite" class="navbar-item">
|
||||
Invites
|
||||
</a>
|
||||
<li>
|
||||
<a href="/invite" class="navbar-item">
|
||||
Invites
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<hr class="navbar-divider">
|
||||
<a href="/logout" class="navbar-item">
|
||||
Log out
|
||||
</a>
|
||||
</div>
|
||||
<li>
|
||||
<a href="/logout" class="navbar-item">
|
||||
Log out
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-item">
|
||||
<a href="/notifications">
|
||||
|
|
|
@ -211,6 +211,19 @@ class Views(TestCase):
|
|||
response.context_data['book_results'][0].title, 'Gideon the Ninth')
|
||||
|
||||
|
||||
def test_search_html_response_users(self):
|
||||
''' searches remote connectors '''
|
||||
request = self.factory.get('', {'q': 'mouse'})
|
||||
with patch('bookwyrm.views.is_api_request') as is_api:
|
||||
is_api.return_value = False
|
||||
with patch('bookwyrm.connectors.connector_manager.search'):
|
||||
response = views.search(request)
|
||||
self.assertIsInstance(response, TemplateResponse)
|
||||
self.assertEqual(response.template_name, 'search_results.html')
|
||||
self.assertEqual(
|
||||
response.context_data['user_results'][0], self.local_user)
|
||||
|
||||
|
||||
def test_import_page(self):
|
||||
''' there are so many views, this just makes sure it LOADS '''
|
||||
request = self.factory.get('')
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.contrib.auth.decorators import login_required, permission_required
|
|||
from django.contrib.postgres.search import TrigramSimilarity
|
||||
from django.core.paginator import Paginator
|
||||
from django.db.models import Avg, Q
|
||||
from django.db.models.functions import Greatest
|
||||
from django.http import HttpResponseNotFound, JsonResponse
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
|
@ -45,7 +46,8 @@ def is_api_request(request):
|
|||
def is_bookworm_request(request):
|
||||
''' check if the request is coming from another bookworm instance '''
|
||||
user_agent = request.headers.get('User-Agent')
|
||||
if user_agent is None or re.search(regex.bookwyrm_user_agent, user_agent) is None:
|
||||
if user_agent is None or \
|
||||
re.search(regex.bookwyrm_user_agent, user_agent) is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
@ -180,7 +182,7 @@ def get_activity_feed(user, filter_level, model=models.Status):
|
|||
return activities.filter(
|
||||
Q(user=user) | Q(mention_users=user),
|
||||
privacy='direct'
|
||||
)
|
||||
).distinct()
|
||||
|
||||
# never show DMs in the regular feed
|
||||
activities = activities.filter(~Q(privacy='direct'))
|
||||
|
@ -195,7 +197,7 @@ def get_activity_feed(user, filter_level, model=models.Status):
|
|||
Q(user__in=following, privacy__in=[
|
||||
'public', 'unlisted', 'followers'
|
||||
]) | Q(mention_users=user) | Q(user=user)
|
||||
)
|
||||
).distinct()
|
||||
elif filter_level == 'self':
|
||||
activities = activities.filter(user=user, privacy='public')
|
||||
elif filter_level == 'local':
|
||||
|
@ -234,7 +236,10 @@ def search(request):
|
|||
|
||||
# do a local user search
|
||||
user_results = models.User.objects.annotate(
|
||||
similarity=TrigramSimilarity('username', query),
|
||||
similarity=Greatest(
|
||||
TrigramSimilarity('username', query),
|
||||
TrigramSimilarity('localname', query),
|
||||
)
|
||||
).filter(
|
||||
similarity__gt=0.5,
|
||||
).order_by('-similarity')[:10]
|
||||
|
@ -512,7 +517,8 @@ def status_page(request, username, status_id):
|
|||
return HttpResponseNotFound()
|
||||
|
||||
if is_api_request(request):
|
||||
return ActivitypubResponse(status.to_activity(pure=not is_bookworm_request(request)))
|
||||
return ActivitypubResponse(
|
||||
status.to_activity(pure=not is_bookworm_request(request)))
|
||||
|
||||
data = {
|
||||
'title': 'Status by %s' % user.username,
|
||||
|
|
Loading…
Reference in a new issue