mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-04 23:36:32 +00:00
Merge branch 'main' into production
This commit is contained in:
commit
1a939ed913
12 changed files with 82 additions and 16 deletions
|
@ -52,10 +52,14 @@ def naive_parse(activity_objects, activity_json, serializer=None):
|
|||
if activity_json.get("publicKeyPem"):
|
||||
# ugh
|
||||
activity_json["type"] = "PublicKey"
|
||||
|
||||
activity_type = activity_json.get("type")
|
||||
try:
|
||||
activity_type = activity_json["type"]
|
||||
serializer = activity_objects[activity_type]
|
||||
except KeyError as e:
|
||||
# we know this exists and that we can't handle it
|
||||
if activity_type in ["Question"]:
|
||||
return None
|
||||
raise ActivitySerializerError(e)
|
||||
|
||||
return serializer(activity_objects=activity_objects, **activity_json)
|
||||
|
|
|
@ -16,7 +16,11 @@ class Verb(ActivityObject):
|
|||
|
||||
def action(self):
|
||||
""" usually we just want to update and save """
|
||||
self.object.to_model()
|
||||
obj = self.object
|
||||
# it may return None if the object is invalid in an expected way
|
||||
# ie, Question type
|
||||
if obj:
|
||||
obj.to_model()
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
|
@ -54,6 +58,8 @@ class Update(Verb):
|
|||
|
||||
def action(self):
|
||||
""" update a model instance from the dataclass """
|
||||
obj = self.object
|
||||
if obj:
|
||||
self.object.to_model(allow_create=False)
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
{% trans "Reports" %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block header %}
|
||||
{% if server %}
|
||||
{% blocktrans with server_name=server.server_name %}Reports: <small>{{ server_name }}</small>{% endblocktrans %}
|
||||
|
@ -29,6 +30,8 @@
|
|||
</ul>
|
||||
</div>
|
||||
|
||||
{% include 'settings/user_admin_filters.html' %}
|
||||
|
||||
<div class="block">
|
||||
{% if not reports %}
|
||||
<em>{% trans "No reports found." %}</em>
|
||||
|
|
|
@ -39,14 +39,14 @@
|
|||
<dt>{% trans "Users:" %}</dt>
|
||||
<dd>
|
||||
{{ users.count }}
|
||||
{% if server.user_set.count %}(<a href="{% url 'settings-users' %}?server={{ server.id }}">{% trans "View all" %}</a>){% endif %}
|
||||
{% if server.user_set.count %}(<a href="{% url 'settings-users' %}?server={{ server.server_name }}">{% trans "View all" %}</a>){% endif %}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="is-flex">
|
||||
<dt>{% trans "Reports:" %}</dt>
|
||||
<dd>
|
||||
{{ reports.count }}
|
||||
{% if reports.count %}(<a href="{% url 'settings-reports' %}?server={{ server.id }}">{% trans "View all" %}</a>){% endif %}
|
||||
{% if reports.count %}(<a href="{% url 'settings-reports' %}?server={{ server.server_name }}">{% trans "View all" %}</a>){% endif %}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="is-flex">
|
||||
|
|
7
bookwyrm/templates/settings/server_filter.html
Normal file
7
bookwyrm/templates/settings/server_filter.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block filter %}
|
||||
<label class="label" for="id_server">{% trans "Server name" %}</label>
|
||||
<input type="text" class="input" name="server" value="{{ request.GET.server|default:'' }}" id="id_server" placeholder="example.server.com">
|
||||
{% endblock %}
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
{% block panel %}
|
||||
|
||||
{% include 'settings/user_admin_filters.html' %}
|
||||
|
||||
<table class="table is-striped">
|
||||
<tr>
|
||||
{% url 'settings-users' as url %}
|
||||
|
|
6
bookwyrm/templates/settings/user_admin_filters.html
Normal file
6
bookwyrm/templates/settings/user_admin_filters.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
{% extends 'snippets/filters_panel/filters_panel.html' %}
|
||||
|
||||
{% block filter_fields %}
|
||||
{% include 'settings/server_filter.html' %}
|
||||
{% include 'settings/username_filter.html' %}
|
||||
{% endblock %}
|
8
bookwyrm/templates/settings/username_filter.html
Normal file
8
bookwyrm/templates/settings/username_filter.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
{% extends 'snippets/filters_panel/filter_field.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block filter %}
|
||||
<label class="label" for="id_username">{% trans "Username" %}</label>
|
||||
<input type="text" class="input" name="username" value="{{ request.GET.username|default:'' }}" id="id_username" placeholder="user@domain.com">
|
||||
{% endblock %}
|
||||
|
|
@ -6,6 +6,7 @@ from unittest.mock import patch
|
|||
from django.test import TestCase
|
||||
|
||||
from bookwyrm import models, views
|
||||
from bookwyrm.activitypub import ActivitySerializerError
|
||||
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
|
@ -51,7 +52,7 @@ class InboxCreate(TestCase):
|
|||
}
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
def test_handle_create_status(self):
|
||||
def test_create_status(self):
|
||||
""" the "it justs works" mode """
|
||||
self.assertEqual(models.Status.objects.count(), 1)
|
||||
|
||||
|
@ -82,7 +83,7 @@ class InboxCreate(TestCase):
|
|||
views.inbox.activity_task(activity)
|
||||
self.assertEqual(models.Status.objects.count(), 2)
|
||||
|
||||
def test_handle_create_status_remote_note_with_mention(self):
|
||||
def test_create_status_remote_note_with_mention(self):
|
||||
""" should only create it under the right circumstances """
|
||||
self.assertEqual(models.Status.objects.count(), 1)
|
||||
self.assertFalse(
|
||||
|
@ -105,7 +106,7 @@ class InboxCreate(TestCase):
|
|||
)
|
||||
self.assertEqual(models.Notification.objects.get().notification_type, "MENTION")
|
||||
|
||||
def test_handle_create_status_remote_note_with_reply(self):
|
||||
def test_create_status_remote_note_with_reply(self):
|
||||
""" should only create it under the right circumstances """
|
||||
self.assertEqual(models.Status.objects.count(), 1)
|
||||
self.assertFalse(models.Notification.objects.filter(user=self.local_user))
|
||||
|
@ -126,7 +127,7 @@ class InboxCreate(TestCase):
|
|||
self.assertTrue(models.Notification.objects.filter(user=self.local_user))
|
||||
self.assertEqual(models.Notification.objects.get().notification_type, "REPLY")
|
||||
|
||||
def test_handle_create_list(self):
|
||||
def test_create_list(self):
|
||||
""" a new list """
|
||||
activity = self.create_json
|
||||
activity["object"] = {
|
||||
|
@ -149,3 +150,23 @@ class InboxCreate(TestCase):
|
|||
self.assertEqual(book_list.curation, "curated")
|
||||
self.assertEqual(book_list.description, "summary text")
|
||||
self.assertEqual(book_list.remote_id, "https://example.com/list/22")
|
||||
|
||||
def test_create_unsupported_type(self):
|
||||
""" ignore activities we know we can't handle """
|
||||
activity = self.create_json
|
||||
activity["object"] = {
|
||||
"id": "https://example.com/status/887",
|
||||
"type": "Question",
|
||||
}
|
||||
# just observer how it doesn't throw an error
|
||||
views.inbox.activity_task(activity)
|
||||
|
||||
def test_create_unknown_type(self):
|
||||
""" ignore activities we know we've never heard of """
|
||||
activity = self.create_json
|
||||
activity["object"] = {
|
||||
"id": "https://example.com/status/887",
|
||||
"type": "Threnody",
|
||||
}
|
||||
with self.assertRaises(ActivitySerializerError):
|
||||
views.inbox.activity_task(activity)
|
||||
|
|
|
@ -29,7 +29,7 @@ class Federation(View):
|
|||
except ValueError:
|
||||
page = 1
|
||||
|
||||
servers = models.FederatedServer.objects.all()
|
||||
servers = models.FederatedServer.objects
|
||||
|
||||
sort = request.GET.get("sort")
|
||||
sort_fields = ["created_date", "application_type", "server_name"]
|
||||
|
|
|
@ -29,8 +29,10 @@ class Reports(View):
|
|||
resolved = request.GET.get("resolved") == "true"
|
||||
server = request.GET.get("server")
|
||||
if server:
|
||||
server = get_object_or_404(models.FederatedServer, id=server)
|
||||
filters["user__federated_server"] = server
|
||||
filters["user__federated_server__server_name"] = server
|
||||
username = request.GET.get("username")
|
||||
if username:
|
||||
filters["user__username__icontains"] = username
|
||||
filters["resolved"] = resolved
|
||||
data = {
|
||||
"resolved": resolved,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
""" manage user """
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.core.paginator import Paginator
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
@ -29,10 +28,14 @@ class UserAdmin(View):
|
|||
filters = {}
|
||||
server = request.GET.get("server")
|
||||
if server:
|
||||
server = get_object_or_404(models.FederatedServer, id=server)
|
||||
server = models.FederatedServer.objects.filter(server_name=server).first()
|
||||
filters["federated_server"] = server
|
||||
filters["federated_server__isnull"] = False
|
||||
username = request.GET.get("username")
|
||||
if username:
|
||||
filters["username__icontains"] = username
|
||||
|
||||
users = models.User.objects.filter(**filters).all()
|
||||
users = models.User.objects.filter(**filters)
|
||||
|
||||
sort = request.GET.get("sort", "-created_date")
|
||||
sort_fields = [
|
||||
|
@ -46,5 +49,9 @@ class UserAdmin(View):
|
|||
users = users.order_by(sort)
|
||||
|
||||
paginated = Paginator(users, PAGE_LENGTH)
|
||||
data = {"users": paginated.get_page(page), "sort": sort, "server": server}
|
||||
data = {
|
||||
"users": paginated.get_page(page),
|
||||
"sort": sort,
|
||||
"server": server,
|
||||
}
|
||||
return TemplateResponse(request, "settings/user_admin.html", data)
|
||||
|
|
Loading…
Reference in a new issue