mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-11 09:45:27 +00:00
Merge pull request #978 from bookwyrm-social/federation-bugs
Federation bugs
This commit is contained in:
commit
4a73894802
5 changed files with 31 additions and 9 deletions
|
@ -11,6 +11,7 @@ class Book(ActivityObject):
|
||||||
""" serializes an edition or work, abstract """
|
""" serializes an edition or work, abstract """
|
||||||
|
|
||||||
title: str
|
title: str
|
||||||
|
lastEditedBy: str = None
|
||||||
sortTitle: str = ""
|
sortTitle: str = ""
|
||||||
subtitle: str = ""
|
subtitle: str = ""
|
||||||
description: str = ""
|
description: str = ""
|
||||||
|
@ -64,6 +65,7 @@ class Author(ActivityObject):
|
||||||
""" author of a book """
|
""" author of a book """
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
|
lastEditedBy: str = None
|
||||||
born: str = None
|
born: str = None
|
||||||
died: str = None
|
died: str = None
|
||||||
aliases: List[str] = field(default_factory=lambda: [])
|
aliases: List[str] = field(default_factory=lambda: [])
|
||||||
|
|
|
@ -148,14 +148,18 @@ class ActivitypubMixin:
|
||||||
mentions = self.recipients if hasattr(self, "recipients") else []
|
mentions = self.recipients if hasattr(self, "recipients") else []
|
||||||
|
|
||||||
# we always send activities to explicitly mentioned users' inboxes
|
# we always send activities to explicitly mentioned users' inboxes
|
||||||
recipients = [u.inbox for u in mentions or []]
|
recipients = [u.inbox for u in mentions or [] if not u.local]
|
||||||
|
|
||||||
# unless it's a dm, all the followers should receive the activity
|
# unless it's a dm, all the followers should receive the activity
|
||||||
if privacy != "direct":
|
if privacy != "direct":
|
||||||
# we will send this out to a subset of all remote users
|
# we will send this out to a subset of all remote users
|
||||||
queryset = user_model.viewer_aware_objects(user).filter(
|
queryset = (
|
||||||
|
user_model.viewer_aware_objects(user)
|
||||||
|
.filter(
|
||||||
local=False,
|
local=False,
|
||||||
)
|
)
|
||||||
|
.distinct()
|
||||||
|
)
|
||||||
# filter users first by whether they're using the desired software
|
# filter users first by whether they're using the desired software
|
||||||
# this lets us send book updates only to other bw servers
|
# this lets us send book updates only to other bw servers
|
||||||
if software:
|
if software:
|
||||||
|
@ -175,7 +179,7 @@ class ActivitypubMixin:
|
||||||
"inbox", flat=True
|
"inbox", flat=True
|
||||||
)
|
)
|
||||||
recipients += list(shared_inboxes) + list(inboxes)
|
recipients += list(shared_inboxes) + list(inboxes)
|
||||||
return recipients
|
return list(set(recipients))
|
||||||
|
|
||||||
def to_activity_dataclass(self):
|
def to_activity_dataclass(self):
|
||||||
""" convert from a model to an activity """
|
""" convert from a model to an activity """
|
||||||
|
|
|
@ -26,7 +26,11 @@ class BookDataModel(ObjectMixin, BookWyrmModel):
|
||||||
max_length=255, blank=True, null=True, deduplication_field=True
|
max_length=255, blank=True, null=True, deduplication_field=True
|
||||||
)
|
)
|
||||||
|
|
||||||
last_edited_by = models.ForeignKey("User", on_delete=models.PROTECT, null=True)
|
last_edited_by = fields.ForeignKey(
|
||||||
|
"User",
|
||||||
|
on_delete=models.PROTECT,
|
||||||
|
null=True,
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
""" can't initialize this model, that wouldn't make sense """
|
""" can't initialize this model, that wouldn't make sense """
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"id": "https://bookwyrm.social/book/5989",
|
"id": "https://bookwyrm.social/book/5989",
|
||||||
|
"lastEditedBy": "https://example.com/users/rat",
|
||||||
"type": "Edition",
|
"type": "Edition",
|
||||||
"authors": [
|
"authors": [
|
||||||
"https://bookwyrm.social/author/417"
|
"https://bookwyrm.social/author/417"
|
||||||
|
|
|
@ -23,6 +23,16 @@ class InboxUpdate(TestCase):
|
||||||
)
|
)
|
||||||
self.local_user.remote_id = "https://example.com/user/mouse"
|
self.local_user.remote_id = "https://example.com/user/mouse"
|
||||||
self.local_user.save(broadcast=False)
|
self.local_user.save(broadcast=False)
|
||||||
|
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||||
|
self.remote_user = models.User.objects.create_user(
|
||||||
|
"rat",
|
||||||
|
"rat@rat.com",
|
||||||
|
"ratword",
|
||||||
|
local=False,
|
||||||
|
remote_id="https://example.com/users/rat",
|
||||||
|
inbox="https://example.com/users/rat/inbox",
|
||||||
|
outbox="https://example.com/users/rat/outbox",
|
||||||
|
)
|
||||||
|
|
||||||
self.create_json = {
|
self.create_json = {
|
||||||
"id": "hi",
|
"id": "hi",
|
||||||
|
@ -34,7 +44,7 @@ class InboxUpdate(TestCase):
|
||||||
}
|
}
|
||||||
models.SiteSettings.objects.create()
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_handle_update_list(self):
|
def test_update_list(self):
|
||||||
""" a new list """
|
""" a new list """
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
book_list = models.List.objects.create(
|
book_list = models.List.objects.create(
|
||||||
|
@ -68,7 +78,7 @@ class InboxUpdate(TestCase):
|
||||||
self.assertEqual(book_list.description, "summary text")
|
self.assertEqual(book_list.description, "summary text")
|
||||||
self.assertEqual(book_list.remote_id, "https://example.com/list/22")
|
self.assertEqual(book_list.remote_id, "https://example.com/list/22")
|
||||||
|
|
||||||
def test_handle_update_user(self):
|
def test_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
|
||||||
self.local_user.local = False
|
self.local_user.local = False
|
||||||
|
@ -94,7 +104,7 @@ class InboxUpdate(TestCase):
|
||||||
self.assertEqual(user.localname, "mouse")
|
self.assertEqual(user.localname, "mouse")
|
||||||
self.assertTrue(user.discoverable)
|
self.assertTrue(user.discoverable)
|
||||||
|
|
||||||
def test_handle_update_edition(self):
|
def test_update_edition(self):
|
||||||
""" update an existing edition """
|
""" update an existing edition """
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_edition.json")
|
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_edition.json")
|
||||||
bookdata = json.loads(datafile.read_bytes())
|
bookdata = json.loads(datafile.read_bytes())
|
||||||
|
@ -122,8 +132,9 @@ class InboxUpdate(TestCase):
|
||||||
)
|
)
|
||||||
book = models.Edition.objects.get(id=book.id)
|
book = models.Edition.objects.get(id=book.id)
|
||||||
self.assertEqual(book.title, "Piranesi")
|
self.assertEqual(book.title, "Piranesi")
|
||||||
|
self.assertEqual(book.last_edited_by, self.remote_user)
|
||||||
|
|
||||||
def test_handle_update_work(self):
|
def test_update_work(self):
|
||||||
""" update an existing edition """
|
""" update an existing edition """
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")
|
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")
|
||||||
bookdata = json.loads(datafile.read_bytes())
|
bookdata = json.loads(datafile.read_bytes())
|
||||||
|
|
Loading…
Reference in a new issue