From 9d52e3cf273e1fa97051b23fbc4508b2fb574005 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 27 Nov 2021 18:32:50 +1100 Subject: [PATCH 01/57] add ostatus subscribe to webfinger links --- bookwyrm/views/wellknown.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bookwyrm/views/wellknown.py b/bookwyrm/views/wellknown.py index 04aa88bf2..c9b1c1299 100644 --- a/bookwyrm/views/wellknown.py +++ b/bookwyrm/views/wellknown.py @@ -30,6 +30,10 @@ def webfinger(request): "rel": "self", "type": "application/activity+json", "href": user.remote_id, + }, + { + "rel": "http://ostatus.org/schema/1.0/subscribe", + "template": f"https://{DOMAIN}/ostatus_subscribe?acct={{uri}}" } ], } From f7c8f121b9c95f0c4ef7e68a358736f1dd209067 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 12:43:29 +1100 Subject: [PATCH 02/57] add remote follow ostatus templates --- bookwyrm/templates/ostatus/ostatus_error.html | 57 ++++++++++ .../templates/ostatus/ostatus_subscribe.html | 48 ++++++++ bookwyrm/templates/ostatus/template.html | 106 ++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 bookwyrm/templates/ostatus/ostatus_error.html create mode 100644 bookwyrm/templates/ostatus/ostatus_subscribe.html create mode 100644 bookwyrm/templates/ostatus/template.html diff --git a/bookwyrm/templates/ostatus/ostatus_error.html b/bookwyrm/templates/ostatus/ostatus_error.html new file mode 100644 index 000000000..5fbc8e945 --- /dev/null +++ b/bookwyrm/templates/ostatus/ostatus_error.html @@ -0,0 +1,57 @@ +{% extends 'ostatus/template.html' %} +{% load i18n %} +{% load utilities %} +{% load markdown %} + +{% block title %} +{% if not request.user.is_authenticated %} +{% trans "Log in to " %} +{% else %} +{% trans "Error following from " %} +{% endif %} +{% endblock %} + +{% block heading %} +{% if not request.user.is_authenticated %} +Let's log in first... +{% else %} +Uh oh... +{% endif %} +{% endblock %} + +{% block content %} +
+ {% if not request.user.is_authenticated %} + + {% elif error == 'ostatus_subscribe' %} +
+

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

+

{% trans 'Check you have the correct username before trying again.' %}

+
+ {% endif %} +
+{% endblock %} diff --git a/bookwyrm/templates/ostatus/ostatus_subscribe.html b/bookwyrm/templates/ostatus/ostatus_subscribe.html new file mode 100644 index 000000000..7e929202e --- /dev/null +++ b/bookwyrm/templates/ostatus/ostatus_subscribe.html @@ -0,0 +1,48 @@ +{% extends 'ostatus/template.html' %} +{% load i18n %} +{% load utilities %} +{% load markdown %} + +{% if error or not request.user.is_authenticated %} + {% include 'ostatus/ostatus_error.html' %} +{% else %} + +{% block title %}{% trans "Follow from " %}{% endblock %} + +{% block heading %}Follow from {{ site.name }}{% endblock %} + +{% block content %} +
+
+ +
+ {% if user.summary %} + {{ user.summary|to_markdown|safe|truncatechars_html:120 }} + {% else %} {% endif %} +
+
+
+{% endblock %} + +{% endif %} diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html new file mode 100644 index 000000000..2e8ee7b3c --- /dev/null +++ b/bookwyrm/templates/ostatus/template.html @@ -0,0 +1,106 @@ +{% load layout %} +{% load i18n %} +{% load static %} +{% load utilities %} +{% load markdown %} + + + + + {% block title %}{% endblock %}{{ site.name }} + + + + + + + + + + {% if preview_images_enabled is True %} + + {% else %} + + {% endif %} + + + + + + {% block opengraph_images %} + {% include 'snippets/opengraph_images.html' %} + {% endblock %} + + + + + + + +
+
+ {% block content%}{% endblock %} +
+
+ + + + + + + + + + + +{% block scripts %}{% endblock %} + + From d05e100421eaf53946e6cd420b2d32f45b35ab2f Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 13:28:58 +1100 Subject: [PATCH 03/57] update ostatus templates --- bookwyrm/templates/ostatus/ostatus_error.html | 19 ------------- .../templates/ostatus/ostatus_subscribe.html | 28 ++++++++++++++----- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/bookwyrm/templates/ostatus/ostatus_error.html b/bookwyrm/templates/ostatus/ostatus_error.html index 5fbc8e945..de2ba988b 100644 --- a/bookwyrm/templates/ostatus/ostatus_error.html +++ b/bookwyrm/templates/ostatus/ostatus_error.html @@ -1,23 +1,4 @@ -{% extends 'ostatus/template.html' %} {% load i18n %} -{% load utilities %} -{% load markdown %} - -{% block title %} -{% if not request.user.is_authenticated %} -{% trans "Log in to " %} -{% else %} -{% trans "Error following from " %} -{% endif %} -{% endblock %} - -{% block heading %} -{% if not request.user.is_authenticated %} -Let's log in first... -{% else %} -Uh oh... -{% endif %} -{% endblock %} {% block content %}
diff --git a/bookwyrm/templates/ostatus/ostatus_subscribe.html b/bookwyrm/templates/ostatus/ostatus_subscribe.html index 7e929202e..9d87d8ef8 100644 --- a/bookwyrm/templates/ostatus/ostatus_subscribe.html +++ b/bookwyrm/templates/ostatus/ostatus_subscribe.html @@ -3,15 +3,30 @@ {% load utilities %} {% load markdown %} -{% if error or not request.user.is_authenticated %} - {% include 'ostatus/ostatus_error.html' %} +{% block title %} +{% if not request.user.is_authenticated %} +{% trans "Log in to " %} +{% elif error %} +{% trans "Error following from " %} {% else %} +{% trans "Follow from " %} +{% endif %} +{% endblock %} -{% block title %}{% trans "Follow from " %}{% endblock %} - -{% block heading %}Follow from {{ site.name }}{% endblock %} +{% block heading %} +{% if not request.user.is_authenticated %} +{% trans "Let's log in first..." %} +{% elif error %} +{% trans 'Uh oh...' %} +{% else %} +{% blocktrans %}Follow from {{ site.name }}{% endblocktrans %} +{% endif %} +{% endblock %} {% block content %} +{% if error or not request.user.is_authenticated %} + {% include 'ostatus/ostatus_error.html' with error=error user=user account=account %} +{% else %}
@@ -43,6 +58,5 @@
-{% endblock %} - {% endif %} +{% endblock %} From 610114b4ebfcd27cde9f76244d559c226e4d78b5 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 16:54:25 +1100 Subject: [PATCH 04/57] rearrange ostatus templates --- .../{ostatus_error.html => error.html} | 14 +++++++- ...{ostatus_subscribe.html => subscribe.html} | 7 ++-- bookwyrm/templates/ostatus/success.html | 32 +++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) rename bookwyrm/templates/ostatus/{ostatus_error.html => error.html} (71%) rename bookwyrm/templates/ostatus/{ostatus_subscribe.html => subscribe.html} (86%) create mode 100644 bookwyrm/templates/ostatus/success.html diff --git a/bookwyrm/templates/ostatus/ostatus_error.html b/bookwyrm/templates/ostatus/error.html similarity index 71% rename from bookwyrm/templates/ostatus/ostatus_error.html rename to bookwyrm/templates/ostatus/error.html index de2ba988b..b6e858e24 100644 --- a/bookwyrm/templates/ostatus/ostatus_error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -29,10 +29,22 @@
{% elif error == 'ostatus_subscribe' %} -
+

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

{% trans 'Check you have the correct username before trying again.' %}

+ {% elif error == 'is_blocked' %} +
+

{% blocktrans %}You have blocked {{ account }}{% endblocktrans %}

+
+ {% elif error == 'already_following' %} +
+

{% blocktrans %}You are already following {{ account }}{% endblocktrans %}

+
+ {% elif error == 'already_requested' %} +
+

{% blocktrans %}You have already requested to follow {{ account }}{% endblocktrans %}

