From a5dcc0e5e4759d71d7a7aeacd644413f3668ba01 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 28 Aug 2021 12:08:24 -0700 Subject: [PATCH] Support multiple possible fields that indicate user ownership --- bookwyrm/models/fields.py | 3 ++- bookwyrm/tests/models/test_user_model.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 76cedea0..ef0f3746 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -226,7 +226,8 @@ class PrivacyField(ActivitypubFieldMixin, models.CharField): cc = data.cc # we need to figure out who this is to get their followers link - user = activitypub.resolve_remote_id(data.attributedTo, model="User") + user_field = "attributedTo" if hasattr(data, "attributedTo") else "owner" + user = activitypub.resolve_remote_id(getattr(data, user_field), model="User") if to == [self.public]: setattr(instance, self.name, "public") diff --git a/bookwyrm/tests/models/test_user_model.py b/bookwyrm/tests/models/test_user_model.py index f717b807..230c503b 100644 --- a/bookwyrm/tests/models/test_user_model.py +++ b/bookwyrm/tests/models/test_user_model.py @@ -11,6 +11,7 @@ from bookwyrm.settings import USE_HTTPS, DOMAIN # pylint: disable=missing-function-docstring class User(TestCase): protocol = "https://" if USE_HTTPS else "http://" + def setUp(self): with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"): self.user = models.User.objects.create_user(