mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-14 12:16:31 +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">
|
<div class="navbar-end">
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<div class="navbar-item has-dropdown is-hoverable">
|
<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/avatar.html' with user=request.user %}
|
||||||
{% include 'snippets/username.html' with user=request.user %}
|
{% include 'snippets/username.html' with user=request.user %}
|
||||||
</p></div>
|
</p></div>
|
||||||
<div class="navbar-dropdown">
|
<ul class="navbar-dropdown" id="navbar-dropdown">
|
||||||
<a href="/direct-messages" class="navbar-item">
|
<li>
|
||||||
Direct messages
|
<a href="/direct-messages" class="navbar-item">
|
||||||
</a>
|
Direct messages
|
||||||
<a href="/user/{{request.user.localname}}" class="navbar-item">
|
</a>
|
||||||
Profile
|
</li>
|
||||||
</a>
|
<li>
|
||||||
<a href="/user-edit" class="navbar-item">
|
<a href="/user/{{request.user.localname}}" class="navbar-item">
|
||||||
Settings
|
Profile
|
||||||
</a>
|
</a>
|
||||||
<a href="/import" class="navbar-item">
|
</li>
|
||||||
Import books
|
<li>
|
||||||
</a>
|
<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 %}
|
{% if perms.bookwyrm.create_invites %}
|
||||||
<a href="/invite" class="navbar-item">
|
<li>
|
||||||
Invites
|
<a href="/invite" class="navbar-item">
|
||||||
</a>
|
Invites
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<hr class="navbar-divider">
|
<hr class="navbar-divider">
|
||||||
<a href="/logout" class="navbar-item">
|
<li>
|
||||||
Log out
|
<a href="/logout" class="navbar-item">
|
||||||
</a>
|
Log out
|
||||||
</div>
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-item">
|
<div class="navbar-item">
|
||||||
<a href="/notifications">
|
<a href="/notifications">
|
||||||
|
|
|
@ -211,6 +211,19 @@ class Views(TestCase):
|
||||||
response.context_data['book_results'][0].title, 'Gideon the Ninth')
|
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):
|
def test_import_page(self):
|
||||||
''' there are so many views, this just makes sure it LOADS '''
|
''' there are so many views, this just makes sure it LOADS '''
|
||||||
request = self.factory.get('')
|
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.contrib.postgres.search import TrigramSimilarity
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.db.models import Avg, Q
|
from django.db.models import Avg, Q
|
||||||
|
from django.db.models.functions import Greatest
|
||||||
from django.http import HttpResponseNotFound, JsonResponse
|
from django.http import HttpResponseNotFound, JsonResponse
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
|
@ -45,7 +46,8 @@ def is_api_request(request):
|
||||||
def is_bookworm_request(request):
|
def is_bookworm_request(request):
|
||||||
''' check if the request is coming from another bookworm instance '''
|
''' check if the request is coming from another bookworm instance '''
|
||||||
user_agent = request.headers.get('User-Agent')
|
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 False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -180,7 +182,7 @@ def get_activity_feed(user, filter_level, model=models.Status):
|
||||||
return activities.filter(
|
return activities.filter(
|
||||||
Q(user=user) | Q(mention_users=user),
|
Q(user=user) | Q(mention_users=user),
|
||||||
privacy='direct'
|
privacy='direct'
|
||||||
)
|
).distinct()
|
||||||
|
|
||||||
# never show DMs in the regular feed
|
# never show DMs in the regular feed
|
||||||
activities = activities.filter(~Q(privacy='direct'))
|
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=[
|
Q(user__in=following, privacy__in=[
|
||||||
'public', 'unlisted', 'followers'
|
'public', 'unlisted', 'followers'
|
||||||
]) | Q(mention_users=user) | Q(user=user)
|
]) | Q(mention_users=user) | Q(user=user)
|
||||||
)
|
).distinct()
|
||||||
elif filter_level == 'self':
|
elif filter_level == 'self':
|
||||||
activities = activities.filter(user=user, privacy='public')
|
activities = activities.filter(user=user, privacy='public')
|
||||||
elif filter_level == 'local':
|
elif filter_level == 'local':
|
||||||
|
@ -234,7 +236,10 @@ def search(request):
|
||||||
|
|
||||||
# do a local user search
|
# do a local user search
|
||||||
user_results = models.User.objects.annotate(
|
user_results = models.User.objects.annotate(
|
||||||
similarity=TrigramSimilarity('username', query),
|
similarity=Greatest(
|
||||||
|
TrigramSimilarity('username', query),
|
||||||
|
TrigramSimilarity('localname', query),
|
||||||
|
)
|
||||||
).filter(
|
).filter(
|
||||||
similarity__gt=0.5,
|
similarity__gt=0.5,
|
||||||
).order_by('-similarity')[:10]
|
).order_by('-similarity')[:10]
|
||||||
|
@ -512,7 +517,8 @@ def status_page(request, username, status_id):
|
||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
if is_api_request(request):
|
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 = {
|
data = {
|
||||||
'title': 'Status by %s' % user.username,
|
'title': 'Status by %s' % user.username,
|
||||||
|
|
Loading…
Reference in a new issue