+
{% endif %}
{% endblock %} diff --git a/bookwyrm/templates/ostatus/ostatus_subscribe.html b/bookwyrm/templates/ostatus/subscribe.html similarity index 86% rename from bookwyrm/templates/ostatus/ostatus_subscribe.html rename to bookwyrm/templates/ostatus/subscribe.html index 9d87d8ef8..e64be6029 100644 --- a/bookwyrm/templates/ostatus/ostatus_subscribe.html +++ b/bookwyrm/templates/ostatus/subscribe.html @@ -25,7 +25,7 @@ {% block content %} {% if error or not request.user.is_authenticated %} - {% include 'ostatus/ostatus_error.html' with error=error user=user account=account %} + {% include 'ostatus/error.html' with error=error user=user account=account %} {% else %}
@@ -45,13 +45,14 @@ @{{ user|username }} -
+ {% csrf_token %} +
-
+
{% if user.summary %} {{ user.summary|to_markdown|safe|truncatechars_html:120 }} {% else %} {% endif %} diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html new file mode 100644 index 000000000..10b4409f3 --- /dev/null +++ b/bookwyrm/templates/ostatus/success.html @@ -0,0 +1,32 @@ +{% extends 'ostatus/template.html' %} +{% load i18n %} +{% load utilities %} + +{% block content %} + +{% endblock %} From e275b98183cdaed4e33d3e11e51307aa63187def Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 16:56:21 +1100 Subject: [PATCH 05/57] ostatus remote follow views --- bookwyrm/urls.py | 3 ++ bookwyrm/views/__init__.py | 2 +- bookwyrm/views/follow.py | 82 +++++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 514bb7e60..79e6e2a98 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -44,6 +44,7 @@ urlpatterns = [ re_path(r"^api/v1/instance/?$", views.instance_info), re_path(r"^api/v1/instance/peers/?$", views.peers), re_path(r"^opensearch.xml$", views.opensearch, name="opensearch"), + re_path(r"^ostatus_subscribe/?$", views.ostatus_follow_request), # polling updates re_path("^api/updates/notifications/?$", views.get_notification_count), re_path("^api/updates/stream/(?P[a-z]+)/?$", views.get_unread_status_count), @@ -450,4 +451,6 @@ urlpatterns = [ re_path(r"^unfollow/?$", views.unfollow, name="unfollow"), re_path(r"^accept-follow-request/?$", views.accept_follow_request), re_path(r"^delete-follow-request/?$", views.delete_follow_request), + # re_path(r"^ostatus_follow/?$", views.remote_follow), + re_path(r"^ostatus_success/?$", views.ostatus_follow_success, name="ostatus-success"), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index d79de4248..034b1830a 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -58,7 +58,7 @@ from .author import Author, EditAuthor from .directory import Directory from .discover import Discover from .feed import DirectMessage, Feed, Replies, Status -from .follow import follow, unfollow +from .follow import follow, unfollow, ostatus_follow_request, ostatus_follow_success from .follow import accept_follow_request, delete_follow_request from .get_started import GetStartedBooks, GetStartedProfile, GetStartedUsers from .goal import Goal, hide_goal diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 7d91ce5b4..471fe3079 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -1,11 +1,14 @@ """ views for actions you can take in the application """ +import urllib.parse +import re from django.contrib.auth.decorators import login_required from django.db import IntegrityError from django.shortcuts import get_object_or_404, redirect +from django.template.response import TemplateResponse from django.views.decorators.http import require_POST from bookwyrm import models -from .helpers import get_user_from_username +from .helpers import get_user_from_username, handle_remote_webfinger @login_required @@ -23,9 +26,13 @@ def follow(request): except IntegrityError: pass + if request.GET.get("next"): + return redirect(request.GET.get("next", "/")) + return redirect(to_follow.local_path) + @login_required @require_POST def unfollow(request): @@ -84,3 +91,76 @@ def delete_follow_request(request): follow_request.delete() return redirect(f"/user/{request.user.localname}") + +def ostatus_follow_request(request): + """prepare an outgoing remote follow request""" + + # parse the acct URI into a user string + uri = urllib.parse.unquote(request.GET.get("acct")) + username_parts = re.search("(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri) + account = f"{username_parts[2]}@{username_parts[1]}" + user = handle_remote_webfinger(account) + error = None + + if user is None or user == "": + error = "ostatus_subscribe" + + if bool(user) and user in request.user.blocks.all(): + error = "is_blocked" + + if hasattr(user, "followers") and request.user in user.followers.all(): + error = "already_following" + + if hasattr(user, "follower_requests") and request.user in user.follower_requests.all(): + error = "already_requested" + + data = { + "account": account, + "user": user, + "error": error + } + + return TemplateResponse(request, "ostatus/subscribe.html", data) + + +@login_required +def ostatus_follow_success(request): + """display success message for remote follow""" + user = get_user_from_username(request.user, request.GET.get("following")) + data = { + "account": user.name, + "user": user, + "error": None + } + return TemplateResponse(request, "ostatus/success.html", data) + +@login_required +@require_POST +def remote_follow(request): + """complete an incoming remote follow request""" + + # this is triggered from remote follow form + # attempt the follow request + # on success [[return success page]] + # on fail return [[ostatus_error]] + + +""" +REQUEST TO FOLLOW FROM REMOTE ACCOUNT +1. click remote follow button [default checked option to open new window] +2. popup new small window +3. enter user acct to follow from (user@domain.tld) and submit form +5. GET {base_url}/.well-known/webfinger/?resource=acct:{user@domain.tld} +6. parse json for links +6.1 rel="http://ostatus.org/schema/1.0/subscribe" and return 'template' +6.2 rel="self" and return href +7. replace '{uri}' in the returned string with self.href +8. GET the URI at 6.1 + +REQUEST TO FOLLOW FROM LOCAL ACCOUNT +1. receive request to /ostatus_subscribe?acct={uri} +2. check user is logged in and present confirmation screen (remote_follow_request) +3. On confirmation, 3. parse user into info needed for a normal follow +4. send follow request, on 200 response display success else display error (remote_follow) +5. Include button inviting to close window +""" From 2e428e6ea1687c15c87856f682a572cdff098e9c Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 20:08:54 +1100 Subject: [PATCH 06/57] add remote follow templates --- bookwyrm/templates/ostatus/remote_follow.html | 43 +++++++++++++++++++ .../ostatus/remote_follow_button.html | 16 +++++++ 2 files changed, 59 insertions(+) create mode 100644 bookwyrm/templates/ostatus/remote_follow.html create mode 100644 bookwyrm/templates/ostatus/remote_follow_button.html diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html new file mode 100644 index 000000000..ea8881e42 --- /dev/null +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -0,0 +1,43 @@ +{% extends 'ostatus/template.html' %} +{% load i18n %} +{% load utilities %} + +{% block content %} +
+
+

{% blocktrans %}Follow {{ user.display_name }} on the fediverse{% endblocktrans %}

+
+ +
+
+
+
+ {% csrf_token %} + + + +
+
+
+
+{% endblock %} diff --git a/bookwyrm/templates/ostatus/remote_follow_button.html b/bookwyrm/templates/ostatus/remote_follow_button.html new file mode 100644 index 000000000..4789d3064 --- /dev/null +++ b/bookwyrm/templates/ostatus/remote_follow_button.html @@ -0,0 +1,16 @@ +{% load i18n %} +{% if request.user == user %} +{% else %} + +
+
+
+ {% csrf_token %} + + +
+
+
+{% endif %} From 6e7d23c1aec60317e7989aaf5cafa08112d49cc0 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 20:09:29 +1100 Subject: [PATCH 07/57] add remote follow button --- bookwyrm/templates/user/layout.html | 3 +++ bookwyrm/urls.py | 3 ++- bookwyrm/views/__init__.py | 2 +- bookwyrm/views/follow.py | 34 +++++++++++++++-------------- bookwyrm/views/helpers.py | 27 +++++++++++++++++++++++ 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/bookwyrm/templates/user/layout.html b/bookwyrm/templates/user/layout.html index d7557ae7b..03e3dfce8 100755 --- a/bookwyrm/templates/user/layout.html +++ b/bookwyrm/templates/user/layout.html @@ -39,6 +39,9 @@ {% if not is_self and request.user.is_authenticated %} {% include 'snippets/follow_button.html' with user=user %} {% endif %} + {% if not is_self %} + {% include 'ostatus/remote_follow_button.html' with user=user %} + {% endif %} {% if is_self and user.follower_requests.all %}
diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 2e8ee7b3c..cb922f9bd 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -92,7 +92,6 @@ - diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 48fe0f6cc..45837ec13 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -453,5 +453,7 @@ urlpatterns = [ re_path(r"^delete-follow-request/?$", views.delete_follow_request), re_path(r"^ostatus_follow/?$", views.remote_follow, name="remote-follow"), re_path(r"^remote_follow/?$", views.remote_follow_page, name="remote-follow-page"), - re_path(r"^ostatus_success/?$", views.ostatus_follow_success, name="ostatus-success"), + re_path( + r"^ostatus_success/?$", views.ostatus_follow_success, name="ostatus-success" + ), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 3b5bf8232..4a92578c2 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -58,7 +58,14 @@ from .author import Author, EditAuthor from .directory import Directory from .discover import Discover from .feed import DirectMessage, Feed, Replies, Status -from .follow import follow, unfollow, ostatus_follow_request, ostatus_follow_success, remote_follow, remote_follow_page +from .follow import ( + follow, + unfollow, + ostatus_follow_request, + ostatus_follow_success, + remote_follow, + remote_follow_page, +) from .follow import accept_follow_request, delete_follow_request from .get_started import GetStartedBooks, GetStartedProfile, GetStartedUsers from .goal import Goal, hide_goal diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 2ebe0ce04..58d979854 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -8,7 +8,11 @@ from django.template.response import TemplateResponse from django.views.decorators.http import require_POST from bookwyrm import models -from .helpers import get_user_from_username, handle_remote_webfinger, subscribe_remote_webfinger +from .helpers import ( + get_user_from_username, + handle_remote_webfinger, + subscribe_remote_webfinger, +) @login_required @@ -32,7 +36,6 @@ def follow(request): return redirect(to_follow.local_path) - @login_required @require_POST def unfollow(request): @@ -92,12 +95,15 @@ def delete_follow_request(request): follow_request.delete() return redirect(f"/user/{request.user.localname}") + def ostatus_follow_request(request): """prepare an outgoing remote follow request""" # parse the acct URI into a user string uri = urllib.parse.unquote(request.GET.get("acct")) - username_parts = re.search("(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri) + username_parts = re.search( + "(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri + ) account = f"{username_parts[2]}@{username_parts[1]}" user = handle_remote_webfinger(account) error = None @@ -111,14 +117,13 @@ def ostatus_follow_request(request): if hasattr(user, "followers") and request.user in user.followers.all(): error = "already_following" - if hasattr(user, "follower_requests") and request.user in user.follower_requests.all(): + if ( + hasattr(user, "follower_requests") + and request.user in user.follower_requests.all() + ): error = "already_requested" - data = { - "account": account, - "user": user, - "error": error - } + data = {"account": account, "user": user, "error": error} return TemplateResponse(request, "ostatus/subscribe.html", data) @@ -127,21 +132,17 @@ def ostatus_follow_request(request): def ostatus_follow_success(request): """display success message for remote follow""" user = get_user_from_username(request.user, request.GET.get("following")) - data = { - "account": user.name, - "user": user, - "error": None - } + data = {"account": user.name, "user": user, "error": None} return TemplateResponse(request, "ostatus/success.html", data) + def remote_follow_page(request): """Display remote follow page""" user = get_user_from_username(request.user, request.GET.get("user")) - data = { - "user": user - } + data = {"user": user} return TemplateResponse(request, "ostatus/remote_follow.html", data) + @require_POST def remote_follow(request): """direct user to follow from remote account using ostatus subscribe protocol""" diff --git a/bookwyrm/views/helpers.py b/bookwyrm/views/helpers.py index 607181489..650087ec0 100644 --- a/bookwyrm/views/helpers.py +++ b/bookwyrm/views/helpers.py @@ -84,6 +84,7 @@ def handle_remote_webfinger(query): return None return user + def subscribe_remote_webfinger(query): """get subscribe template from other servers""" template = None @@ -112,6 +113,7 @@ def subscribe_remote_webfinger(query): return template + def get_edition(book_id): """look up a book in the db and return an edition""" book = models.Book.objects.select_subclasses().get(id=book_id) diff --git a/bookwyrm/views/wellknown.py b/bookwyrm/views/wellknown.py index c9b1c1299..03e619dfd 100644 --- a/bookwyrm/views/wellknown.py +++ b/bookwyrm/views/wellknown.py @@ -32,9 +32,9 @@ def webfinger(request): "href": user.remote_id, }, { - "rel": "http://ostatus.org/schema/1.0/subscribe", - "template": f"https://{DOMAIN}/ostatus_subscribe?acct={{uri}}" - } + "rel": "http://ostatus.org/schema/1.0/subscribe", + "template": f"https://{DOMAIN}/ostatus_subscribe?acct={{uri}}", + }, ], } ) From 6abf5d69107c4440e1809e34458e169e823d7e92 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 21:48:03 +1100 Subject: [PATCH 10/57] add submit button to remote follow form --- bookwyrm/templates/ostatus/remote_follow.html | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html index ea8881e42..3ff769432 100644 --- a/bookwyrm/templates/ostatus/remote_follow.html +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -36,6 +36,7 @@ + From feaf0d5e52ec8d2887b2d14e3bcd3bfc49446cf4 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 07:11:57 +1100 Subject: [PATCH 11/57] handle username errors in remote follow form --- bookwyrm/templates/ostatus/error.html | 5 +++++ bookwyrm/views/follow.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index b6e858e24..cb1aec408 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -33,6 +33,11 @@

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

{% trans 'Check you have the correct username before trying again.' %}

+ {% elif error == 'remote_subscribe' %} +
+

{% blocktrans %}Something went wrong trying to follow from {{ account }}{% endblocktrans %}

+

{% trans 'Check you have the correct username before trying again.' %}

+
{% elif error == 'is_blocked' %}

{% blocktrans %}You have blocked {{ account }}{% endblocktrans %}

diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 58d979854..fcab5d6ac 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -148,5 +148,8 @@ def remote_follow(request): """direct user to follow from remote account using ostatus subscribe protocol""" remote_user = request.POST.get("remote_user") template = subscribe_remote_webfinger(remote_user) + if template is None: + data = {"account": remote_user, "user": None, "error": "remote_subscribe"} + return TemplateResponse(request, "ostatus/subscribe.html", data) url = template.replace("{uri}", request.POST.get("user")) return redirect(url) From 46f32944315b9add4f04776668bbf7c2117efc12 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 07:56:09 +1100 Subject: [PATCH 12/57] fix remote follow template --- bookwyrm/templates/ostatus/remote_follow.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html index 3ff769432..98442547e 100644 --- a/bookwyrm/templates/ostatus/remote_follow.html +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -24,7 +24,7 @@ @{{ user|username }} -

Follow {{ user.name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.

+

Follow {{ user.display_name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.

From c7242b6022c9e70725e9445255fe766ecedee2ed Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 07:56:31 +1100 Subject: [PATCH 13/57] add popup warning --- bookwyrm/templates/ostatus/remote_follow_button.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templates/ostatus/remote_follow_button.html b/bookwyrm/templates/ostatus/remote_follow_button.html index 2848fde0e..fc869229a 100644 --- a/bookwyrm/templates/ostatus/remote_follow_button.html +++ b/bookwyrm/templates/ostatus/remote_follow_button.html @@ -4,9 +4,12 @@ {% endif %} From 4a9713b812d65d2bc2f9ef4ecbc1eeec8f6a617f Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 08:03:01 +1100 Subject: [PATCH 14/57] fix template for remote follower error --- bookwyrm/templates/ostatus/error.html | 2 +- bookwyrm/templates/ostatus/subscribe.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index cb1aec408..442c35b9e 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -2,7 +2,7 @@ {% block content %}
- {% if not request.user.is_authenticated %} + {% if not request.user.is_authenticated and not error == 'remote_subscribe' %}
diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index 10b4409f3..d8c311829 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -22,11 +22,14 @@ @{{ user|username }} - - - {% include 'snippets/avatar.html' with user=user large=True %} - +

+ + {% trans 'You are now following ' %}{{ user.display_name }}! +

+ {% endblock %} From 3d73ea92e85b84bfc4f7e2fc5a8fab5179767e00 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 18:08:25 +1100 Subject: [PATCH 17/57] handle user blocks properly --- bookwyrm/templates/ostatus/error.html | 4 +++ bookwyrm/views/follow.py | 36 +++++++++++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 91bb6a0a4..8a047172f 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -42,6 +42,10 @@

{% blocktrans %}You have blocked {{ account }}{% endblocktrans %}

+ {% elif error == 'has_blocked' %} +
+

{% blocktrans %}{{ account }} has blocked you{% endblocktrans %}

+
{% elif error == 'already_following' %}

{% blocktrans %}You are already following {{ account }}{% endblocktrans %}

diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 1555fc5e4..83b900354 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -109,17 +109,33 @@ def ostatus_follow_request(request): if user is None or user == "": error = "ostatus_subscribe" - if hasattr(request.user, "blocks") and user in request.user.blocks.all(): - error = "is_blocked" + # don't do these checks for AnonymousUser before they sign in + if request.user.id: - if hasattr(user, "followers") and request.user in user.followers.all(): - error = "already_following" - - if ( - hasattr(user, "follower_requests") - and request.user in user.follower_requests.all() - ): - error = "already_requested" + # you have blocked them so you probably don't want to follow + if ( + hasattr(request.user, "blocks") + and user in request.user.blocks.all() + ): + error = "is_blocked" + # they have blocked you + if ( + hasattr(user, "blocks") + and request.user in user.blocks.all() + ): + error = "has_blocked" + # you're already following them + if ( + hasattr(user, "followers") + and request.user in user.followers.all() + ): + error = "already_following" + # you're not following yet but you already asked + if ( + hasattr(user, "follower_requests") + and request.user in user.follower_requests.all() + ): + error = "already_requested" data = {"account": account, "user": user, "error": error} From f5d9a204ebfd0045a04046200feaeaa3b21d68d8 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 19:37:56 +1100 Subject: [PATCH 18/57] clean up ostatus templates --- bookwyrm/templates/ostatus/error.html | 46 +++--- bookwyrm/templates/ostatus/remote_follow.html | 67 +++++---- bookwyrm/templates/ostatus/success.html | 46 +++--- bookwyrm/templates/ostatus/template.html | 133 +++++++++--------- 4 files changed, 145 insertions(+), 147 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 8a047172f..085fa3454 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -4,30 +4,28 @@
{% if not request.user.is_authenticated and not error == 'remote_subscribe' %} +
+
+
+ {% csrf_token %} +
+
+ + +
+
+ + +

{% trans "Forgot your password?" %}

+
+
+ +
+
+
+
+
+
{% elif error == 'ostatus_subscribe' %}

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html index ef8f1b90f..6a4e565ac 100644 --- a/bookwyrm/templates/ostatus/remote_follow.html +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -4,41 +4,40 @@ {% block content %}
-
-

{% blocktrans %}Follow {{ user.display_name }} on the fediverse{% endblocktrans %}

-
-
-
- - {% include 'snippets/avatar.html' with user=user large=True %} - -
- - - {{ user.display_name }} - {% if user.manually_approves_followers %} - - {% trans "Locked account" %} - - {% endif %} - - @{{ user|username }} - -

{% blocktrans %}Follow {{ user.display_name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.{% endblocktrans %}

-
-
+
+

{% blocktrans %}Follow {{ user.display_name }} on the fediverse{% endblocktrans %}

+
+
+
+ + {% include 'snippets/avatar.html' with user=user large=True %} + +
+ + + {{ user.display_name }} + {% if user.manually_approves_followers %} + + {% trans "Locked account" %} + + {% endif %} + + @{{ user|username }} + +

{% blocktrans %}Follow {{ user.display_name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.{% endblocktrans %}

+
+
-
-
-
- {% csrf_token %} - - - - -
-
-
+
+
+
+ {% csrf_token %} + + + + +
+
{% endblock %} diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index d8c311829..89f662735 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -4,29 +4,29 @@ {% block content %}
-
diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index cb922f9bd..1dbb32a36 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -7,45 +7,46 @@ - {% block title %}{% endblock %}{{ site.name }} - - - - + {% block title %}{% endblock %}{{ site.name }} + + + + - + - + - {% if preview_images_enabled is True %} - - {% else %} - - {% endif %} - - - - + {% if preview_images_enabled is True %} + + {% else %} + + {% endif %} + + + + - {% block opengraph_images %} - {% include 'snippets/opengraph_images.html' %} - {% endblock %} - - + {% block opengraph_images %} + {% include 'snippets/opengraph_images.html' %} + {% endblock %} + + @@ -57,43 +58,43 @@ From 9a3ec4362b85ce7920632ff6a74ee44f4b99d9ff Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 19:45:52 +1100 Subject: [PATCH 19/57] code cleanup --- bookwyrm/static/js/bookwyrm.js | 13 ++++++------- bookwyrm/views/follow.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index 86a021af8..ebac78a91 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -376,12 +376,11 @@ let BookWyrm = new class { * @param {string} windowName windowName * @return {undefined} */ - displayPopUp(url, windowName){ - - window.open( - url, - windowName, - "left=100,top=100,width=430,height=600" - ) + displayPopUp(url, windowName) { + window.open( + url, + windowName, + "left=100,top=100,width=430,height=600" + ); } }(); diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 83b900354..11bff60a3 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -100,7 +100,7 @@ def ostatus_follow_request(request): """prepare an outgoing remote follow request""" uri = urllib.parse.unquote(request.GET.get("acct")) username_parts = re.search( - "(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri + r"(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri ) account = f"{username_parts[2]}@{username_parts[1]}" user = handle_remote_webfinger(account) From 1211fda7ff82a2eca793981cb5fbddda4643af5b Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 19:53:13 +1100 Subject: [PATCH 20/57] beautiful code quality, pylint will be pleased --- bookwyrm/templates/ostatus/template.html | 2 +- bookwyrm/views/follow.py | 19 ++++--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 1dbb32a36..7d670b0a5 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -33,7 +33,7 @@ diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 11bff60a3..7af8b0db7 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -113,22 +113,13 @@ def ostatus_follow_request(request): if request.user.id: # you have blocked them so you probably don't want to follow - if ( - hasattr(request.user, "blocks") - and user in request.user.blocks.all() - ): + if hasattr(request.user, "blocks") and user in request.user.blocks.all(): error = "is_blocked" # they have blocked you - if ( - hasattr(user, "blocks") - and request.user in user.blocks.all() - ): + if hasattr(user, "blocks") and request.user in user.blocks.all(): error = "has_blocked" # you're already following them - if ( - hasattr(user, "followers") - and request.user in user.followers.all() - ): + if hasattr(user, "followers") and request.user in user.followers.all(): error = "already_following" # you're not following yet but you already asked if ( @@ -165,8 +156,6 @@ def remote_follow(request): if template is None: data = {"account": remote_user, "user": None, "error": "remote_subscribe"} return TemplateResponse(request, "ostatus/subscribe.html", data) - user = get_object_or_404( - models.User, id=request.POST.get("user") - ) + user = get_object_or_404(models.User, id=request.POST.get("user")) url = template.replace("{uri}", urllib.parse.quote(user.remote_id)) return redirect(url) From 1d90ca6fa62362e840ca2ba9fd0306b0ea8a2752 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 20:35:26 +1100 Subject: [PATCH 21/57] keep footer DRY Pulls footer and scripts after it into a separate component template. This allows ostatus/template to use the footer without having to use layout without repeating the same code. --- bookwyrm/templates/components/footer.html | 49 +++++++++++++++++++++++ bookwyrm/templates/layout.html | 45 +-------------------- bookwyrm/templates/ostatus/template.html | 48 +--------------------- 3 files changed, 51 insertions(+), 91 deletions(-) create mode 100644 bookwyrm/templates/components/footer.html diff --git a/bookwyrm/templates/components/footer.html b/bookwyrm/templates/components/footer.html new file mode 100644 index 000000000..047d7bfad --- /dev/null +++ b/bookwyrm/templates/components/footer.html @@ -0,0 +1,49 @@ +{% load layout %} +{% load i18n %} +{% load static %} + + + + + + + + + +{% block scripts %}{% endblock %} diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index f2d04f961..50a7ae6d1 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -222,50 +222,7 @@
- +{% include 'components/footer.html' %} - - - - - - -{% block scripts %}{% endblock %} diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 7d670b0a5..04e432aaa 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -48,59 +48,13 @@
- -
{% block content%}{% endblock %}
- - +{% include 'components/footer.html' %} - - - - - - -{% block scripts %}{% endblock %} From 1636dfd308ca8eb8827a6aa8f6be9587bc902656 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 20:42:16 +1100 Subject: [PATCH 22/57] fix footer indentation --- bookwyrm/templates/components/footer.html | 68 +++++++++++------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/bookwyrm/templates/components/footer.html b/bookwyrm/templates/components/footer.html index 047d7bfad..df11e9d55 100644 --- a/bookwyrm/templates/components/footer.html +++ b/bookwyrm/templates/components/footer.html @@ -3,43 +3,43 @@ {% load static %} From 386371baa3ee85e54c1f918c41297dc3c0681120 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 12:42:52 +1100 Subject: [PATCH 23/57] improve a11y on notifications Also change close link to a button. Co-authored-by: Joachim --- bookwyrm/templates/ostatus/error.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 085fa3454..99a2a9acb 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -27,34 +27,34 @@
{% elif error == 'ostatus_subscribe' %} -
+

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

{% trans 'Check you have the correct username before trying again.' %}

{% elif error == 'remote_subscribe' %} -
+

{% blocktrans %}Something went wrong trying to follow from {{ account }}{% endblocktrans %}

{% trans 'Check you have the correct username before trying again.' %}

{% elif error == 'is_blocked' %} -
+

{% blocktrans %}You have blocked {{ account }}{% endblocktrans %}

{% elif error == 'has_blocked' %} -
+

{% blocktrans %}{{ account }} has blocked you{% endblocktrans %}

{% elif error == 'already_following' %} -
+

{% blocktrans %}You are already following {{ account }}{% endblocktrans %}

{% elif error == 'already_requested' %} -
+

{% blocktrans %}You have already requested to follow {{ account }}{% endblocktrans %}

{% endif %}
- Close window +
{% endblock %} From 4ee234258a15edb56485306480cb141f291e6c1b Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 12:47:04 +1100 Subject: [PATCH 24/57] remove OG meta in ostatus template It's just a temporary popup so would be weird to share and just gunks things up. Co-authored-by: Joachim --- bookwyrm/templates/ostatus/template.html | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 04e432aaa..68284a35f 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -17,20 +17,6 @@ - {% if preview_images_enabled is True %} - - {% else %} - - {% endif %} - - - - - - {% block opengraph_images %} - {% include 'snippets/opengraph_images.html' %} - {% endblock %} - - - - - - -{% block scripts %}{% endblock %} diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 50a7ae6d1..bc85e678e 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -222,7 +222,51 @@
-{% include 'components/footer.html' %} + + + + + + + + +{% block scripts %}{% endblock %} From 7848ff792766b67d171e27dcab13f485cbf23bd4 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 20:46:41 +1100 Subject: [PATCH 26/57] fix translation strings --- bookwyrm/templates/ostatus/remote_follow.html | 11 +++++++---- bookwyrm/templates/ostatus/subscribe.html | 10 +++++----- bookwyrm/templates/ostatus/success.html | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html index 6a4e565ac..96c7f9452 100644 --- a/bookwyrm/templates/ostatus/remote_follow.html +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -2,11 +2,12 @@ {% load i18n %} {% load utilities %} +{% block heading %} +{% blocktrans with username=user.localname sitename=site.name %}Follow {{ username }} on the fediverse{% endblocktrans %} +{% endblock %} + {% block content %}
-
-

{% blocktrans %}Follow {{ user.display_name }} on the fediverse{% endblocktrans %}

-
@@ -24,11 +25,13 @@ @{{ user|username }} -

{% blocktrans %}Follow {{ user.display_name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.{% endblocktrans %}

+
+

{% blocktrans with username=user.display_name %}Follow {{ username }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.{% endblocktrans %}

+
diff --git a/bookwyrm/templates/ostatus/subscribe.html b/bookwyrm/templates/ostatus/subscribe.html index d41ce6743..51dec4382 100644 --- a/bookwyrm/templates/ostatus/subscribe.html +++ b/bookwyrm/templates/ostatus/subscribe.html @@ -5,11 +5,11 @@ {% block title %} {% if not request.user.is_authenticated %} -{% trans "Log in to " %} +{% blocktrans with sitename=site.name %}Log in to {{ sitename }}{% endblocktrans %} {% elif error %} -{% trans "Error following from " %} +{% blocktrans with sitename=site.name %}Error following from {{ sitename }}{% endblocktrans %} {% else %} -{% trans "Follow from " %} +{% blocktrans with sitename=site.name %}Follow from {{ sitename }}{% endblocktrans %} {% endif %} {% endblock %} @@ -19,7 +19,7 @@ {% elif error %} {% trans 'Uh oh...' %} {% else %} -{% trans 'Follow from ' %}{{ site.name }} +{% blocktrans with sitename=site.name %}Follow from {{ sitename }}{% endblocktrans %} {% endif %} {% endblock %} @@ -48,7 +48,7 @@ {% csrf_token %} - +
diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index 89f662735..a652989be 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -25,7 +25,7 @@

- {% trans 'You are now following ' %}{{ user.display_name }}! + {% blocktrans with display_name=user.display_name %}You are now following {{ display_name }}!{% endblocktrans %}

From 080fa72c84b6608d0788e2fc1b31cf0e34ed2b1c Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 21:01:07 +1100 Subject: [PATCH 27/57] ostatus template fixes - remove unnecessary links - remove footer - remove unnecessary JS scripts - make block title and block heading empty --- bookwyrm/templates/ostatus/template.html | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 68284a35f..8d2d193ec 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -7,16 +7,11 @@ - {% block title %}{% endblock %}{{ site.name }} + {% block title %}{% endblock %} - - - - - + From 461c35f416e1838c470824d03f10c8eed8a7ff73 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 21:02:39 +1100 Subject: [PATCH 28/57] fix buttons --- bookwyrm/templates/ostatus/error.html | 2 +- bookwyrm/templates/ostatus/success.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 99a2a9acb..0c8d6f768 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -55,6 +55,6 @@ {% endif %}
- +
{% endblock %} diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index a652989be..a4f78ace8 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -30,6 +30,6 @@
- Close window +
{% endblock %} From 9be1a8f4557e98e9bfe4aee072f074fed3fc4d5a Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Wed, 1 Dec 2021 07:45:30 +1100 Subject: [PATCH 29/57] keep close button simple --- bookwyrm/templates/ostatus/error.html | 2 +- bookwyrm/templates/ostatus/success.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 0c8d6f768..b5a3bf406 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -55,6 +55,6 @@ {% endif %}
- +
{% endblock %} diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index a4f78ace8..66577e83f 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -30,6 +30,6 @@
- +
{% endblock %} From c77edab79c1b53404a83f8e8bcc33de37ec55648 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 5 Dec 2021 18:09:51 +1100 Subject: [PATCH 30/57] minor functionality fixes --- bookwyrm/templates/ostatus/remote_follow.html | 4 ++-- bookwyrm/views/follow.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html index 96c7f9452..ca47c529b 100644 --- a/bookwyrm/templates/ostatus/remote_follow.html +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -30,7 +30,7 @@
-

{% blocktrans with username=user.display_name %}Follow {{ username }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.{% endblocktrans %}

+

{% blocktrans with username=user.display_name %}Follow {{ username }} from another Fediverse account like BookWyrm, Mastodon, or Pleroma.{% endblocktrans %}

@@ -38,7 +38,7 @@ {% csrf_token %} - +
diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 7af8b0db7..7a9d7bad1 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -110,7 +110,7 @@ def ostatus_follow_request(request): error = "ostatus_subscribe" # don't do these checks for AnonymousUser before they sign in - if request.user.id: + if request.user.is_authenticated: # you have blocked them so you probably don't want to follow if hasattr(request.user, "blocks") and user in request.user.blocks.all(): From 2d875b5575c580f1da2c40051c6952992f52e8c8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Dec 2021 12:28:17 -0800 Subject: [PATCH 31/57] Add link properties for remotes --- bookwyrm/models/author.py | 12 ++++++++++++ bookwyrm/models/book.py | 10 ++++++++++ bookwyrm/templates/author/author.html | 10 +++++----- bookwyrm/templates/book/book.html | 4 ++-- bookwyrm/templatetags/utilities.py | 8 -------- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index 6c29ac058..ce0d027cd 100644 --- a/bookwyrm/models/author.py +++ b/bookwyrm/models/author.py @@ -1,4 +1,5 @@ """ database schema for info about authors """ +import re from django.contrib.postgres.indexes import GinIndex from django.db import models @@ -33,6 +34,17 @@ class Author(BookDataModel): ) bio = fields.HtmlField(null=True, blank=True) + @property + def isni_link(self): + """generate the url from the isni id""" + clean_isni = re.sub(r"\s", "", self.isni) + return f"https://insi.org/isni/{clean_isni}" + + @property + def openlibrary_link(self): + """generate the url from the openlibrary id""" + return f"https://openlibrary.org/authors/{self.openlibrary_key}" + def get_remote_id(self): """editions and works both use "book" instead of model_name""" return f"https://{DOMAIN}/author/{self.id}" diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index d97a1b8a6..0a551bf28 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -52,6 +52,16 @@ class BookDataModel(ObjectMixin, BookWyrmModel): null=True, ) + @property + def openlibrary_link(self): + """generate the url from the openlibrary id""" + return f"https://openlibrary.org/books/{self.openlibrary_key}" + + @property + def inventaire_link(self): + """generate the url from the inventaire id""" + return f"https://inventaire.io/entity/{self.inventaire_id}" + class Meta: """can't initialize this model, that wouldn't make sense""" diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index b066c6ca4..fb6821766 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -66,23 +66,23 @@ {% if author.isni %}

- + {% trans "View ISNI record" %}

{% endif %} {% if author.openlibrary_key %} -

- +

+ {% trans "View on OpenLibrary" %}

{% endif %} {% if author.inventaire_id %} -

- +

+ {% trans "View on Inventaire" %}

diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 7d4df76f7..cbca31b56 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -91,10 +91,10 @@ {% endwith %} {% if book.openlibrary_key %} -

{% trans "View on OpenLibrary" %}

+

{% trans "View on OpenLibrary" %}

{% endif %} {% if book.inventaire_id %} -

{% trans "View on Inventaire" %}

+

{% trans "View on Inventaire" %}

{% endif %}
diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py index 5cc25fed8..2246fab19 100644 --- a/bookwyrm/templatetags/utilities.py +++ b/bookwyrm/templatetags/utilities.py @@ -5,7 +5,6 @@ from uuid import uuid4 from django import template from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ -from django.template.defaultfilters import stringfilter from django.templatetags.static import static @@ -98,10 +97,3 @@ def get_isni(existing, author, autoescape=True): f'' ) return "" - - -@register.filter(name="remove_spaces") -@stringfilter -def remove_spaces(arg): - """Removes spaces from argument passed in""" - return re.sub(r"\s", "", str(arg)) From b824841cb333d1624b49de06613ac324549a2a96 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Dec 2021 12:37:19 -0800 Subject: [PATCH 32/57] Adds update logic to connectors --- bookwyrm/connectors/abstract_connector.py | 36 ++++++++++++++++++----- bookwyrm/connectors/inventaire.py | 2 ++ bookwyrm/connectors/openlibrary.py | 2 ++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index c032986d1..97ac92496 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -111,7 +111,7 @@ class AbstractConnector(AbstractMinimalConnector): return existing.default_edition return existing - # load the json + # load the json data from the remote data source data = self.get_book_data(remote_id) if self.is_work_data(data): try: @@ -150,23 +150,32 @@ class AbstractConnector(AbstractMinimalConnector): """this allows connectors to override the default behavior""" return get_data(remote_id) - def create_edition_from_data(self, work, edition_data): + def create_edition_from_data(self, work, edition_data, instance=None): """if we already have the work, we're ready""" mapped_data = dict_from_mappings(edition_data, self.book_mappings) mapped_data["work"] = work.remote_id edition_activity = activitypub.Edition(**mapped_data) - edition = edition_activity.to_model(model=models.Edition, overwrite=False) - edition.connector = self.connector - edition.save() + edition = edition_activity.to_model( + model=models.Edition, overwrite=False, instance=instance + ) + + # if we're updating an existing instance, we don't need to load authors + if instance: + return edition + + if not edition.connector: + edition.connector = self.connector + edition.save(broadcast=False, update_fields=["connector"]) for author in self.get_authors_from_data(edition_data): edition.authors.add(author) + # use the authors from the work if none are found for the edition if not edition.authors.exists() and work.authors.exists(): edition.authors.set(work.authors.all()) return edition - def get_or_create_author(self, remote_id): + def get_or_create_author(self, remote_id, instance=None): """load that author""" existing = models.Author.find_existing_by_remote_id(remote_id) if existing: @@ -181,7 +190,20 @@ class AbstractConnector(AbstractMinimalConnector): return None # this will dedupe - return activity.to_model(model=models.Author, overwrite=False) + return activity.to_model( + model=models.Author, overwrite=False, instance=instance + ) + + def update_author_from_remote(self, obj): + """load the remote data from this connector and add it to an existing author""" + remote_id = obj.getattr(self, "generated_remote_link_field") + return self.get_or_create_author(remote_id, instance=obj) + + def update_book_from_remote(self, obj): + """load the remote data from this connector and add it to an existing book""" + remote_id = obj.getattr(self, "generated_remote_link_field") + data = self.get_book_data(remote_id) + return self.create_edition_from_data(obj.parent_work, data, instance=obj) @abstractmethod def is_work_data(self, data): diff --git a/bookwyrm/connectors/inventaire.py b/bookwyrm/connectors/inventaire.py index e9f538569..bc5b3f684 100644 --- a/bookwyrm/connectors/inventaire.py +++ b/bookwyrm/connectors/inventaire.py @@ -11,6 +11,8 @@ from .connector_manager import ConnectorException class Connector(AbstractConnector): """instantiate a connector for inventaire""" + generated_remote_link_field = "inventaire_link" + def __init__(self, identifier): super().__init__(identifier) diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index b8afc7ca6..225174c80 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -12,6 +12,8 @@ from .openlibrary_languages import languages class Connector(AbstractConnector): """instantiate a connector for OL""" + generated_remote_link_field = "openlibrary_link" + def __init__(self, identifier): super().__init__(identifier) From 113eda33e9cf5281b8c1aa406634f76658ae0ed9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Dec 2021 12:47:43 -0800 Subject: [PATCH 33/57] Adds update views --- bookwyrm/views/author.py | 18 ++++++++++++++++++ bookwyrm/views/books/books.py | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index 0c8e3e05a..fdf86cd49 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -6,9 +6,11 @@ from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View +from django.views.decorators.http import require_POST from bookwyrm import forms, models from bookwyrm.activitypub import ActivitypubResponse +from bookwyrm.connectors import connector_manager from bookwyrm.settings import PAGE_LENGTH from bookwyrm.views.helpers import is_api_request @@ -73,3 +75,19 @@ class EditAuthor(View): author = form.save() return redirect(f"/author/{author.id}") + + +@login_required +@require_POST +@permission_required("bookwyrm.edit_book", raise_exception=True) +# pylint: disable=unused-argument +def update_author_from_remote(request, connector_identifier, author_id): + """load the remote data for this author""" + connector = connector_manager.load_connector( + get_object_or_404(models.Connector, identifier=connector_identifier) + ) + author = get_object_or_404(models.Book.objects.select_subclasses(), id=author_id) + + connector.update_author_from_remote(author) + + return redirect("author", author.id) diff --git a/bookwyrm/views/books/books.py b/bookwyrm/views/books/books.py index e495da3e7..f7166749b 100644 --- a/bookwyrm/views/books/books.py +++ b/bookwyrm/views/books/books.py @@ -178,3 +178,19 @@ def resolve_book(request): book = connector.get_or_create_book(remote_id) return redirect("book", book.id) + + +@login_required +@require_POST +@permission_required("bookwyrm.edit_book", raise_exception=True) +# pylint: disable=unused-argument +def update_book_from_remote(request, connector_identifier, book_id): + """load the remote data for this book""" + connector = connector_manager.load_connector( + get_object_or_404(models.Connector, identifier=connector_identifier) + ) + book = get_object_or_404(models.Book.objects.select_subclasses(), id=book_id) + + connector.update_book_from_remote(book) + + return redirect("book", book.id) From d7e4e6aa1e45a9bdd8c55eba449d06b4ff4f422f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Dec 2021 13:02:42 -0800 Subject: [PATCH 34/57] Adds openlibrary update for book --- bookwyrm/connectors/abstract_connector.py | 4 ++-- bookwyrm/templates/author/author.html | 6 ++++++ bookwyrm/templates/book/book.html | 8 +++++++- bookwyrm/urls.py | 9 +++++++-- bookwyrm/views/__init__.py | 1 + bookwyrm/views/author.py | 2 +- bookwyrm/views/books/books.py | 2 +- 7 files changed, 25 insertions(+), 7 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 97ac92496..48d2b4cbc 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -196,12 +196,12 @@ class AbstractConnector(AbstractMinimalConnector): def update_author_from_remote(self, obj): """load the remote data from this connector and add it to an existing author""" - remote_id = obj.getattr(self, "generated_remote_link_field") + remote_id = getattr(obj, getattr(self, "generated_remote_link_field")) return self.get_or_create_author(remote_id, instance=obj) def update_book_from_remote(self, obj): """load the remote data from this connector and add it to an existing book""" - remote_id = obj.getattr(self, "generated_remote_link_field") + remote_id = getattr(obj, getattr(self, "generated_remote_link_field")) data = self.get_book_data(remote_id) return self.create_edition_from_data(obj.parent_work, data, instance=obj) diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index fb6821766..c2355955b 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -77,6 +77,9 @@ {% trans "View on OpenLibrary" %} + {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} + + {% endif %}

{% endif %} @@ -85,6 +88,9 @@ {% trans "View on Inventaire" %} + {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} + + {% endif %}

{% endif %} diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index cbca31b56..3a7b1cbc8 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -91,7 +91,13 @@ {% endwith %} {% if book.openlibrary_key %} -

{% trans "View on OpenLibrary" %}

+

+ {% trans "View on OpenLibrary" %} +

+ {% csrf_token %} + +
+

{% endif %} {% if book.inventaire_id %}

{% trans "View on Inventaire" %}

diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 514bb7e60..697028b79 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -422,8 +422,13 @@ urlpatterns = [ r"^upload-cover/(?P\d+)/?$", views.upload_cover, name="upload-cover" ), re_path(r"^add-description/(?P\d+)/?$", views.add_description), - re_path(r"^resolve-book/?$", views.resolve_book), - re_path(r"^switch-edition/?$", views.switch_edition), + re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"), + re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"), + re_path( + rf"{BOOK_PATH}/update/(?P[\w\.]+)?$", + views.update_book_from_remote, + name="book-update-remote" + ), # isbn re_path(r"^isbn/(?P\d+)(.json)?/?$", views.Isbn.as_view()), # author diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index d79de4248..b399b90ab 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -29,6 +29,7 @@ from .preferences.block import Block, unblock # books from .books.books import Book, upload_cover, add_description, resolve_book +from .books.books import update_book_from_remote from .books.edit_book import EditBook, ConfirmEditBook from .books.editions import Editions, switch_edition diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index fdf86cd49..838d1c2b7 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -81,7 +81,7 @@ class EditAuthor(View): @require_POST @permission_required("bookwyrm.edit_book", raise_exception=True) # pylint: disable=unused-argument -def update_author_from_remote(request, connector_identifier, author_id): +def update_author_from_remote(request, author_id, connector_identifier): """load the remote data for this author""" connector = connector_manager.load_connector( get_object_or_404(models.Connector, identifier=connector_identifier) diff --git a/bookwyrm/views/books/books.py b/bookwyrm/views/books/books.py index f7166749b..2d49ae30c 100644 --- a/bookwyrm/views/books/books.py +++ b/bookwyrm/views/books/books.py @@ -184,7 +184,7 @@ def resolve_book(request): @require_POST @permission_required("bookwyrm.edit_book", raise_exception=True) # pylint: disable=unused-argument -def update_book_from_remote(request, connector_identifier, book_id): +def update_book_from_remote(request, book_id, connector_identifier): """load the remote data for this book""" connector = connector_manager.load_connector( get_object_or_404(models.Connector, identifier=connector_identifier) From 4085714764af94157e740848f1c90472f0b16e5c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Dec 2021 13:24:40 -0800 Subject: [PATCH 35/57] Update openlibrary author with ISNI --- bookwyrm/connectors/abstract_connector.py | 7 ++++--- bookwyrm/connectors/openlibrary.py | 8 ++++++++ bookwyrm/models/author.py | 2 +- bookwyrm/templates/author/author.html | 16 +++++++++++----- bookwyrm/templates/book/book.html | 2 ++ bookwyrm/urls.py | 19 +++++++++++++++---- bookwyrm/views/__init__.py | 2 +- bookwyrm/views/author.py | 2 +- 8 files changed, 43 insertions(+), 15 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 48d2b4cbc..4b1f6e58e 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -177,9 +177,10 @@ class AbstractConnector(AbstractMinimalConnector): def get_or_create_author(self, remote_id, instance=None): """load that author""" - existing = models.Author.find_existing_by_remote_id(remote_id) - if existing: - return existing + if not instance: + existing = models.Author.find_existing_by_remote_id(remote_id) + if existing: + return existing data = self.get_book_data(remote_id) diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index 225174c80..c15277f84 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -68,6 +68,7 @@ class Connector(AbstractConnector): Mapping("born", remote_field="birth_date"), Mapping("died", remote_field="death_date"), Mapping("bio", formatter=get_description), + Mapping("isni", remote_field="remote_ids", formatter=get_isni), ] def get_book_data(self, remote_id): @@ -226,6 +227,13 @@ def get_languages(language_blob): return langs +def get_isni(remote_ids_blob): + """extract the isni from the remote id data for the author""" + if not remote_ids_blob or not isinstance(remote_ids_blob, dict): + return None + return remote_ids_blob.get("isni") + + def pick_default_edition(options): """favor physical copies with covers in english""" if not options: diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index ce0d027cd..5cc11afd6 100644 --- a/bookwyrm/models/author.py +++ b/bookwyrm/models/author.py @@ -38,7 +38,7 @@ class Author(BookDataModel): def isni_link(self): """generate the url from the isni id""" clean_isni = re.sub(r"\s", "", self.isni) - return f"https://insi.org/isni/{clean_isni}" + return f"https://isni.org/isni/{clean_isni}" @property def openlibrary_link(self): diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index c2355955b..6e93d3131 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -14,7 +14,7 @@ {% if request.user.is_authenticated and perms.bookwyrm.edit_book %}
- + {% trans "Edit Author" %} @@ -73,23 +73,29 @@ {% endif %} {% if author.openlibrary_key %} -

+

{% trans "View on OpenLibrary" %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} - +

+ {% csrf_token %} + +
{% endif %}

{% endif %} {% if author.inventaire_id %} -

+

{% trans "View on Inventaire" %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} - +

+ {% csrf_token %} + +
{% endif %}

{% endif %} diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 3a7b1cbc8..cdfbdf983 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -93,10 +93,12 @@ {% if book.openlibrary_key %}

{% trans "View on OpenLibrary" %} + {% if request.user.is_authenticated and perms.bookwyrm.edit_book %}

{% csrf_token %}
+ {% endif %}

{% endif %} {% if book.inventaire_id %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 697028b79..6e53ef2ac 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -425,15 +425,26 @@ urlpatterns = [ re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"), re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"), re_path( - rf"{BOOK_PATH}/update/(?P[\w\.]+)?$", + rf"^{BOOK_PATH}/update/(?P[\w\.]+)?$", views.update_book_from_remote, - name="book-update-remote" + name="book-update-remote", + ), + re_path( + r"^author/(?P\d+)/update/(?P[\w\.]+)?$", + views.update_author_from_remote, + name="author-update-remote", ), # isbn re_path(r"^isbn/(?P\d+)(.json)?/?$", views.Isbn.as_view()), # author - re_path(r"^author/(?P\d+)(.json)?/?$", views.Author.as_view()), - re_path(r"^author/(?P\d+)/edit/?$", views.EditAuthor.as_view()), + re_path( + r"^author/(?P\d+)(.json)?/?$", views.Author.as_view(), name="author" + ), + re_path( + r"^author/(?P\d+)/edit/?$", + views.EditAuthor.as_view(), + name="edit-author", + ), # reading progress re_path(r"^edit-readthrough/?$", views.edit_readthrough, name="edit-readthrough"), re_path(r"^delete-readthrough/?$", views.delete_readthrough), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index b399b90ab..837b12570 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -55,7 +55,7 @@ from .imports.manually_review import ( ) # misc views -from .author import Author, EditAuthor +from .author import Author, EditAuthor, update_author_from_remote from .directory import Directory from .discover import Discover from .feed import DirectMessage, Feed, Replies, Status diff --git a/bookwyrm/views/author.py b/bookwyrm/views/author.py index 838d1c2b7..2acb3b19a 100644 --- a/bookwyrm/views/author.py +++ b/bookwyrm/views/author.py @@ -86,7 +86,7 @@ def update_author_from_remote(request, author_id, connector_identifier): connector = connector_manager.load_connector( get_object_or_404(models.Connector, identifier=connector_identifier) ) - author = get_object_or_404(models.Book.objects.select_subclasses(), id=author_id) + author = get_object_or_404(models.Author, id=author_id) connector.update_author_from_remote(author) From 071da7d4fb9d379dab8a703b987e88dfd353ef9a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Dec 2021 13:38:15 -0800 Subject: [PATCH 36/57] Handle various link generation needs --- bookwyrm/connectors/abstract_connector.py | 8 ++++++-- bookwyrm/connectors/inventaire.py | 7 ++++++- bookwyrm/templates/author/author.html | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 4b1f6e58e..bb2bfb6f9 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -195,14 +195,18 @@ class AbstractConnector(AbstractMinimalConnector): model=models.Author, overwrite=False, instance=instance ) + def get_remote_id_from_model(self, obj): + """given the data stored, how can we look this up""" + return getattr(obj, getattr(self, "generated_remote_link_field")) + def update_author_from_remote(self, obj): """load the remote data from this connector and add it to an existing author""" - remote_id = getattr(obj, getattr(self, "generated_remote_link_field")) + remote_id = self.get_remote_id_from_model(obj) return self.get_or_create_author(remote_id, instance=obj) def update_book_from_remote(self, obj): """load the remote data from this connector and add it to an existing book""" - remote_id = getattr(obj, getattr(self, "generated_remote_link_field")) + remote_id = self.get_remote_id_from_model(obj) data = self.get_book_data(remote_id) return self.create_edition_from_data(obj.parent_work, data, instance=obj) diff --git a/bookwyrm/connectors/inventaire.py b/bookwyrm/connectors/inventaire.py index bc5b3f684..45d0546fb 100644 --- a/bookwyrm/connectors/inventaire.py +++ b/bookwyrm/connectors/inventaire.py @@ -11,7 +11,7 @@ from .connector_manager import ConnectorException class Connector(AbstractConnector): """instantiate a connector for inventaire""" - generated_remote_link_field = "inventaire_link" + generated_remote_link_field = "inventaire_id" def __init__(self, identifier): super().__init__(identifier) @@ -212,6 +212,11 @@ class Connector(AbstractConnector): return "" return data.get("extract") + def get_remote_id_from_model(self, obj): + """use get_remote_id to figure out the link from a model obj""" + remote_id_value = getattr(obj, self.inventaire_id) + return self.get_remote_id(remote_id_value) + def get_language_code(options, code="en"): """when there are a bunch of translation but we need a single field""" diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index 6e93d3131..bf2c8f3fd 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -92,7 +92,7 @@ {% trans "View on Inventaire" %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} -
+ {% csrf_token %}
From 02313f40b8700a7a3c121f94bbdc0d301db16c60 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 5 Dec 2021 13:46:13 -0800 Subject: [PATCH 37/57] Adds update from inventaire link for books --- bookwyrm/connectors/inventaire.py | 2 +- bookwyrm/templates/book/book.html | 10 +++++++++- bookwyrm/urls.py | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bookwyrm/connectors/inventaire.py b/bookwyrm/connectors/inventaire.py index 45d0546fb..a9aeb94f9 100644 --- a/bookwyrm/connectors/inventaire.py +++ b/bookwyrm/connectors/inventaire.py @@ -214,7 +214,7 @@ class Connector(AbstractConnector): def get_remote_id_from_model(self, obj): """use get_remote_id to figure out the link from a model obj""" - remote_id_value = getattr(obj, self.inventaire_id) + remote_id_value = obj.inventaire_id return self.get_remote_id(remote_id_value) diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index cdfbdf983..6d8ce72b8 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -102,7 +102,15 @@

{% endif %} {% if book.inventaire_id %} -

{% trans "View on Inventaire" %}

+

+ {% trans "View on Inventaire" %} + {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} +

+ {% csrf_token %} + +
+ {% endif %} +

{% endif %}
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 6e53ef2ac..012a91164 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -425,12 +425,12 @@ urlpatterns = [ re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"), re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"), re_path( - rf"^{BOOK_PATH}/update/(?P[\w\.]+)?$", + rf"{BOOK_PATH}/update/(?P[\w\.]+)/?$", views.update_book_from_remote, name="book-update-remote", ), re_path( - r"^author/(?P\d+)/update/(?P[\w\.]+)?$", + r"^author/(?P\d+)/update/(?P[\w\.]+)/?$", views.update_author_from_remote, name="author-update-remote", ), From 781fe69470125f888f5c7583db157e0ecc8129f9 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 6 Dec 2021 09:29:51 +1100 Subject: [PATCH 38/57] more descriptive remote follow errors - distinguish between invalid username, user not found, and remote follow not supported - make helpers DRYer --- bookwyrm/templates/ostatus/error.html | 28 ++++++++++--- bookwyrm/templates/ostatus/subscribe.html | 6 +-- bookwyrm/views/follow.py | 36 +++++++++++++--- bookwyrm/views/helpers.py | 51 +++++++++++++---------- 4 files changed, 83 insertions(+), 38 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index b5a3bf406..a603529fe 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -2,7 +2,28 @@ {% block content %}
- {% if not request.user.is_authenticated and not error == 'remote_subscribe' %} + {% if error == 'invalid_username' %} +
+ {% blocktrans %} +

{{ account }} is not a valid username.

+

Check you have the correct username before trying again.

+ {% endblocktrans %} +
+ {% elif error == 'user_not_found' %} +
+ {% blocktrans %} +

{{ account }} could not be found or {{ remote_domain }} does not support identity discovery.

+

Check you have the correct username before trying again.

+ {% endblocktrans %} +
+ {% elif error == 'not_supported' %} +
+ {% blocktrans %} +

{{ account }} was found but {{ remote_domain }} does not support 'remote follow'.

+

Try searching for {{ user }} on {{ remote_domain }} instead.

+ {% endblocktrans %} +
+ {% elif not request.user.is_authenticated %}