diff --git a/bookwyrm/activitypub/verbs.py b/bookwyrm/activitypub/verbs.py index e890d81fc..7c6279279 100644 --- a/bookwyrm/activitypub/verbs.py +++ b/bookwyrm/activitypub/verbs.py @@ -3,7 +3,7 @@ from dataclasses import dataclass from typing import List from .base_activity import ActivityObject, Signature -from .book import Book +from .book import Edition @dataclass(init=False) class Verb(ActivityObject): @@ -73,7 +73,7 @@ class Add(Verb): @dataclass(init=False) class AddBook(Verb): '''Add activity that's aware of the book obj ''' - target: Book + target: Edition type: str = 'Add' diff --git a/bookwyrm/incoming.py b/bookwyrm/incoming.py index 9c8c28878..556c34a27 100644 --- a/bookwyrm/incoming.py +++ b/bookwyrm/incoming.py @@ -57,7 +57,6 @@ def shared_inbox(request): 'Announce': handle_boost, 'Add': { 'Edition': handle_add, - 'Work': handle_add, }, 'Undo': { 'Follow': handle_unfollow, diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index b8efc71d0..5e12f5d56 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -283,6 +283,8 @@ class TagField(ManyToManyField): for link_json in value: link = activitypub.Link(**link_json) tag_type = link.type if link.type != 'Mention' else 'Person' + if tag_type == 'Book': + tag_type = 'Edition' if tag_type != self.related_model.activity_serializer.type: # tags can contain multiple types continue diff --git a/bookwyrm/models/shelf.py b/bookwyrm/models/shelf.py index 68f3614fb..69df43b4c 100644 --- a/bookwyrm/models/shelf.py +++ b/bookwyrm/models/shelf.py @@ -3,7 +3,7 @@ import re from django.db import models from bookwyrm import activitypub -from .base_model import BookWyrmModel +from .base_model import ActivitypubMixin, BookWyrmModel from .base_model import OrderedCollectionMixin from . import fields @@ -51,7 +51,7 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel): unique_together = ('user', 'identifier') -class ShelfBook(BookWyrmModel): +class ShelfBook(ActivitypubMixin, BookWyrmModel): ''' many to many join table for books and shelves ''' book = fields.ForeignKey( 'Edition', on_delete=models.PROTECT, activitypub_field='object') diff --git a/bookwyrm/tests/test_incoming.py b/bookwyrm/tests/test_incoming.py index d8e85ef2a..a317ef714 100644 --- a/bookwyrm/tests/test_incoming.py +++ b/bookwyrm/tests/test_incoming.py @@ -433,6 +433,28 @@ class Incoming(TestCase): boosted_status=self.status, user=self.remote_user) incoming.handle_unboost(activity) + + def test_handle_add_book(self): + ''' shelving a book ''' + book = models.Edition.objects.create( + title='Test', remote_id='https://bookwyrm.social/book/37292') + shelf = models.Shelf.objects.create( + user=self.remote_user, name='Test Shelf') + shelf.remote_id = 'https://bookwyrm.social/user/mouse/shelf/to-read' + shelf.save() + + activity = { + "id": "https://bookwyrm.social/shelfbook/6189#add", + "type": "Add", + "actor": "hhttps://example.com/users/rat", + "object": "https://bookwyrm.social/book/37292", + "target": "https://bookwyrm.social/user/mouse/shelf/to-read", + "@context": "https://www.w3.org/ns/activitystreams" + } + incoming.handle_add(activity) + self.assertEqual(shelf.books.first(), book) + + def test_handle_update_user(self): ''' update an existing user ''' datafile = pathlib.Path(__file__).parent.joinpath( diff --git a/bw-dev b/bw-dev index 53c8e52d9..bf5e8f758 100755 --- a/bw-dev +++ b/bw-dev @@ -57,7 +57,8 @@ case "$1" in clean ;; makemigrations) - execweb python manage.py makemigrations + shift 1 + execweb python manage.py makemigrations "$@" ;; migrate) execweb python manage.py rename_app fedireads bookwyrm