From 0f32471b2a727d3a24128ffbe4cdbcb40feedd90 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 08:31:40 -0700 Subject: [PATCH 01/14] Show quotes without content as large discover cards --- bookwyrm/views/discover.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bookwyrm/views/discover.py b/bookwyrm/views/discover.py index 059365f97..2ae4a9303 100644 --- a/bookwyrm/views/discover.py +++ b/bookwyrm/views/discover.py @@ -16,6 +16,7 @@ class Discover(View): def get(self, request): """tiled book activity page""" + # all activities in the "federated" feed associated with a book activities = ( activitystreams.streams["local"] .get_activity_stream(request.user) @@ -29,13 +30,19 @@ class Discover(View): large_activities = Paginator( activities.filter(mention_books__isnull=True) - .exclude(content=None, quotation__quote=None) - .exclude(content=""), + # exclude statuses with no user-provided content for large panels + .exclude( + Q(Q(content="") | Q(content__isnull=True)) & Q(quotation__isnull=True), + ), 6, ) small_activities = Paginator( activities.filter( - Q(mention_books__isnull=False) | Q(content=None) | Q(content="") + Q(mention_books__isnull=False) + | Q( + Q(Q(content="") | Q(content__isnull=True)) + & Q(quotation__isnull=True), + ) ), 4, ) From a68196d9bbd5cfa2d68142afd4f320633890f1e9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 08:54:57 -0700 Subject: [PATCH 02/14] Improves user admin filter behavior --- bookwyrm/templates/user_admin/user_admin_filters.html | 2 +- bookwyrm/views/user_admin.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/user_admin/user_admin_filters.html b/bookwyrm/templates/user_admin/user_admin_filters.html index 5283b4e9c..c9c7a93fc 100644 --- a/bookwyrm/templates/user_admin/user_admin_filters.html +++ b/bookwyrm/templates/user_admin/user_admin_filters.html @@ -1,7 +1,7 @@ {% extends 'snippets/filters_panel/filters_panel.html' %} {% block filter_fields %} -{% include 'user_admin/server_filter.html' %} {% include 'user_admin/username_filter.html' %} {% include 'directory/community_filter.html' %} +{% include 'user_admin/server_filter.html' %} {% endblock %} diff --git a/bookwyrm/views/user_admin.py b/bookwyrm/views/user_admin.py index 3a9ea3392..ac5357a28 100644 --- a/bookwyrm/views/user_admin.py +++ b/bookwyrm/views/user_admin.py @@ -31,8 +31,8 @@ class UserAdminList(View): if username: filters["username__icontains"] = username scope = request.GET.get("scope") - if scope: - filters["local"] = scope == "local" + if scope and scope == "local": + filters["local"] = True users = models.User.objects.filter(**filters) From 2886c15e1d70d1ee8acbd3e0cd9825f7affa7688 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 09:35:25 -0700 Subject: [PATCH 03/14] Adds more info to user admin page --- bookwyrm/templates/user_admin/user.html | 12 +-- bookwyrm/templates/user_admin/user_info.html | 93 +++++++++++++++++++- 2 files changed, 99 insertions(+), 6 deletions(-) diff --git a/bookwyrm/templates/user_admin/user.html b/bookwyrm/templates/user_admin/user.html index c79c6971f..5c118175b 100644 --- a/bookwyrm/templates/user_admin/user.html +++ b/bookwyrm/templates/user_admin/user.html @@ -2,13 +2,15 @@ {% load i18n %} {% block title %}{{ user.username }}{% endblock %} -{% block header %}{{ user.username }}{% endblock %} +{% block header %} +{{ user.username }} +

+ {% trans "Back to users" %} +

