gotta simplify the add activity

This commit is contained in:
Mouse Reeve 2021-02-23 15:51:02 -08:00
parent cbccdea468
commit 6e6bcb2f48
4 changed files with 80 additions and 10 deletions

View file

@ -15,7 +15,7 @@ from .response import ActivitypubResponse
from .book import Edition, Work, Author from .book import Edition, Work, Author
from .verbs import Create, Delete, Undo, Update from .verbs import Create, Delete, Undo, Update
from .verbs import Follow, Accept, Reject, Block from .verbs import Follow, Accept, Reject, Block
from .verbs import Add, AddListItem, Remove from .verbs import Add, Remove
from .verbs import Announce, Like from .verbs import Announce, Like
# this creates a list of all the Activity types that we can serialize, # this creates a list of all the Activity types that we can serialize,

View file

@ -121,6 +121,9 @@ class Add(Verb):
target: str target: str
object: Edition object: Edition
type: str = 'Add' type: str = 'Add'
notes: str = None
order: int = 0
approved: bool = True
def action(self): def action(self):
''' add obj to collection ''' ''' add obj to collection '''
@ -131,14 +134,6 @@ class Add(Verb):
self.to_model(model=model) self.to_model(model=model)
@dataclass(init=False)
class AddListItem(Add):
'''Add activity that's aware of the book obj '''
notes: str = None
order: int = 0
approved: bool = True
@dataclass(init=False) @dataclass(init=False)
class Remove(Verb): class Remove(Verb):
'''Remove activity ''' '''Remove activity '''

View file

@ -68,7 +68,7 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
order = fields.IntegerField(blank=True, null=True) order = fields.IntegerField(blank=True, null=True)
endorsement = models.ManyToManyField('User', related_name='endorsers') endorsement = models.ManyToManyField('User', related_name='endorsers')
activity_serializer = activitypub.AddListItem activity_serializer = activitypub.Add
object_field = 'book' object_field = 'book'
collection_field = 'book_list' collection_field = 'book_list'

View file

@ -612,6 +612,81 @@ class Inbox(TestCase):
self.assertEqual(shelf.books.first(), book) self.assertEqual(shelf.books.first(), book)
# def test_handle_tag_book(self):
# ''' tagging a book '''
# work = models.Work.objects.create(title='work title')
# book = models.Edition.objects.create(
# title='Test', remote_id='https://bookwyrm.social/book/37292',
# parent_work=work)
#
# activity = {
# "id": "https://bookwyrm.social/shelfbook/6189#add",
# "type": "Add",
# "actor": "https://example.com/users/rat",
# "object": {
# "type": "Edition",
# "title": "Test Title",
# "work": work.remote_id,
# "id": "https://bookwyrm.social/book/37292",
# },
# "target": "",
# "@context": "https://www.w3.org/ns/activitystreams"
# }
# views.inbox.activity_task(activity)
# self.assertEqual(shelf.books.first(), book)
@responses.activate
def test_handle_add_book_to_list(self):
''' listing a book '''
work = models.Work.objects.create(title='work title')
book = models.Edition.objects.create(
title='Test', remote_id='https://bookwyrm.social/book/37292',
parent_work=work)
responses.add(
responses.GET,
'https://bookwyrm.social/user/mouse/list/to-read',
json={
"id": "https://example.com/list/22",
"type": "BookList",
"totalItems": 1,
"first": "https://example.com/list/22?page=1",
"last": "https://example.com/list/22?page=1",
"name": "Test List",
"owner": "https://example.com/user/mouse",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://example.com/user/mouse/followers"
],
"summary": "summary text",
"curation": "curated",
"@context": "https://www.w3.org/ns/activitystreams"
}
)
activity = {
"id": "https://bookwyrm.social/listbook/6189#add",
"type": "Add",
"actor": "https://example.com/users/rat",
"object": {
"type": "Edition",
"title": "Test Title",
"work": work.remote_id,
"id": "https://bookwyrm.social/book/37292",
},
"target": "https://bookwyrm.social/user/mouse/list/to-read",
"@context": "https://www.w3.org/ns/activitystreams"
}
views.inbox.activity_task(activity)
booklist = models.List.objects.get()
self.assertEqual(booklist.name, 'Test List')
self.assertEqual(booklist.books.first(), book)
def test_handle_update_user(self): def test_handle_update_user(self):
''' update an existing user ''' ''' update an existing user '''
# we only do this with remote users # we only do this with remote users