From c9f81c9d2754fc53b2316b814a0cd036f1c87d97 Mon Sep 17 00:00:00 2001 From: Margaret Fero Date: Sat, 2 Mar 2024 18:55:24 -0800 Subject: [PATCH] Update to current versions of dependencies (#43) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix multiple issues from user exports config changes - improve nginx config - fix DATA_UPLOAD_MAX_MEMORY_SIZE default not being an int - translate fallback value in id_to_username template tag - make location of setting to turn on user exports easier to locate for admins fixes #3227 fixes #3231 fixes #3232 fixes #3236 * fix comment in env example * Fixes translation tags * Add search for author * Support DATA_UPLOAD_MAX_MEMORY_MiB, only, in .env Since arithmetic is not allowed in .env files, a change in unit for the variable seems most usable. * Adds production.conf security configuration missing in version 0.7.2 * Add timeout to isbn.py An instance of requests.get in isbn.py lacks a timeout, and this commit adds one with a default of 15 as used other places in the code, where requests.get does already have a timeout. * Add timeout to base_activity.py An instance of requests.get was missing a timeout; this commit adds a timeout of 15 as used in other places in this codebase which already have timeouts. * Typo fix Add a comma * Remove duplicate types-requests==2.31.0.2 The types-requests==2.31.0.2 dependency was double-listed right next to each other; this commit removes one. * Alphabetize requirements.txt Alphabetize requirements.txt for developer convenience; this helps to find duplicates and unnecessarily-pinned subdependencies, as well as making the file easier to read and use. * Upgrade Python Version from 3.9 to 3.11 * Disable Pylint Failure for imghdr deprecation for now * Upgrade Celery to 5.3.1 * Upgrade django-celery-beat to 2.5.0 * Upgrade django-compressor to 4.4 * Upgrade flower to 2.0.0 * Add grpcio pin @ 1.57.0 * Pin Tornado at 6.3.3 * Upgrade Pylint to 2.15.0 * Upgrade pytest to 6.2.5 * Pin setuptools at 65.5.1 * Fix typo in operator * Add extra space required by linter * Fix spacing for linter * Add linter exclusion for TBookWyrmModel --------- Co-authored-by: Hugh Rundle Co-authored-by: Mouse Reeve Co-authored-by: Bart Schuurmans Co-authored-by: Adeodato Simó Co-authored-by: Hugh Rundle Co-authored-by: FoW --- .env.example | 8 ++-- .github/workflows/django-tests.yml | 2 +- .github/workflows/mypy.yml | 4 +- .github/workflows/pylint.yml | 4 +- bookwyrm/activitypub/base_activity.py | 2 + bookwyrm/connectors/abstract_connector.py | 4 +- bookwyrm/isbn/isbn.py | 2 +- bookwyrm/settings.py | 4 +- bookwyrm/templates/layout.html | 2 +- .../templates/preferences/export-user.html | 39 +++++++++-------- bookwyrm/templates/search/author.html | 17 ++++++++ bookwyrm/templates/search/layout.html | 4 ++ bookwyrm/templatetags/utilities.py | 2 +- bookwyrm/views/search.py | 27 ++++++++++++ nginx/development | 14 ++++-- nginx/production | 16 +++++-- requirements.txt | 43 ++++++++++--------- 17 files changed, 135 insertions(+), 59 deletions(-) create mode 100644 bookwyrm/templates/search/author.html diff --git a/.env.example b/.env.example index d0971660ef..1bf6d5406f 100644 --- a/.env.example +++ b/.env.example @@ -138,9 +138,9 @@ TWO_FACTOR_LOGIN_MAX_SECONDS=60 # Value should be a comma-separated list of host names. CSP_ADDITIONAL_HOSTS= -# The last number here means "megabytes" -# Increase if users are having trouble uploading BookWyrm export files. -DATA_UPLOAD_MAX_MEMORY_SIZE = (1024**2 * 100) - # Time before being logged out (in seconds) # SESSION_COOKIE_AGE=2592000 # current default: 30 days + +# Maximum allowed memory for file uploads (increase if users are having trouble +# uploading BookWyrm export files). +# DATA_UPLOAD_MAX_MEMORY_MiB=100 diff --git a/.github/workflows/django-tests.yml b/.github/workflows/django-tests.yml index 78b6e142ed..de71d9bcfc 100644 --- a/.github/workflows/django-tests.yml +++ b/.github/workflows/django-tests.yml @@ -27,7 +27,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: 3.11 - name: Install Dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 1a641edd28..6df987aa4f 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python 3.9 + - name: Set up Python 3.11 uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: 3.11 - name: Install Dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 3811c97d38..ab8633b48c 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -13,10 +13,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python 3.9 + - name: Set up Python 3.11 uses: actions/setup-python@v4 with: - python-version: 3.9 + python-version: 3.11 - name: Install Dependencies run: | python -m pip install --upgrade pip diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index fbbc18f73e..efc9d8da2f 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -20,6 +20,7 @@ logger = logging.getLogger(__name__) +# pylint: disable=invalid-name TBookWyrmModel = TypeVar("TBookWyrmModel", bound=base_model.BookWyrmModel) @@ -423,6 +424,7 @@ def get_activitypub_data(url): "Date": now, "Signature": make_signature("get", sender, url, now), }, + timeout=15, ) except requests.RequestException: raise ConnectorException() diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 8b6dcb8858..aa8edbeae9 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -3,7 +3,9 @@ from abc import ABC, abstractmethod from typing import Optional, TypedDict, Any, Callable, Union, Iterator from urllib.parse import quote_plus -import imghdr + +# pylint: disable-next=deprecated-module +import imghdr # Deprecated in 3.11 for removal in 3.13; no good alternative yet import logging import re import asyncio diff --git a/bookwyrm/isbn/isbn.py b/bookwyrm/isbn/isbn.py index 56062ff7b8..d14dc26196 100644 --- a/bookwyrm/isbn/isbn.py +++ b/bookwyrm/isbn/isbn.py @@ -26,7 +26,7 @@ class IsbnHyphenator: def update_range_message(self) -> None: """Download the range message xml file and save it locally""" - response = requests.get(self.__range_message_url) + response = requests.get(self.__range_message_url, timeout=15) with open(self.__range_file_path, "w", encoding="utf-8") as file: file.write(response.text) self.__element_tree = None diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 7f45573c92..2bb68ff857 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -446,4 +446,6 @@ # user with the same username - in which case you should change it! INSTANCE_ACTOR_USERNAME = "bookwyrm.instance.actor" -DATA_UPLOAD_MAX_MEMORY_SIZE = env.int("DATA_UPLOAD_MAX_MEMORY_SIZE", (1024**2 * 100)) +# We only allow specifying DATA_UPLOAD_MAX_MEMORY_SIZE in MiB from .env +# (note the difference in variable names). +DATA_UPLOAD_MAX_MEMORY_SIZE = env.int("DATA_UPLOAD_MAX_MEMORY_MiB", 100) << 20 diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 6283e61c45..ced4e80061 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -36,7 +36,7 @@
{% if request.user.is_authenticated %} - {% trans "Search for a book, user, or list" as search_placeholder %} + {% trans "Search for a book, author, user, or list" as search_placeholder %} {% else %} {% trans "Search for a book" as search_placeholder %} {% endif %} diff --git a/bookwyrm/templates/preferences/export-user.html b/bookwyrm/templates/preferences/export-user.html index cd3119e3e7..955cff6561 100644 --- a/bookwyrm/templates/preferences/export-user.html +++ b/bookwyrm/templates/preferences/export-user.html @@ -14,31 +14,29 @@

{% trans "You can create an export file here. This will allow you to migrate your data to another BookWyrm account." %}

- {% blocktrans trimmed %}
-

Your file will include:

+

{% trans "Your file will include:" %}

    -
  • User profile
  • -
  • Most user settings
  • -
  • Reading goals
  • -
  • Shelves
  • -
  • Reading history
  • -
  • Book reviews
  • -
  • Statuses
  • -
  • Your own lists and saved lists
  • -
  • Which users you follow and block
  • +
  • {% trans "User profile" %}
  • +
  • {% trans "Most user settings" %}
  • +
  • {% trans "Reading goals" %}
  • +
  • {% trans "Shelves" %}
  • +
  • {% trans "Reading history" %}
  • +
  • {% trans "Book reviews" %}
  • +
  • {% trans "Statuses" %}
  • +
  • {% trans "Your own lists and saved lists" %}
  • +
  • {% trans "Which users you follow and block" %}
-

Your file will not include:

+

{% trans "Your file will not include:" %}

    -
  • Direct messages
  • -
  • Replies to your statuses
  • -
  • Groups
  • -
  • Favorites
  • +
  • {% trans "Direct messages" %}
  • +
  • {% trans "Replies to your statuses" %}
  • +
  • {% trans "Groups" %}
  • +
  • {% trans "Favorites" %}
- {% endblocktrans %}

{% trans "In your new BookWyrm account can choose what to import: you will not have to import everything that is exported." %}

@@ -49,6 +47,13 @@

Your file will not include:

{% if not site.user_exports_enabled %}

{% trans "New user exports are currently disabled." %} + {% if perms.bookwyrm.edit_instance_settings %} +
+ {% url 'settings-imports' as url %} + {% blocktrans trimmed %} + User exports settings can be changed from the Imports page in the Admin dashboard. + {% endblocktrans %} + {% endif%}

{% elif next_available %}

diff --git a/bookwyrm/templates/search/author.html b/bookwyrm/templates/search/author.html new file mode 100644 index 0000000000..d42c3b54f4 --- /dev/null +++ b/bookwyrm/templates/search/author.html @@ -0,0 +1,17 @@ +{% extends 'search/layout.html' %} + +{% block panel %} + +{% if results %} +

+{% endif %} + +{% endblock %} diff --git a/bookwyrm/templates/search/layout.html b/bookwyrm/templates/search/layout.html index 8cf47b3717..725a4f43f3 100644 --- a/bookwyrm/templates/search/layout.html +++ b/bookwyrm/templates/search/layout.html @@ -20,6 +20,7 @@