+ +{% endblock %} {% block panel %} - - {% include 'user_admin/user_info.html' with user=user %} {% include 'user_admin/user_moderation_actions.html' with user=user %} diff --git a/bookwyrm/templates/user_admin/user_info.html b/bookwyrm/templates/user_admin/user_info.html index 579b3af7e..69a84a664 100644 --- a/bookwyrm/templates/user_admin/user_info.html +++ b/bookwyrm/templates/user_admin/user_info.html @@ -1,8 +1,10 @@ {% load i18n %} {% load markdown %} +{% load humanize %} +
-

{% trans "User details" %}

+

{% trans "Profile" %}

{% include 'user/user_preview.html' with user=user %} {% if user.summary %} @@ -14,6 +16,95 @@

{% trans "View user profile" %}

+
+

{% trans "Status" %}

+
+ {% if user.is_active %} +

+ {% trans "Active" %} +

+ {% else %} +

+ {% trans "Inactive" %} + {% if user.deactivation_reason %} + ({{ user.deactivation_reason }}) + {% endif %} +

+ {% endif %} +

+ {% if user.local %} + {% trans "Local" %} + {% else %} + {% trans "Remote" %} + {% endif %} +

+
+
+
+ +
+
+

{% trans "User details" %}

+
+
+ {% if user.local %} +
+
{% trans "Email:" %}
+
{{ user.email }}
+
+ {% endif %} + + {% with report_count=user.report_set.count %} +
+
{% trans "Reports:" %}
+
+ {{ report_count|intcomma }} + {% if report_count > 0 %} + + {% trans "(View reports)" %} + + {% endif %} +
+
+ {% endwith %} + +
+
{% trans "Blocked by count:" %}
+
{{ user.blocked_by.count }}
+
+ +
+
{% trans "Last active date:" %}
+
{{ user.last_active_date }}
+
+ +
+
{% trans "Manually approved followers:" %}
+
{{ user.manually_approves_followers }}
+
+ +
+
{% trans "Discoverable:" %}
+
{{ user.discoverable }}
+
+ + {% if not user.is_active %} +
+
{% trans "Deactivation reason:" %}
+
{{ user.deactivation_reason }}
+
+ {% endif %} + + {% if not user.is_active and user.deactivation_reason == "pending" %} +
+
{% trans "Confirmation code:" %}
+
{{ user.confirmation_code }}
+
+ {% endif %} +
+
+
+ {% if not user.local %} {% with server=user.federated_server %}
From 34a5eccba76f0aa34f735fd4ccca18ee7a92186f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 09:43:41 -0700 Subject: [PATCH 04/14] Increase max upload size in nginx --- nginx/production | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nginx/production b/nginx/production index 76f18f32f..3c8b2ea7d 100644 --- a/nginx/production +++ b/nginx/production @@ -24,7 +24,9 @@ server { # listen 443 ssl http2; # # server_name your-domain.com; - +# +# client_max_body_size 3M; +# # if ($host != "you-domain.com") { # return 301 $scheme://your-domain.com$request_uri; # } From eb67c4730f37b7f5134ee9a7517005a12f51136a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 09:48:57 -0700 Subject: [PATCH 05/14] Renames list layout file --- bookwyrm/templates/lists/curate.html | 2 +- bookwyrm/templates/lists/{list_layout.html => layout.html} | 0 bookwyrm/templates/lists/list.html | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename bookwyrm/templates/lists/{list_layout.html => layout.html} (100%) diff --git a/bookwyrm/templates/lists/curate.html b/bookwyrm/templates/lists/curate.html index 661410e81..638d86b88 100644 --- a/bookwyrm/templates/lists/curate.html +++ b/bookwyrm/templates/lists/curate.html @@ -1,4 +1,4 @@ -{% extends 'lists/list_layout.html' %} +{% extends 'lists/layout.html' %} {% load i18n %} {% block panel %} diff --git a/bookwyrm/templates/lists/list_layout.html b/bookwyrm/templates/lists/layout.html similarity index 100% rename from bookwyrm/templates/lists/list_layout.html rename to bookwyrm/templates/lists/layout.html diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index 37f7079bd..35014a7b6 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -1,4 +1,4 @@ -{% extends 'lists/list_layout.html' %} +{% extends 'lists/layout.html' %} {% load i18n %} {% load bookwyrm_tags %} {% load markdown %} From 1e037d20a499c7943572acbc4f5a3865e47eab43 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 10:03:00 -0700 Subject: [PATCH 06/14] Adds delete button to list --- bookwyrm/templates/lists/edit_form.html | 1 + bookwyrm/templates/lists/form.html | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/lists/edit_form.html b/bookwyrm/templates/lists/edit_form.html index 917e5e2aa..def47f063 100644 --- a/bookwyrm/templates/lists/edit_form.html +++ b/bookwyrm/templates/lists/edit_form.html @@ -9,4 +9,5 @@
{% include 'lists/form.html' %}
+{% include "lists/delete_list_modal.html" with controls_text="delete_list" controls_uid=list.id %} {% endblock %} diff --git a/bookwyrm/templates/lists/form.html b/bookwyrm/templates/lists/form.html index e5eb9c379..4252d709f 100644 --- a/bookwyrm/templates/lists/form.html +++ b/bookwyrm/templates/lists/form.html @@ -3,7 +3,7 @@
-
+
{{ list_form.name }} @@ -34,12 +34,19 @@
-
-
- {% include 'snippets/privacy_select.html' with current=list.privacy %} +
+
+
+
+ {% include 'snippets/privacy_select.html' with current=list.privacy %} +
+
+ +
+
-
- +
+ {% trans "Delete list" as button_text %} + {% include 'snippets/toggle/toggle_button.html' with class="is-danger" text=button_text icon_with_text="x" controls_text="delete_list" controls_uid=list.id focus="modal_title_delete_list" %}
- From c630ec3572195104331617742c7495364e5b6ee9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 10:38:37 -0700 Subject: [PATCH 07/14] Adds delete list view --- bookwyrm/urls.py | 1 + bookwyrm/views/__init__.py | 1 + bookwyrm/views/list.py | 15 +++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 1dbd67a76..991114fad 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -220,6 +220,7 @@ urlpatterns = [ re_path(r"^list/?$", views.Lists.as_view(), name="lists"), re_path(r"^list/saved/?$", views.SavedLists.as_view(), name="saved-lists"), re_path(r"^list/(?P\d+)(.json)?/?$", views.List.as_view(), name="list"), + re_path(r"^list/delete/(?P\d+)/?$", views.delete_list, name="delete-list"), re_path(r"^list/add-book/?$", views.list.add_book, name="list-add-book"), re_path( r"^list/(?P\d+)/remove/?$", diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index f42049254..ca52800c4 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -27,6 +27,7 @@ from .isbn import Isbn from .landing import About, Home, Landing from .list import Lists, SavedLists, List, Curate, UserLists from .list import save_list, unsave_list +from .list import delete_list from .notifications import Notifications from .outbox import Outbox from .reading import edit_readthrough, create_readthrough diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index e6ef52ba5..af99e9f55 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -3,6 +3,7 @@ from typing import Optional from urllib.parse import urlencode from django.contrib.auth.decorators import login_required +from django.core.exceptions import PermissionDenied from django.core.paginator import Paginator from django.db import IntegrityError, transaction from django.db.models import Avg, Count, DecimalField, Q, Max @@ -260,6 +261,20 @@ def unsave_list(request, list_id): return redirect("list", list_id) +@require_POST +@login_required +def delete_list(request, list_id): + """delete a list""" + book_list = get_object_or_404(models.List, id=list_id) + + # only the owner or a moderator can delete a list + if book_list.user != request.user and not request.user.has_perm("moderate_post"): + raise PermissionDenied + + book_list.delete() + return redirect("lists") + + @require_POST @login_required def add_book(request): From c4f2d670488d8c9248adfd6816e8c03a05b4f628 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 10:52:20 -0700 Subject: [PATCH 08/14] Adds view tests --- bookwyrm/tests/views/test_list_actions.py | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/bookwyrm/tests/views/test_list_actions.py b/bookwyrm/tests/views/test_list_actions.py index 2339427c6..710d83de5 100644 --- a/bookwyrm/tests/views/test_list_actions.py +++ b/bookwyrm/tests/views/test_list_actions.py @@ -3,6 +3,7 @@ import json from unittest.mock import patch from django.contrib.auth.models import AnonymousUser +from django.core.exceptions import PermissionDenied from django.test import TestCase from django.test.client import RequestFactory @@ -66,6 +67,37 @@ class ListActionViews(TestCase): self.anonymous_user.is_authenticated = False models.SiteSettings.objects.create() + def test_delete_list(self): + """delete an entire list""" + models.ListItem.objects.create( + book_list=self.list, + user=self.local_user, + book=self.book, + approved=True, + order=1, + ) + models.ListItem.objects.create( + book_list=self.list, + user=self.local_user, + book=self.book_two, + approved=False, + order=2, + ) + request = self.factory.post("") + request.user = self.local_user + with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: + views.delete_list(request, self.list.id) + self.assertEqual(mock.call_count, 1) + self.assertFalse(models.List.objects.exists()) + self.assertFalse(models.ListItem.objects.exists()) + + def test_delete_list_permission_denied(self): + """delete an entire list""" + request = self.factory.post("") + request.user = self.rat + with self.assertRaises(PermissionDenied): + views.delete_list(request, self.list.id) + def test_curate_approve(self): """approve a pending item""" view = views.Curate.as_view() From 5640ae4f7e2230220f2ae3474b59800424e5feb5 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 11:24:08 -0700 Subject: [PATCH 09/14] Handle deletions of ordered collections --- bookwyrm/models/activitypub_mixin.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index 4e313723a..f287b752f 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -362,6 +362,13 @@ class OrderedCollectionMixin(OrderedCollectionPageMixin): self.collection_queryset, **kwargs ).serialize() + def delete(self, *args, broadcast=True, **kwargs): + """Delete the object""" + activity = self.to_delete_activity(self.user) + super().delete(*args, **kwargs) + if self.user.local and broadcast: + self.broadcast(activity, self.user) + class CollectionItemMixin(ActivitypubMixin): """for items that are part of an (Ordered)Collection""" From d212cbfd3c6f13bb00da90f0d6bbe2f74914cb07 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 11:54:53 -0700 Subject: [PATCH 10/14] Adds new template --- .../templates/lists/delete_list_modal.html | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 bookwyrm/templates/lists/delete_list_modal.html diff --git a/bookwyrm/templates/lists/delete_list_modal.html b/bookwyrm/templates/lists/delete_list_modal.html new file mode 100644 index 000000000..ee7a33935 --- /dev/null +++ b/bookwyrm/templates/lists/delete_list_modal.html @@ -0,0 +1,21 @@ +{% extends 'components/modal.html' %} +{% load i18n %} + +{% block modal-title %}{% trans "Delete this list?" %}{% endblock %} + +{% block modal-body %} +{% trans "This action cannot be un-done" %} +{% endblock %} + +{% block modal-footer %} +
+ {% csrf_token %} + + + {% trans "Cancel" as button_text %} + {% include 'snippets/toggle/toggle_button.html' with text=button_text controls_text="delete_list" controls_uid=list.id %} +
+{% endblock %} + From ae81d6cf71b44468b15eb14e06e35322410795e0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 11:55:04 -0700 Subject: [PATCH 11/14] More tests --- bookwyrm/models/activitypub_mixin.py | 10 ++++++++ .../tests/views/inbox/test_inbox_delete.py | 25 +++++++++++++------ bookwyrm/tests/views/test_list_actions.py | 5 ++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index f287b752f..3e9e1940f 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -369,6 +369,16 @@ class OrderedCollectionMixin(OrderedCollectionPageMixin): if self.user.local and broadcast: self.broadcast(activity, self.user) + def to_delete_activity(self, user): + """notice of deletion""" + return activitypub.Delete( + id=self.remote_id + "/activity", + actor=user.remote_id, + to=["%s/followers" % user.remote_id], + cc=["https://www.w3.org/ns/activitystreams#Public"], + object=self.remote_id, + ).serialize() + class CollectionItemMixin(ActivitypubMixin): """for items that are part of an (Ordered)Collection""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index 1566c05a2..fef5ce513 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -40,14 +40,6 @@ class InboxActivities(TestCase): remote_id="https://example.com/status/1", ) - self.create_json = { - "id": "hi", - "type": "Create", - "actor": "hi", - "to": ["https://www.w3.org/ns/activitystreams#public"], - "cc": ["https://example.com/user/mouse/followers"], - "object": {}, - } models.SiteSettings.objects.create() def test_delete_status(self): @@ -137,3 +129,20 @@ class InboxActivities(TestCase): # nothing happens. views.inbox.activity_task(activity) self.assertEqual(models.User.objects.filter(is_active=True).count(), 2) + + def test_delete_list(self): + """delete a list""" + book_list = models.List.objects.create( + name="test list", + user=self.remote_user, + ) + activity = { + "@context": "https://www.w3.org/ns/activitystreams", + "id": "https://example.com/users/test-user#delete", + "type": "Delete", + "actor": "https://example.com/users/test-user", + "to": ["https://www.w3.org/ns/activitystreams#Public"], + "object": book_list.remote_id, + } + views.inbox.activity_task(activity) + self.assertFalse(models.List.objects.exists()) diff --git a/bookwyrm/tests/views/test_list_actions.py b/bookwyrm/tests/views/test_list_actions.py index 710d83de5..e268905d8 100644 --- a/bookwyrm/tests/views/test_list_actions.py +++ b/bookwyrm/tests/views/test_list_actions.py @@ -87,6 +87,11 @@ class ListActionViews(TestCase): request.user = self.local_user with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: views.delete_list(request, self.list.id) + activity = json.loads(mock.call_args[0][1]) + self.assertEqual(activity["type"], "Delete") + self.assertEqual(activity["actor"], self.local_user.remote_id) + self.assertEqual(activity["object"], self.list.remote_id) + self.assertEqual(mock.call_count, 1) self.assertFalse(models.List.objects.exists()) self.assertFalse(models.ListItem.objects.exists()) From cb21099e0b29edca72d694f52936df9d9290150c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 12:00:10 -0700 Subject: [PATCH 12/14] Fixes serialization of delete activity --- bookwyrm/models/activitypub_mixin.py | 10 ---------- bookwyrm/tests/views/inbox/test_inbox_delete.py | 2 +- bookwyrm/tests/views/test_list_actions.py | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index 3e9e1940f..f287b752f 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -369,16 +369,6 @@ class OrderedCollectionMixin(OrderedCollectionPageMixin): if self.user.local and broadcast: self.broadcast(activity, self.user) - def to_delete_activity(self, user): - """notice of deletion""" - return activitypub.Delete( - id=self.remote_id + "/activity", - actor=user.remote_id, - to=["%s/followers" % user.remote_id], - cc=["https://www.w3.org/ns/activitystreams#Public"], - object=self.remote_id, - ).serialize() - class CollectionItemMixin(ActivitypubMixin): """for items that are part of an (Ordered)Collection""" diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index fef5ce513..c40f7a331 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -142,7 +142,7 @@ class InboxActivities(TestCase): "type": "Delete", "actor": "https://example.com/users/test-user", "to": ["https://www.w3.org/ns/activitystreams#Public"], - "object": book_list.remote_id, + "object": {"id": book_list.remote_id, "type": "List"} } views.inbox.activity_task(activity) self.assertFalse(models.List.objects.exists()) diff --git a/bookwyrm/tests/views/test_list_actions.py b/bookwyrm/tests/views/test_list_actions.py index e268905d8..8ebeea28b 100644 --- a/bookwyrm/tests/views/test_list_actions.py +++ b/bookwyrm/tests/views/test_list_actions.py @@ -90,7 +90,7 @@ class ListActionViews(TestCase): activity = json.loads(mock.call_args[0][1]) self.assertEqual(activity["type"], "Delete") self.assertEqual(activity["actor"], self.local_user.remote_id) - self.assertEqual(activity["object"], self.list.remote_id) + self.assertEqual(activity["object"]["id"], self.list.remote_id) self.assertEqual(mock.call_count, 1) self.assertFalse(models.List.objects.exists()) From 8382d1a684f4eafe5b078cb67a43e1bbbbf956bd Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 12:30:11 -0700 Subject: [PATCH 13/14] Updates tests --- bookwyrm/tests/views/inbox/test_inbox_delete.py | 12 +++++++++++- bookwyrm/tests/views/test_list_actions.py | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/bookwyrm/tests/views/inbox/test_inbox_delete.py b/bookwyrm/tests/views/inbox/test_inbox_delete.py index c40f7a331..f47d87374 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_delete.py +++ b/bookwyrm/tests/views/inbox/test_inbox_delete.py @@ -135,6 +135,7 @@ class InboxActivities(TestCase): book_list = models.List.objects.create( name="test list", user=self.remote_user, + remote_id="https://example.com/list/1", ) activity = { "@context": "https://www.w3.org/ns/activitystreams", @@ -142,7 +143,16 @@ class InboxActivities(TestCase): "type": "Delete", "actor": "https://example.com/users/test-user", "to": ["https://www.w3.org/ns/activitystreams#Public"], - "object": {"id": book_list.remote_id, "type": "List"} + "object": { + "id": book_list.remote_id, + "owner": self.remote_user.remote_id, + "type": "BookList", + "totalItems": 0, + "first": "", + "name": "test list", + "to": [], + "cc": [], + }, } views.inbox.activity_task(activity) self.assertFalse(models.List.objects.exists()) diff --git a/bookwyrm/tests/views/test_list_actions.py b/bookwyrm/tests/views/test_list_actions.py index 8ebeea28b..b998f2749 100644 --- a/bookwyrm/tests/views/test_list_actions.py +++ b/bookwyrm/tests/views/test_list_actions.py @@ -91,6 +91,7 @@ class ListActionViews(TestCase): self.assertEqual(activity["type"], "Delete") self.assertEqual(activity["actor"], self.local_user.remote_id) self.assertEqual(activity["object"]["id"], self.list.remote_id) + self.assertEqual(activity["object"]["type"], "BookList") self.assertEqual(mock.call_count, 1) self.assertFalse(models.List.objects.exists()) From a8973336d9ff90b90b2a310f32d0e96e9935079b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 6 Sep 2021 12:58:18 -0700 Subject: [PATCH 14/14] Adds mock to list items creation --- bookwyrm/tests/views/test_list_actions.py | 29 ++++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/bookwyrm/tests/views/test_list_actions.py b/bookwyrm/tests/views/test_list_actions.py index b998f2749..84c5540c5 100644 --- a/bookwyrm/tests/views/test_list_actions.py +++ b/bookwyrm/tests/views/test_list_actions.py @@ -69,20 +69,21 @@ class ListActionViews(TestCase): def test_delete_list(self): """delete an entire list""" - models.ListItem.objects.create( - book_list=self.list, - user=self.local_user, - book=self.book, - approved=True, - order=1, - ) - models.ListItem.objects.create( - book_list=self.list, - user=self.local_user, - book=self.book_two, - approved=False, - order=2, - ) + with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): + models.ListItem.objects.create( + book_list=self.list, + user=self.local_user, + book=self.book, + approved=True, + order=1, + ) + models.ListItem.objects.create( + book_list=self.list, + user=self.local_user, + book=self.book_two, + approved=False, + order=2, + ) request = self.factory.post("") request.user = self.local_user with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay") as mock: