From addcc59d7fa9eef940c26cd91669abc357730b12 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 15 Apr 2021 16:21:54 -0700 Subject: [PATCH 1/3] Makes cc fields optional Plus a bit of cleanup in comments and to: fields --- bookwyrm/activitypub/verbs.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/bookwyrm/activitypub/verbs.py b/bookwyrm/activitypub/verbs.py index c3c84ee5..f79afdca 100644 --- a/bookwyrm/activitypub/verbs.py +++ b/bookwyrm/activitypub/verbs.py @@ -1,4 +1,4 @@ -""" undo wrapper activity """ +""" activities that do things """ from dataclasses import dataclass, field from typing import List from django.apps import apps @@ -9,14 +9,13 @@ from .ordered_collection import CollectionItem @dataclass(init=False) class Verb(ActivityObject): - """generic fields for activities - maybe an unecessary level of - abstraction but w/e""" + """generic fields for activities """ actor: str object: ActivityObject def action(self): - """ usually we just want to save, this can be overridden as needed """ + """ usually we just want to update and save """ self.object.to_model() @@ -24,8 +23,8 @@ class Verb(ActivityObject): class Create(Verb): """ Create activity """ - to: List - cc: List + to: List[str] + cc: List[str] = field(default_factory=lambda: []) signature: Signature = None type: str = "Create" @@ -34,8 +33,8 @@ class Create(Verb): class Delete(Verb): """ Create activity """ - to: List - cc: List + to: List[str] + cc: List[str] = field(default_factory=lambda: []) type: str = "Delete" def action(self): @@ -48,7 +47,7 @@ class Delete(Verb): class Update(Verb): """ Update activity """ - to: List + to: List[str] type: str = "Update" def action(self): From 2f493336adf73df6aa344c33732532d90e6e2719 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 15 Apr 2021 16:24:05 -0700 Subject: [PATCH 2/3] Don't try to delete nonexistant objects --- bookwyrm/activitypub/verbs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bookwyrm/activitypub/verbs.py b/bookwyrm/activitypub/verbs.py index f79afdca..23032a87 100644 --- a/bookwyrm/activitypub/verbs.py +++ b/bookwyrm/activitypub/verbs.py @@ -40,7 +40,9 @@ class Delete(Verb): def action(self): """ find and delete the activity object """ obj = self.object.to_model(save=False, allow_create=False) - obj.delete() + if obj: + obj.delete() + # if we can't find it, we don't need to delete it because we don't have it @dataclass(init=False) From 220fb926c927d0d7ab4ee02d6a6032fac9c3edfb Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 15 Apr 2021 16:35:04 -0700 Subject: [PATCH 3/3] Rename Image to Document --- bookwyrm/activitypub/__init__.py | 2 +- bookwyrm/activitypub/book.py | 4 ++-- bookwyrm/activitypub/image.py | 2 +- bookwyrm/activitypub/note.py | 4 ++-- bookwyrm/activitypub/person.py | 4 ++-- bookwyrm/models/attachment.py | 2 +- bookwyrm/models/fields.py | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bookwyrm/activitypub/__init__.py b/bookwyrm/activitypub/__init__.py index c67c5dca..71658455 100644 --- a/bookwyrm/activitypub/__init__.py +++ b/bookwyrm/activitypub/__init__.py @@ -5,7 +5,7 @@ import sys from .base_activity import ActivityEncoder, Signature, naive_parse from .base_activity import Link, Mention from .base_activity import ActivitySerializerError, resolve_remote_id -from .image import Image +from .image import Document from .note import Note, GeneratedNote, Article, Comment, Quotation from .note import Review, Rating from .note import Tombstone diff --git a/bookwyrm/activitypub/book.py b/bookwyrm/activitypub/book.py index 7e552b0a..7615adcf 100644 --- a/bookwyrm/activitypub/book.py +++ b/bookwyrm/activitypub/book.py @@ -3,7 +3,7 @@ from dataclasses import dataclass, field from typing import List from .base_activity import ActivityObject -from .image import Image +from .image import Document @dataclass(init=False) @@ -28,7 +28,7 @@ class Book(ActivityObject): librarythingKey: str = "" goodreadsKey: str = "" - cover: Image = None + cover: Document = None type: str = "Book" diff --git a/bookwyrm/activitypub/image.py b/bookwyrm/activitypub/image.py index 931de977..42598422 100644 --- a/bookwyrm/activitypub/image.py +++ b/bookwyrm/activitypub/image.py @@ -4,7 +4,7 @@ from .base_activity import ActivityObject @dataclass(init=False) -class Image(ActivityObject): +class Document(ActivityObject): """ image block """ url: str diff --git a/bookwyrm/activitypub/note.py b/bookwyrm/activitypub/note.py index a739eafa..e1a42958 100644 --- a/bookwyrm/activitypub/note.py +++ b/bookwyrm/activitypub/note.py @@ -4,7 +4,7 @@ from typing import Dict, List from django.apps import apps from .base_activity import ActivityObject, Link -from .image import Image +from .image import Document @dataclass(init=False) @@ -32,7 +32,7 @@ class Note(ActivityObject): inReplyTo: str = "" summary: str = "" tag: List[Link] = field(default_factory=lambda: []) - attachment: List[Image] = field(default_factory=lambda: []) + attachment: List[Document] = field(default_factory=lambda: []) sensitive: bool = False type: str = "Note" diff --git a/bookwyrm/activitypub/person.py b/bookwyrm/activitypub/person.py index 9231bd95..550fc7bd 100644 --- a/bookwyrm/activitypub/person.py +++ b/bookwyrm/activitypub/person.py @@ -3,7 +3,7 @@ from dataclasses import dataclass, field from typing import Dict from .base_activity import ActivityObject -from .image import Image +from .image import Document @dataclass(init=False) @@ -28,7 +28,7 @@ class Person(ActivityObject): endpoints: Dict = None name: str = None summary: str = None - icon: Image = field(default_factory=lambda: {}) + icon: Document = field(default_factory=lambda: {}) bookwyrmUser: bool = False manuallyApprovesFollowers: str = False discoverable: str = False diff --git a/bookwyrm/models/attachment.py b/bookwyrm/models/attachment.py index 8d2238a1..eaeca11e 100644 --- a/bookwyrm/models/attachment.py +++ b/bookwyrm/models/attachment.py @@ -33,4 +33,4 @@ class Image(Attachment): ) caption = fields.TextField(null=True, blank=True, activitypub_field="name") - activity_serializer = activitypub.Image + activity_serializer = activitypub.Document diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index e034d59e..2aefae51 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -336,7 +336,7 @@ def image_serializer(value, alt): else: return None url = "https://%s%s" % (DOMAIN, url) - return activitypub.Image(url=url, name=alt) + return activitypub.Document(url=url, name=alt) class ImageField(ActivitypubFieldMixin, models.ImageField):