forked from mirrors/bookwyrm
Merge pull request #616 from mouse-reeve/list-federation
Fixes bugs in how lists/shelves federate Adds
This commit is contained in:
commit
c7e7c56a89
5 changed files with 33 additions and 6 deletions
|
@ -16,7 +16,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, AddBook, Remove
|
from .verbs import Add, AddBook, AddListItem, Remove
|
||||||
|
|
||||||
# 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,
|
||||||
# so when an Activity comes in from outside, we can check if it's known
|
# so when an Activity comes in from outside, we can check if it's known
|
||||||
|
|
|
@ -65,6 +65,13 @@ class ActivityObject:
|
||||||
|
|
||||||
def to_model(self, model, instance=None, save=True):
|
def to_model(self, model, instance=None, save=True):
|
||||||
''' convert from an activity to a model instance '''
|
''' convert from an activity to a model instance '''
|
||||||
|
if self.type != model.activity_serializer.type:
|
||||||
|
raise ActivitySerializerError(
|
||||||
|
'Wrong activity type "%s" for activity of type "%s"' % \
|
||||||
|
(model.activity_serializer.type,
|
||||||
|
self.type)
|
||||||
|
)
|
||||||
|
|
||||||
if not isinstance(self, model.activity_serializer):
|
if not isinstance(self, model.activity_serializer):
|
||||||
raise ActivitySerializerError(
|
raise ActivitySerializerError(
|
||||||
'Wrong activity type "%s" for model "%s" (expects "%s")' % \
|
'Wrong activity type "%s" for model "%s" (expects "%s")' % \
|
||||||
|
|
|
@ -70,17 +70,26 @@ class Reject(Verb):
|
||||||
@dataclass(init=False)
|
@dataclass(init=False)
|
||||||
class Add(Verb):
|
class Add(Verb):
|
||||||
'''Add activity '''
|
'''Add activity '''
|
||||||
target: ActivityObject
|
target: str
|
||||||
|
object: ActivityObject
|
||||||
type: str = 'Add'
|
type: str = 'Add'
|
||||||
|
|
||||||
|
|
||||||
@dataclass(init=False)
|
@dataclass(init=False)
|
||||||
class AddBook(Verb):
|
class AddBook(Add):
|
||||||
'''Add activity that's aware of the book obj '''
|
'''Add activity that's aware of the book obj '''
|
||||||
target: Edition
|
object: Edition
|
||||||
type: str = 'Add'
|
type: str = 'Add'
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(init=False)
|
||||||
|
class AddListItem(AddBook):
|
||||||
|
'''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 '''
|
||||||
|
|
|
@ -319,8 +319,19 @@ def handle_add(activity):
|
||||||
#this is janky as heck but I haven't thought of a better solution
|
#this is janky as heck but I haven't thought of a better solution
|
||||||
try:
|
try:
|
||||||
activitypub.AddBook(**activity).to_model(models.ShelfBook)
|
activitypub.AddBook(**activity).to_model(models.ShelfBook)
|
||||||
|
return
|
||||||
except activitypub.ActivitySerializerError:
|
except activitypub.ActivitySerializerError:
|
||||||
activitypub.AddBook(**activity).to_model(models.Tag)
|
pass
|
||||||
|
try:
|
||||||
|
activitypub.AddListItem(**activity).to_model(models.ListItem)
|
||||||
|
return
|
||||||
|
except activitypub.ActivitySerializerError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
activitypub.AddBook(**activity).to_model(models.UserTag)
|
||||||
|
return
|
||||||
|
except activitypub.ActivitySerializerError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
|
|
|
@ -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.AddBook
|
activity_serializer = activitypub.AddListItem
|
||||||
object_field = 'book'
|
object_field = 'book'
|
||||||
collection_field = 'book_list'
|
collection_field = 'book_list'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue