Merge pull request #392 from mouse-reeve/incoming-shelve

Incoming shelve
This commit is contained in:
Mouse Reeve 2020-12-16 08:32:54 -08:00 committed by GitHub
commit cf78087bfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 6 deletions

View file

@ -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'

View file

@ -57,7 +57,6 @@ def shared_inbox(request):
'Announce': handle_boost,
'Add': {
'Edition': handle_add,
'Work': handle_add,
},
'Undo': {
'Follow': handle_unfollow,

View file

@ -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

View file

@ -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')

View file

@ -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(

3
bw-dev
View file

@ -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