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"):
|
if activity_json.get("publicKeyPem"):
|
||||||
# ugh
|
# ugh
|
||||||
activity_json["type"] = "PublicKey"
|
activity_json["type"] = "PublicKey"
|
||||||
|
|
||||||
|
activity_type = activity_json.get("type")
|
||||||
try:
|
try:
|
||||||
activity_type = activity_json["type"]
|
|
||||||
serializer = activity_objects[activity_type]
|
serializer = activity_objects[activity_type]
|
||||||
except KeyError as e:
|
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)
|
raise ActivitySerializerError(e)
|
||||||
|
|
||||||
return serializer(activity_objects=activity_objects, **activity_json)
|
return serializer(activity_objects=activity_objects, **activity_json)
|
||||||
|
|
|
@ -16,7 +16,11 @@ class Verb(ActivityObject):
|
||||||
|
|
||||||
def action(self):
|
def action(self):
|
||||||
""" usually we just want to update and save """
|
""" 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)
|
@dataclass(init=False)
|
||||||
|
@ -54,7 +58,9 @@ class Update(Verb):
|
||||||
|
|
||||||
def action(self):
|
def action(self):
|
||||||
""" update a model instance from the dataclass """
|
""" update a model instance from the dataclass """
|
||||||
self.object.to_model(allow_create=False)
|
obj = self.object
|
||||||
|
if obj:
|
||||||
|
self.object.to_model(allow_create=False)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(init=False)
|
@dataclass(init=False)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
{% trans "Reports" %}
|
{% trans "Reports" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{% if server %}
|
{% if server %}
|
||||||
{% blocktrans with server_name=server.server_name %}Reports: <small>{{ server_name }}</small>{% endblocktrans %}
|
{% blocktrans with server_name=server.server_name %}Reports: <small>{{ server_name }}</small>{% endblocktrans %}
|
||||||
|
@ -29,6 +30,8 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% include 'settings/user_admin_filters.html' %}
|
||||||
|
|
||||||
<div class="block">
|
<div class="block">
|
||||||
{% if not reports %}
|
{% if not reports %}
|
||||||
<em>{% trans "No reports found." %}</em>
|
<em>{% trans "No reports found." %}</em>
|
||||||
|
|
|
@ -39,14 +39,14 @@
|
||||||
<dt>{% trans "Users:" %}</dt>
|
<dt>{% trans "Users:" %}</dt>
|
||||||
<dd>
|
<dd>
|
||||||
{{ users.count }}
|
{{ 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>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
<div class="is-flex">
|
<div class="is-flex">
|
||||||
<dt>{% trans "Reports:" %}</dt>
|
<dt>{% trans "Reports:" %}</dt>
|
||||||
<dd>
|
<dd>
|
||||||
{{ reports.count }}
|
{{ 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>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
<div class="is-flex">
|
<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 %}
|
{% block panel %}
|
||||||
|
|
||||||
|
{% include 'settings/user_admin_filters.html' %}
|
||||||
|
|
||||||
<table class="table is-striped">
|
<table class="table is-striped">
|
||||||
<tr>
|
<tr>
|
||||||
{% url 'settings-users' as url %}
|
{% 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 django.test import TestCase
|
||||||
|
|
||||||
from bookwyrm import models, views
|
from bookwyrm import models, views
|
||||||
|
from bookwyrm.activitypub import ActivitySerializerError
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=too-many-public-methods
|
||||||
|
@ -51,7 +52,7 @@ class InboxCreate(TestCase):
|
||||||
}
|
}
|
||||||
models.SiteSettings.objects.create()
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_handle_create_status(self):
|
def test_create_status(self):
|
||||||
""" the "it justs works" mode """
|
""" the "it justs works" mode """
|
||||||
self.assertEqual(models.Status.objects.count(), 1)
|
self.assertEqual(models.Status.objects.count(), 1)
|
||||||
|
|
||||||
|
@ -82,7 +83,7 @@ class InboxCreate(TestCase):
|
||||||
views.inbox.activity_task(activity)
|
views.inbox.activity_task(activity)
|
||||||
self.assertEqual(models.Status.objects.count(), 2)
|
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 """
|
""" should only create it under the right circumstances """
|
||||||
self.assertEqual(models.Status.objects.count(), 1)
|
self.assertEqual(models.Status.objects.count(), 1)
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
|
@ -105,7 +106,7 @@ class InboxCreate(TestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(models.Notification.objects.get().notification_type, "MENTION")
|
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 """
|
""" should only create it under the right circumstances """
|
||||||
self.assertEqual(models.Status.objects.count(), 1)
|
self.assertEqual(models.Status.objects.count(), 1)
|
||||||
self.assertFalse(models.Notification.objects.filter(user=self.local_user))
|
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.assertTrue(models.Notification.objects.filter(user=self.local_user))
|
||||||
self.assertEqual(models.Notification.objects.get().notification_type, "REPLY")
|
self.assertEqual(models.Notification.objects.get().notification_type, "REPLY")
|
||||||
|
|
||||||
def test_handle_create_list(self):
|
def test_create_list(self):
|
||||||
""" a new list """
|
""" a new list """
|
||||||
activity = self.create_json
|
activity = self.create_json
|
||||||
activity["object"] = {
|
activity["object"] = {
|
||||||
|
@ -149,3 +150,23 @@ class InboxCreate(TestCase):
|
||||||
self.assertEqual(book_list.curation, "curated")
|
self.assertEqual(book_list.curation, "curated")
|
||||||
self.assertEqual(book_list.description, "summary text")
|
self.assertEqual(book_list.description, "summary text")
|
||||||
self.assertEqual(book_list.remote_id, "https://example.com/list/22")
|
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:
|
except ValueError:
|
||||||
page = 1
|
page = 1
|
||||||
|
|
||||||
servers = models.FederatedServer.objects.all()
|
servers = models.FederatedServer.objects
|
||||||
|
|
||||||
sort = request.GET.get("sort")
|
sort = request.GET.get("sort")
|
||||||
sort_fields = ["created_date", "application_type", "server_name"]
|
sort_fields = ["created_date", "application_type", "server_name"]
|
||||||
|
|
|
@ -29,8 +29,10 @@ class Reports(View):
|
||||||
resolved = request.GET.get("resolved") == "true"
|
resolved = request.GET.get("resolved") == "true"
|
||||||
server = request.GET.get("server")
|
server = request.GET.get("server")
|
||||||
if server:
|
if server:
|
||||||
server = get_object_or_404(models.FederatedServer, id=server)
|
filters["user__federated_server__server_name"] = server
|
||||||
filters["user__federated_server"] = server
|
username = request.GET.get("username")
|
||||||
|
if username:
|
||||||
|
filters["user__username__icontains"] = username
|
||||||
filters["resolved"] = resolved
|
filters["resolved"] = resolved
|
||||||
data = {
|
data = {
|
||||||
"resolved": resolved,
|
"resolved": resolved,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
""" manage user """
|
""" manage user """
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
@ -29,10 +28,14 @@ class UserAdmin(View):
|
||||||
filters = {}
|
filters = {}
|
||||||
server = request.GET.get("server")
|
server = request.GET.get("server")
|
||||||
if 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"] = 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 = request.GET.get("sort", "-created_date")
|
||||||
sort_fields = [
|
sort_fields = [
|
||||||
|
@ -46,5 +49,9 @@ class UserAdmin(View):
|
||||||
users = users.order_by(sort)
|
users = users.order_by(sort)
|
||||||
|
|
||||||
paginated = Paginator(users, PAGE_LENGTH)
|
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)
|
return TemplateResponse(request, "settings/user_admin.html", data)
|
||||||
|
|
Loading…
Reference in a new issue