From af3c84cd8741334e723d09a895bf6576143deac1 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Mon, 10 Jan 2022 06:43:43 +0000 Subject: [PATCH 001/145] Add basic logging config --- bookwyrm/settings.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index fe2f7467a..d56b569de 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -106,6 +106,27 @@ TEMPLATES = [ }, ] +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'console': { + 'class': 'logging.StreamHandler', + }, + }, + 'root': { + 'handlers': ['console'], + 'level': 'WARNING', + }, + 'loggers': { + 'django': { + 'handlers': ['console'], + 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), + 'propagate': False, + }, + }, +} + WSGI_APPLICATION = "bookwyrm.wsgi.application" From 83851c29338ac269fefa7bc8971116e70b583e88 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Mon, 10 Jan 2022 06:45:14 +0000 Subject: [PATCH 002/145] Add bookwyrm-specific logging --- bookwyrm/settings.py | 4 ++++ bookwyrm/views/inbox.py | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index d56b569de..31ad75d8f 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -124,6 +124,10 @@ LOGGING = { 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), 'propagate': False, }, + 'bookwyrm': { + 'handlers': ['console'], + 'level': os.getenv('LOG_LEVEL', 'DEBUG' if DEBUG else 'INFO').upper(), + } }, } diff --git a/bookwyrm/views/inbox.py b/bookwyrm/views/inbox.py index 239824958..514cb685b 100644 --- a/bookwyrm/views/inbox.py +++ b/bookwyrm/views/inbox.py @@ -10,12 +10,14 @@ from django.utils.decorators import method_decorator from django.views import View from django.views.decorators.csrf import csrf_exempt import requests +import logging from bookwyrm import activitypub, models from bookwyrm.tasks import app from bookwyrm.signatures import Signature from bookwyrm.utils import regex +logger = logging.getLogger(__name__) @method_decorator(csrf_exempt, name="dispatch") # pylint: disable=no-self-use @@ -71,6 +73,7 @@ def raise_is_blocked_user_agent(request): return url = url.group() if models.FederatedServer.is_blocked(url): + logger.debug(f"{url} is blocked, denying request based on user agent") raise PermissionDenied() @@ -78,16 +81,18 @@ def raise_is_blocked_activity(activity_json): """get the sender out of activity json and check if it's blocked""" actor = activity_json.get("actor") - # check if the user is banned/deleted - existing = models.User.find_existing_by_remote_id(actor) - if existing and existing.deleted: - raise PermissionDenied() - if not actor: # well I guess it's not even a valid activity so who knows return + # check if the user is banned/deleted + existing = models.User.find_existing_by_remote_id(actor) + if existing and existing.deleted: + logger.debug(f"{actor} is banned/deleted, denying request based on actor") + raise PermissionDenied() + if models.FederatedServer.is_blocked(actor): + logger.debug(f"{actor} is blocked, denying request based on actor") raise PermissionDenied() From 085dd24a62df7f08608fea096dcfe198079f4c72 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 9 Jan 2022 23:26:27 -0800 Subject: [PATCH 003/145] Simplify and explain our overrides This should also fix the 500s-in-prod issue, yay --- bookwyrm/settings.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 31ad75d8f..a3b0d48d6 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -106,27 +106,30 @@ TEMPLATES = [ }, ] +LOG_LEVEL = env('LOG_LEVEL', 'INFO').upper() +# Override aspects of the default handler to our taste +# See https://docs.djangoproject.com/en/3.2/topics/logging/#default-logging-configuration +# for a reference to the defaults we're overriding LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { + # Overrides the default handler, which does not log in prod 'console': { + 'level': LOG_LEVEL, 'class': 'logging.StreamHandler', }, }, - 'root': { - 'handlers': ['console'], - 'level': 'WARNING', - }, 'loggers': { + # Override the log level for the default logger 'django': { - 'handlers': ['console'], - 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), - 'propagate': False, + 'handlers': ['console', 'mail_admins'], + 'level': LOG_LEVEL, }, + # Add a bookwyrm-specific logger 'bookwyrm': { 'handlers': ['console'], - 'level': os.getenv('LOG_LEVEL', 'DEBUG' if DEBUG else 'INFO').upper(), + 'level': LOG_LEVEL, } }, } From 5cf1d8a30a50b67a15f1110538238b63eb114283 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 9 Jan 2022 23:53:23 -0800 Subject: [PATCH 004/145] Make it black --- bookwyrm/settings.py | 30 +++++++++++++++--------------- bookwyrm/views/inbox.py | 1 + 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index a3b0d48d6..57a49df0b 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -106,31 +106,31 @@ TEMPLATES = [ }, ] -LOG_LEVEL = env('LOG_LEVEL', 'INFO').upper() +LOG_LEVEL = env("LOG_LEVEL", "INFO").upper() # Override aspects of the default handler to our taste # See https://docs.djangoproject.com/en/3.2/topics/logging/#default-logging-configuration # for a reference to the defaults we're overriding LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'handlers': { + "version": 1, + "disable_existing_loggers": False, + "handlers": { # Overrides the default handler, which does not log in prod - 'console': { - 'level': LOG_LEVEL, - 'class': 'logging.StreamHandler', + "console": { + "level": LOG_LEVEL, + "class": "logging.StreamHandler", }, }, - 'loggers': { + "loggers": { # Override the log level for the default logger - 'django': { - 'handlers': ['console', 'mail_admins'], - 'level': LOG_LEVEL, + "django": { + "handlers": ["console", "mail_admins"], + "level": LOG_LEVEL, }, # Add a bookwyrm-specific logger - 'bookwyrm': { - 'handlers': ['console'], - 'level': LOG_LEVEL, - } + "bookwyrm": { + "handlers": ["console"], + "level": LOG_LEVEL, + }, }, } diff --git a/bookwyrm/views/inbox.py b/bookwyrm/views/inbox.py index 514cb685b..1d2c303b4 100644 --- a/bookwyrm/views/inbox.py +++ b/bookwyrm/views/inbox.py @@ -19,6 +19,7 @@ from bookwyrm.utils import regex logger = logging.getLogger(__name__) + @method_decorator(csrf_exempt, name="dispatch") # pylint: disable=no-self-use class Inbox(View): From 29ebfc456d4e584b11cc993e67e9f84410524bc2 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 9 Jan 2022 23:57:57 -0800 Subject: [PATCH 005/145] Use run --rm instead of exec for initdb This way we don't depend on the containers already being up and running. --- bw-dev | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bw-dev b/bw-dev index 6bf5a125e..29c2660da 100755 --- a/bw-dev +++ b/bw-dev @@ -30,12 +30,12 @@ function execweb { } function initdb { - execweb python manage.py migrate - execweb python manage.py initdb + runweb python manage.py migrate + runweb python manage.py initdb } function makeitblack { - docker-compose run --rm web black celerywyrm bookwyrm + runweb black celerywyrm bookwyrm } function awscommand { From 32acccc350f0d9d32e260935b9163e0abdaae125 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 17 Jan 2022 11:25:41 -0800 Subject: [PATCH 006/145] Use both noopener and noreferrer --- bookwyrm/templates/author/author.html | 12 +- bookwyrm/templates/book/book.html | 4 +- .../templates/book/file_links/edit_links.html | 2 +- bookwyrm/templates/book/file_links/links.html | 2 +- .../book/file_links/verification_modal.html | 2 +- bookwyrm/templates/import/tooltip.html | 2 +- bookwyrm/templates/search/book.html | 2 +- .../federation/instance_blocklist.html | 2 +- .../settings/link_domains/link_domains.html | 2 +- .../settings/link_domains/link_table.html | 2 +- locale/de_DE/LC_MESSAGES/django.mo | Bin 72911 -> 72617 bytes locale/de_DE/LC_MESSAGES/django.po | 374 +++++++++++----- locale/en_US/LC_MESSAGES/django.po | 72 ++-- locale/es_ES/LC_MESSAGES/django.mo | Bin 79543 -> 79237 bytes locale/es_ES/LC_MESSAGES/django.po | 374 +++++++++++----- locale/fr_FR/LC_MESSAGES/django.mo | Bin 79004 -> 81212 bytes locale/fr_FR/LC_MESSAGES/django.po | 400 +++++++++++++----- locale/gl_ES/LC_MESSAGES/django.mo | Bin 77784 -> 77474 bytes locale/gl_ES/LC_MESSAGES/django.po | 374 +++++++++++----- locale/it_IT/LC_MESSAGES/django.mo | Bin 78729 -> 78427 bytes locale/it_IT/LC_MESSAGES/django.po | 374 +++++++++++----- locale/lt_LT/LC_MESSAGES/django.mo | Bin 75364 -> 75079 bytes locale/lt_LT/LC_MESSAGES/django.po | 376 +++++++++++----- locale/no_NO/LC_MESSAGES/django.mo | Bin 75072 -> 74806 bytes locale/no_NO/LC_MESSAGES/django.po | 374 +++++++++++----- locale/pt_BR/LC_MESSAGES/django.mo | Bin 78146 -> 81381 bytes locale/pt_BR/LC_MESSAGES/django.po | 376 +++++++++++----- locale/pt_PT/LC_MESSAGES/django.mo | Bin 73743 -> 73450 bytes locale/pt_PT/LC_MESSAGES/django.po | 374 +++++++++++----- locale/zh_Hans/LC_MESSAGES/django.mo | Bin 67101 -> 66840 bytes locale/zh_Hans/LC_MESSAGES/django.po | 373 +++++++++++----- locale/zh_Hant/LC_MESSAGES/django.mo | Bin 36669 -> 36376 bytes locale/zh_Hant/LC_MESSAGES/django.po | 373 +++++++++++----- 33 files changed, 3123 insertions(+), 1123 deletions(-) diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index 27beeb468..8061d580c 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -66,7 +66,7 @@
{% if author.wikipedia_link %} @@ -74,7 +74,7 @@ {% if author.isni %} @@ -83,7 +83,7 @@ {% trans "Load data" as button_text %} {% if author.openlibrary_key %}
- + {% trans "View on OpenLibrary" %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} @@ -98,7 +98,7 @@ {% if author.inventaire_id %}
- + {% trans "View on Inventaire" %} @@ -114,7 +114,7 @@ {% if author.librarything_key %} @@ -122,7 +122,7 @@ {% if author.goodreads_key %} diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index f6d9929dd..d2ab99b4b 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -122,7 +122,7 @@ {% trans "Load data" as button_text %} {% if book.openlibrary_key %}

