Skip to content

Commit

Permalink
Merge branch 'main' into import-tombstone
Browse files Browse the repository at this point in the history
  • Loading branch information
hughrun authored Oct 21, 2024
2 parents a0dd613 + d16faac commit 3fb9b18
Show file tree
Hide file tree
Showing 49 changed files with 8,898 additions and 4,757 deletions.
10 changes: 3 additions & 7 deletions bookwyrm/activitypub/base_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,13 @@ def resolve_remote_id(

# load the data and create the object
try:
data = get_data(remote_id)
data = get_activitypub_data(remote_id)
except ConnectionError:
logger.info("Could not connect to host for remote_id: %s", remote_id)
return None
except requests.HTTPError as e:
if (e.response is not None) and e.response.status_code == 401:
# This most likely means it's a mastodon with secure fetch enabled.
data = get_activitypub_data(remote_id)
else:
logger.info("Could not connect to host for remote_id: %s", remote_id)
return None
logger.exception("HTTP error - remote_id: %s - error: %s", remote_id, e)
return None
# determine the model implicitly, if not provided
# or if it's a model with subclasses like Status, check again
if not model or hasattr(model.objects, "select_subclasses"):
Expand Down
10 changes: 9 additions & 1 deletion bookwyrm/templates/author/author.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1 class="title">{{ author.name }}</h1>
<meta itemprop="name" content="{{ author.name }}">

{% firstof author.aliases author.born author.died as details %}
{% firstof author.wikipedia_link author.website author.openlibrary_key author.inventaire_id author.isni author.isfdb as links %}
{% firstof author.wikipedia_link author.website author.openlibrary_key author.inventaire_id author.isni author.isfdb author.wikidata as links %}
{% if details or links %}
<div class="column is-3">
{% if details %}
Expand Down Expand Up @@ -73,6 +73,14 @@ <h2 class="title is-4">{% trans "External links" %}</h2>
</div>
{% endif %}

{% if author.wikidata %}
<div>
<a itemprop="sameAs" href="https://www.wikidata.org/wiki/{{ author.wikidata }}" rel="nofollow noopener noreferrer" target="_blank">
{% trans "View on Wikidata" %}
</a>
</div>
{% endif %}

{% if author.website %}
<div>
<a itemprop="sameAs" href="{{ author.website }}" rel="nofollow noopener noreferrer" target="_blank">
Expand Down
2 changes: 1 addition & 1 deletion bookwyrm/templates/notifications/items/link_domain.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
{% blocktrans trimmed count counter=notification.related_link_domains.count with display_count=notification.related_link_domains.count|intcomma %}
A new <a href="{{ path }}">link domain</a> needs review
{% plural %}
{{ display_count }} new <a href="{{ path }}">link domains</a> need moderation
{{ display_count }} new <a href="{{ path }}">link domains</a> need review
{% endblocktrans %}
{% endblock %}
5 changes: 3 additions & 2 deletions bookwyrm/templatetags/status_display.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" template filters """
from dateutil.relativedelta import relativedelta
from django import template
from django.conf import settings
from django.contrib.humanize.templatetags.humanize import naturaltime, naturalday
from django.template.loader import select_template
from django.utils import timezone
Expand Down Expand Up @@ -60,8 +61,8 @@ def get_published_date(date):
delta = relativedelta(now, date)
if delta.years:
return naturalday(date)
if delta.days:
return naturalday(date, "M j")
if delta.days or delta.months:
return naturalday(date, settings.MONTH_DAY_FORMAT)
return naturaltime(date)


Expand Down
54 changes: 54 additions & 0 deletions bookwyrm/tests/activitypub/test_base_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def setUp(self):
# don't try to load the user icon
del self.userdata["icon"]

remote_datafile = pathlib.Path(__file__).parent.joinpath(
"../data/ap_user_external.json"
)
self.remote_userdata = json.loads(remote_datafile.read_bytes())
del self.remote_userdata["icon"]

alias_datafile = pathlib.Path(__file__).parent.joinpath(
"../data/ap_user_aliased.json"
)
self.alias_userdata = json.loads(alias_datafile.read_bytes())
del self.alias_userdata["icon"]

image_path = pathlib.Path(__file__).parent.joinpath(
"../../static/images/default_avi.jpg"
)
Expand Down Expand Up @@ -118,6 +130,48 @@ def test_resolve_remote_id(self, *_):
self.assertEqual(result.remote_id, "https://example.com/user/mouse")
self.assertEqual(result.name, "MOUSE?? MOUSE!!")

@responses.activate
def test_resolve_remote_alias(self, *_):
"""look up or load user who has an unknown alias"""

self.assertEqual(models.User.objects.count(), 1)

# remote user with unknown user as an alias
responses.add(
responses.GET,
"https://example.com/user/moose",
json=self.alias_userdata,
status=200,
)

responses.add(
responses.GET,
"https://example.com/user/ali",
json=self.remote_userdata,
status=200,
)

with patch("bookwyrm.models.user.set_remote_server.delay"):
result = resolve_remote_id(
"https://example.com/user/moose", model=models.User
)

self.assertTrue(
models.User.objects.filter(
remote_id="https://example.com/user/moose"
).exists()
) # moose has been added to DB
self.assertTrue(
models.User.objects.filter(
remote_id="https://example.com/user/ali"
).exists()
) # Ali has been added to DB
self.assertIsInstance(result, models.User)
self.assertEqual(result.name, "moose?? moose!!")
alias = models.User.objects.last()
self.assertEqual(alias.name, "Ali As")
self.assertEqual(result.also_known_as.first(), alias) # Ali is alias of Moose

def test_to_model_invalid_model(self, *_):
"""catch mismatch between activity type and model type"""
instance = ActivityObject(id="a", type="b")
Expand Down
40 changes: 40 additions & 0 deletions bookwyrm/tests/data/ap_user_aliased.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"schema": "http://schema.org#",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value"
}
],
"id": "https://example.com/user/moose",
"type": "Person",
"preferredUsername": "moose",
"name": "moose?? moose!!",
"inbox": "https://example.com/user/moose/inbox",
"outbox": "https://example.com/user/moose/outbox",
"followers": "https://example.com/user/moose/followers",
"following": "https://example.com/user/moose/following",
"summary": "",
"publicKey": {
"id": "https://example.com/user/moose/#main-key",
"owner": "https://example.com/user/moose",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC6QisDrjOQvkRo/MqNmSYPwqtt\nCxg/8rCW+9jKbFUKvqjTeKVotEE85122v/DCvobCCdfQuYIFdVMk+dB1xJ0iPGPg\nyU79QHY22NdV9mFKA2qtXVVxb5cxpA4PlwOHM6PM/k8B+H09OUrop2aPUAYwy+vg\n+MXyz8bAXrIS1kq6fQIDAQAB\n-----END PUBLIC KEY-----"
},
"endpoints": {
"sharedInbox": "https://example.com/inbox"
},
"bookwyrmUser": true,
"manuallyApprovesFollowers": false,
"discoverable": false,
"alsoKnownAs": ["https://example.com/user/ali"],
"devices": "",
"tag": [],
"icon": {
"type": "Image",
"mediaType": "image/png",
"url": "https://example.com/images/avatars/AL-3-crop-50.png"
}
}
40 changes: 40 additions & 0 deletions bookwyrm/tests/data/ap_user_external.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"schema": "http://schema.org#",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value"
}
],
"id": "https://example.com/user/ali",
"type": "Person",
"preferredUsername": "alias",
"name": "Ali As",
"inbox": "https://example.com/user/ali/inbox",
"outbox": "https://example.com/user/ali/outbox",
"followers": "https://example.com/user/ali/followers",
"following": "https://example.com/user/ali/following",
"summary": "",
"publicKey": {
"id": "https://example.com/user/ali/#main-key",
"owner": "https://example.com/user/ali",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC6QisDrjOQvkRo/MqNmSYPwqtt\nCxg/8rCW+9jKbFUKvqjTeKVotEE85122v/DCvobCCdfQuYIFdVMk+dB1xJ0iPGPg\nyU79QHY22NdV9mFKA2qtXVVxb5cxpA4PlwOHM6PM/k8B+H09OUrop2aPUAYwy+vg\n+MXyz8bAXrIS1kq6fQIDAQAB\n-----END PUBLIC KEY-----"
},
"endpoints": {
"sharedInbox": "https://example.com/inbox"
},
"bookwyrmUser": true,
"manuallyApprovesFollowers": false,
"alsoKnownAs": [],
"discoverable": false,
"devices": "",
"tag": [],
"icon": {
"type": "Image",
"mediaType": "image/png",
"url": "https://example.com/images/avatars/ALIAS-2-crop-50.png"
}
}
15 changes: 14 additions & 1 deletion bookwyrm/tests/templatetags/test_status_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,17 @@ def test_get_published_date(self, *_):
2022, 1, 8, 0, 0, tzinfo=datetime.timezone.utc
)
result = status_display.get_published_date(date)
self.assertEqual(result, "Jan 1")
self.assertEqual(result, "January 1")

with patch("django.utils.timezone.now") as timezone_mock:
timezone_mock.return_value = datetime.datetime(
# bookwyrm-social#3365: bug with exact month deltas
2022,
3,
1,
0,
0,
tzinfo=datetime.timezone.utc,
)
result = status_display.get_published_date(date)
self.assertEqual(result, "January 1")
2 changes: 1 addition & 1 deletion bookwyrm/views/admin/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def post(self, request):
schedule, _ = IntervalSchedule.objects.get_or_create(
**schedule_form.cleaned_data
)
PeriodicTask.objects.get_or_create(
PeriodicTask.objects.update_or_create(
interval=schedule,
name="check-for-updates",
task="bookwyrm.models.site.check_for_updates_task",
Expand Down
Binary file modified locale/ca_ES/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 3fb9b18

Please sign in to comment.