- + {% trans "View on OpenLibrary" %} {% if request.user.is_authenticated and perms.bookwyrm.edit_book %} @@ -136,7 +136,7 @@ {% endif %} {% if book.inventaire_id %}

- + {% trans "View on Inventaire" %} diff --git a/bookwyrm/templates/book/file_links/edit_links.html b/bookwyrm/templates/book/file_links/edit_links.html index 8dad6c40a..39d3b998b 100644 --- a/bookwyrm/templates/book/file_links/edit_links.html +++ b/bookwyrm/templates/book/file_links/edit_links.html @@ -39,7 +39,7 @@ {% for link in links %} - {{ link.url }} + {{ link.url }} {{ link.added_by.display_name }} diff --git a/bookwyrm/templates/book/file_links/links.html b/bookwyrm/templates/book/file_links/links.html index 25e0ba89a..fbc95b566 100644 --- a/bookwyrm/templates/book/file_links/links.html +++ b/bookwyrm/templates/book/file_links/links.html @@ -28,7 +28,7 @@ {% for link in links.all %} {% join "verify" link.id as verify_modal %}

  • - {{ link.name }} + {{ link.name }} ({{ link.filetype }}) {% if link.availability != "free" %} diff --git a/bookwyrm/templates/book/file_links/verification_modal.html b/bookwyrm/templates/book/file_links/verification_modal.html index 1d53c1ef2..81685da0f 100644 --- a/bookwyrm/templates/book/file_links/verification_modal.html +++ b/bookwyrm/templates/book/file_links/verification_modal.html @@ -17,7 +17,7 @@ Is that where you'd like to go? {% block modal-footer %} -{% trans "Continue" %} +{% trans "Continue" %} {% if request.user.is_authenticated %} diff --git a/bookwyrm/templates/import/tooltip.html b/bookwyrm/templates/import/tooltip.html index 311cce82c..f2712b7e9 100644 --- a/bookwyrm/templates/import/tooltip.html +++ b/bookwyrm/templates/import/tooltip.html @@ -3,6 +3,6 @@ {% block tooltip_content %} -{% trans 'You can download your Goodreads data from the Import/Export page of your Goodreads account.' %} +{% trans 'You can download your Goodreads data from the Import/Export page of your Goodreads account.' %} {% endblock %} diff --git a/bookwyrm/templates/search/book.html b/bookwyrm/templates/search/book.html index ab62d4734..cc615d508 100644 --- a/bookwyrm/templates/search/book.html +++ b/bookwyrm/templates/search/book.html @@ -63,7 +63,7 @@ {{ result.title }} diff --git a/bookwyrm/templates/settings/federation/instance_blocklist.html b/bookwyrm/templates/settings/federation/instance_blocklist.html index 926ab5f4a..abd580918 100644 --- a/bookwyrm/templates/settings/federation/instance_blocklist.html +++ b/bookwyrm/templates/settings/federation/instance_blocklist.html @@ -47,7 +47,7 @@