From db8c686dd35df0126ee770455651d99d15458c82 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Wed, 3 Jan 2024 15:43:15 +0100 Subject: [PATCH 01/15] Include book Readtrhough in the csv export --- bookwyrm/views/preferences/export.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index f54d97ccb..c691e2f50 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -54,6 +54,7 @@ class Export(View): fields = ( ["title", "author_text"] + deduplication_fields + + ["start_date", "finish_date", "stopped_date"] + ["rating", "review_name", "review_cw", "review_content"] ) writer.writerow(fields) @@ -70,6 +71,18 @@ class Export(View): book.rating = review_rating.rating if review_rating else None + readthrough = ( + models.ReadThrough.objects.filter( + user=request.user, book=book + ) + .order_by("-finish_date") + .first() + ) + if readthrough: + book.start_date = readthrough.start_date + book.finish_date = readthrough.finish_date + book.stopped_date = readthrough.stopped_date + review = ( models.Review.objects.filter( user=request.user, book=book, content__isnull=False From 766a2163ddc745afe0ecc4871f38d37235cb2cb9 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Wed, 3 Jan 2024 20:41:31 +0100 Subject: [PATCH 02/15] Code formatting --- bookwyrm/views/preferences/export.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index c691e2f50..5a3b0fd8e 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -72,9 +72,7 @@ class Export(View): book.rating = review_rating.rating if review_rating else None readthrough = ( - models.ReadThrough.objects.filter( - user=request.user, book=book - ) + models.ReadThrough.objects.filter(user=request.user, book=book) .order_by("-finish_date") .first() ) From ae5950f1871f2ac168c810a0a6bc98c7b5e37474 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:03:07 +0100 Subject: [PATCH 03/15] Add readthrough fields to text_export.py --- bookwyrm/tests/views/preferences/test_export.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 4f498f589..d633ae952 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -66,7 +66,7 @@ class ExportViews(TestCase): # pylint: disable=line-too-long self.assertEqual( export.content, - b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,rating,review_name,review_cw,review_content\r\nTest Book,," + b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,start_date,finish_date,stopped_date,rating,review_name,review_cw,review_content\r\nTest Book,," + self.book.remote_id.encode("utf-8") - + b",,,,,beep,,,,,,123456789X,9781234567890,,,,,\r\n", + + b",,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,\r\n", ) From 9acb5f66fee9e64f43c703f1dd631146f35a7724 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:26:44 +0100 Subject: [PATCH 04/15] Convert DateTime to date --- bookwyrm/views/preferences/export.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index 5a3b0fd8e..4353cf259 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -77,9 +77,9 @@ class Export(View): .first() ) if readthrough: - book.start_date = readthrough.start_date - book.finish_date = readthrough.finish_date - book.stopped_date = readthrough.stopped_date + book.start_date = readthrough.start_date.date() if readthrough.start_date else "" + book.finish_date = readthrough.finish_date.date() if readthrough.finish_date else "" + book.stopped_date = readthrough.stopped_date.date() if readthrough.stopped_date else "" review = ( models.Review.objects.filter( From 51cb70d34423afb65653947bff15a90a8fc3278e Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:27:17 +0100 Subject: [PATCH 05/15] Change readhtrough order --- bookwyrm/views/preferences/export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index 4353cf259..c8badbc8c 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -73,7 +73,7 @@ class Export(View): readthrough = ( models.ReadThrough.objects.filter(user=request.user, book=book) - .order_by("-finish_date") + .order_by("-start_date","-finish_date") .first() ) if readthrough: From 30c9ec9611530ee8d98eaef8fc046c5e514d9f28 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:28:17 +0100 Subject: [PATCH 06/15] Prevent lint error See @hughrun 's explanation https://github.com/bookwyrm-social/bookwyrm/pull/3189#issuecomment-1876145423 --- bookwyrm/tests/views/preferences/test_export.py | 4 +++- bookwyrm/views/preferences/export.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index d633ae952..2ef0f96fb 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -38,6 +38,8 @@ class ExportViews(TestCase): parent_work=self.work, isbn_13="9781234567890", bnf_id="beep", + start_date="2023-01-04", + finish_date="2024-01-04" ) def setUp(self): @@ -68,5 +70,5 @@ class ExportViews(TestCase): export.content, b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,start_date,finish_date,stopped_date,rating,review_name,review_cw,review_content\r\nTest Book,," + self.book.remote_id.encode("utf-8") - + b",,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,\r\n", + + b",,,,,beep,,,,,,123456789X,9781234567890,,,2023-01-04,2024-01-04,,,,\r\n", ) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index c8badbc8c..2450a427d 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -103,7 +103,7 @@ class Export(View): ) -# pylint: disable=no-self-use +# pylint: disable=no-self-use,too-many-locals @method_decorator(login_required, name="dispatch") class ExportUser(View): """Let users export user data to import into another Bookwyrm instance""" From ebcc81dd73b295141a16407fded008d3c0abb85d Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:33:26 +0100 Subject: [PATCH 07/15] Revert changes to default book These changes were introduced by mistake in my previous commit. --- bookwyrm/tests/views/preferences/test_export.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 2ef0f96fb..74201ddad 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -37,9 +37,7 @@ class ExportViews(TestCase): remote_id="https://example.com/book/1", parent_work=self.work, isbn_13="9781234567890", - bnf_id="beep", - start_date="2023-01-04", - finish_date="2024-01-04" + bnf_id="beep" ) def setUp(self): @@ -70,5 +68,5 @@ class ExportViews(TestCase): export.content, b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,start_date,finish_date,stopped_date,rating,review_name,review_cw,review_content\r\nTest Book,," + self.book.remote_id.encode("utf-8") - + b",,,,,beep,,,,,,123456789X,9781234567890,,,2023-01-04,2024-01-04,,,,\r\n", + + b",,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,\r\n", ) From c2622a510cd40eb3883eae4d01ccf2095754aa3b Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Thu, 4 Jan 2024 11:40:40 +0100 Subject: [PATCH 08/15] Change else statement to None vs "" --- bookwyrm/views/preferences/export.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index 2450a427d..a6d51e24a 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -77,9 +77,9 @@ class Export(View): .first() ) if readthrough: - book.start_date = readthrough.start_date.date() if readthrough.start_date else "" - book.finish_date = readthrough.finish_date.date() if readthrough.finish_date else "" - book.stopped_date = readthrough.stopped_date.date() if readthrough.stopped_date else "" + book.start_date = readthrough.start_date.date() if readthrough.start_date else None + book.finish_date = readthrough.finish_date.date() if readthrough.finish_date else None + book.stopped_date = readthrough.stopped_date.date() if readthrough.stopped_date else None review = ( models.Review.objects.filter( From 93cab480d6a7cc1d8897d8a0a765c6ce9f5301a4 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Sat, 6 Jan 2024 09:50:14 +0100 Subject: [PATCH 09/15] Code format --- bookwyrm/tests/views/preferences/test_export.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 74201ddad..d633ae952 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -37,7 +37,7 @@ class ExportViews(TestCase): remote_id="https://example.com/book/1", parent_work=self.work, isbn_13="9781234567890", - bnf_id="beep" + bnf_id="beep", ) def setUp(self): From ce18d343e8de7a40b2da17fae0ebff1c065eda9f Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Sat, 6 Jan 2024 09:53:22 +0100 Subject: [PATCH 10/15] Fix pylint error and code format --- bookwyrm/views/preferences/export.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index a6d51e24a..3443be461 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -17,7 +17,7 @@ from bookwyrm import models from bookwyrm.models.bookwyrm_export_job import BookwyrmExportJob from bookwyrm.settings import PAGE_LENGTH -# pylint: disable=no-self-use +# pylint: disable=no-self-use,too-many-locals @method_decorator(login_required, name="dispatch") class Export(View): """Let users export data""" @@ -73,13 +73,21 @@ class Export(View): readthrough = ( models.ReadThrough.objects.filter(user=request.user, book=book) - .order_by("-start_date","-finish_date") + .order_by("-start_date", "-finish_date") .first() ) if readthrough: - book.start_date = readthrough.start_date.date() if readthrough.start_date else None - book.finish_date = readthrough.finish_date.date() if readthrough.finish_date else None - book.stopped_date = readthrough.stopped_date.date() if readthrough.stopped_date else None + book.start_date = ( + readthrough.start_date.date() if readthrough.start_date else None + ) + book.finish_date = ( + readthrough.finish_date.date() if readthrough.finish_date else None + ) + book.stopped_date = ( + readthrough.stopped_date.date() + if readthrough.stopped_date + else None + ) review = ( models.Review.objects.filter( @@ -103,7 +111,7 @@ class Export(View): ) -# pylint: disable=no-self-use,too-many-locals +# pylint: disable=no-self-use @method_decorator(login_required, name="dispatch") class ExportUser(View): """Let users export user data to import into another Bookwyrm instance""" From 854eb36618fe4371b37b4da3a86c68d6778d195b Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Sat, 13 Jan 2024 16:43:41 +0000 Subject: [PATCH 11/15] Export bookshelves and review date --- .../tests/views/preferences/test_export.py | 9 +++-- bookwyrm/views/preferences/export.py | 36 +++++++++++++++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index d633ae952..7a1bcd6db 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -18,7 +18,9 @@ class ExportViews(TestCase): """viewing and creating statuses""" @classmethod - def setUpTestData(self): # pylint: disable=bad-classmethod-argument + def setUpTestData( + self, + ): # pylint: disable=bad-classmethod-argument, disable=invalid-name """we need basic test data and mocks""" with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch( "bookwyrm.activitystreams.populate_stream_task.delay" @@ -40,6 +42,7 @@ class ExportViews(TestCase): bnf_id="beep", ) + # pylint: disable=invalid-name def setUp(self): """individual test setup""" self.factory = RequestFactory() @@ -66,7 +69,7 @@ class ExportViews(TestCase): # pylint: disable=line-too-long self.assertEqual( export.content, - b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,start_date,finish_date,stopped_date,rating,review_name,review_cw,review_content\r\nTest Book,," + b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,start_date,finish_date,stopped_date,rating,review_name,review_cw,review_content,review_published,shelf,shelf_name,shelf_date\r\nTest Book,," + self.book.remote_id.encode("utf-8") - + b",,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,\r\n", + + b",,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,,,,,\r\n", ) diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index 3443be461..d16f3aaa3 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -17,6 +17,7 @@ from bookwyrm import models from bookwyrm.models.bookwyrm_export_job import BookwyrmExportJob from bookwyrm.settings import PAGE_LENGTH + # pylint: disable=no-self-use,too-many-locals @method_decorator(login_required, name="dispatch") class Export(View): @@ -54,8 +55,19 @@ class Export(View): fields = ( ["title", "author_text"] + deduplication_fields - + ["start_date", "finish_date", "stopped_date"] - + ["rating", "review_name", "review_cw", "review_content"] + + [ + "start_date", + "finish_date", + "stopped_date", + "rating", + "review_name", + "review_cw", + "review_content", + "review_published", + "shelf", + "shelf_name", + "shelf_date", + ] ) writer.writerow(fields) @@ -97,9 +109,27 @@ class Export(View): .first() ) if review: + book.review_published = ( + review.published_date.date() if review.published_date else None + ) book.review_name = review.name book.review_cw = review.content_warning - book.review_content = review.raw_content + book.review_content = ( + review.raw_content if review.raw_content else review.content + ) # GoodReads imported reviews do not have raw_content, but content. + + shelfbook = ( + models.ShelfBook.objects.filter(user=request.user, book=book) + .order_by("-shelved_date", "-created_date", "-updated_date") + .last() + ) + if shelfbook: + book.shelf = shelfbook.shelf.identifier + book.shelf_name = shelfbook.shelf.name + book.shelf_date = ( + shelfbook.shelved_date.date() if shelfbook.shelved_date else None + ) + writer.writerow([getattr(book, field, "") or "" for field in fields]) return HttpResponse( From ddbda3ab9ca1f1e4658e711d3a5e5fbd971369c4 Mon Sep 17 00:00:00 2001 From: Carlos Camara Date: Tue, 16 Jan 2024 08:12:24 +0000 Subject: [PATCH 12/15] Fix test_export --- bookwyrm/tests/views/preferences/test_export.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bookwyrm/tests/views/preferences/test_export.py b/bookwyrm/tests/views/preferences/test_export.py index 7a1bcd6db..3f758b2f7 100644 --- a/bookwyrm/tests/views/preferences/test_export.py +++ b/bookwyrm/tests/views/preferences/test_export.py @@ -56,11 +56,12 @@ class ExportViews(TestCase): def test_export_file(self, *_): """simple export""" - models.ShelfBook.objects.create( + shelfbook = models.ShelfBook.objects.create( shelf=self.local_user.shelf_set.first(), user=self.local_user, book=self.book, ) + book_date = str.encode(f"{shelfbook.shelved_date.date()}") request = self.factory.post("") request.user = self.local_user export = views.Export.as_view()(request) @@ -69,7 +70,7 @@ class ExportViews(TestCase): # pylint: disable=line-too-long self.assertEqual( export.content, - b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,start_date,finish_date,stopped_date,rating,review_name,review_cw,review_content,review_published,shelf,shelf_name,shelf_date\r\nTest Book,," - + self.book.remote_id.encode("utf-8") - + b",,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,,,,,\r\n", + b"title,author_text,remote_id,openlibrary_key,inventaire_id,librarything_key,goodreads_key,bnf_id,viaf,wikidata,asin,aasin,isfdb,isbn_10,isbn_13,oclc_number,start_date,finish_date,stopped_date,rating,review_name,review_cw,review_content,review_published,shelf,shelf_name,shelf_date\r\n" + + b"Test Book,,%b,,,,,beep,,,,,,123456789X,9781234567890,,,,,,,,,,to-read,To Read,%b\r\n" + % (self.book.remote_id.encode("utf-8"), book_date), ) From d640e4ac96005cdc2b21b6a08f97a8805c26d00b Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 16 Jan 2024 21:32:13 +1100 Subject: [PATCH 13/15] disable user exports by default - new setting to enable user exports defaults to False - add setting to enable and disable user exports - do not allow user exports when using s3 storage - do not serve non-image files from /images/ (requires update to nginx settings) - increase default file upload limit to 100MB to enable user exports to be imported (can be changed in .env) --- .env.example | 3 ++ .../0192_sitesettings_user_exports_enabled.py | 18 +++++++ bookwyrm/models/site.py | 1 + bookwyrm/settings.py | 2 + .../templates/preferences/export-user.html | 6 ++- .../templates/settings/imports/imports.html | 51 ++++++++++++++++++- bookwyrm/urls.py | 10 ++++ bookwyrm/views/__init__.py | 2 + bookwyrm/views/admin/imports.py | 25 ++++++++- nginx/development | 7 ++- nginx/production | 7 ++- 11 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 bookwyrm/migrations/0192_sitesettings_user_exports_enabled.py diff --git a/.env.example b/.env.example index fb0f7308d..20ce8240b 100644 --- a/.env.example +++ b/.env.example @@ -137,3 +137,6 @@ TWO_FACTOR_LOGIN_MAX_SECONDS=60 # and AWS_S3_CUSTOM_DOMAIN (if used) are added by default. # 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) \ No newline at end of file diff --git a/bookwyrm/migrations/0192_sitesettings_user_exports_enabled.py b/bookwyrm/migrations/0192_sitesettings_user_exports_enabled.py new file mode 100644 index 000000000..ec5b411e2 --- /dev/null +++ b/bookwyrm/migrations/0192_sitesettings_user_exports_enabled.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.23 on 2024-01-16 10:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0191_merge_20240102_0326"), + ] + + operations = [ + migrations.AddField( + model_name="sitesettings", + name="user_exports_enabled", + field=models.BooleanField(default=False), + ), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index bd53f1f07..8075b6434 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -96,6 +96,7 @@ class SiteSettings(SiteModel): imports_enabled = models.BooleanField(default=True) import_size_limit = models.IntegerField(default=0) import_limit_reset = models.IntegerField(default=0) + user_exports_enabled = models.BooleanField(default=False) user_import_time_limit = models.IntegerField(default=48) field_tracker = FieldTracker(fields=["name", "instance_tagline", "logo"]) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index fcc91857a..cc941da84 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -442,3 +442,5 @@ if HTTP_X_FORWARDED_PROTO: # Do not change this setting unless you already have an existing # 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)) diff --git a/bookwyrm/templates/preferences/export-user.html b/bookwyrm/templates/preferences/export-user.html index a468c3f74..cd3119e3e 100644 --- a/bookwyrm/templates/preferences/export-user.html +++ b/bookwyrm/templates/preferences/export-user.html @@ -46,7 +46,11 @@ {% trans "If you wish to migrate any statuses (comments, reviews, or quotes) you must either set the account you are moving to as an alias of this one, or move this account to the new account, before you import your user data." %} {% endspaceless %}

- {% if next_available %} + {% if not site.user_exports_enabled %} +

+ {% trans "New user exports are currently disabled." %} +

+ {% elif next_available %}

{% blocktrans trimmed %} You will be able to create a new export file at {{ next_available }} diff --git a/bookwyrm/templates/settings/imports/imports.html b/bookwyrm/templates/settings/imports/imports.html index 8898aab71..11b3c7e03 100644 --- a/bookwyrm/templates/settings/imports/imports.html +++ b/bookwyrm/templates/settings/imports/imports.html @@ -90,6 +90,33 @@ + + {% if site.user_exports_enabled %} +

+ + + {% trans "Disable starting new user exports" %} + + + +
+
+ {% trans "This is only intended to be used when things have gone very wrong with exports and you need to pause the feature while addressing issues." %} + {% trans "While exports are disabled, users will not be allowed to start new user exports, but existing exports will not be affected." %} +
+ {% csrf_token %} +
+ +
+
+
@@ -108,7 +135,7 @@ {% trans "Set the value to 0 to not enforce any limit." %}
- + {% csrf_token %} @@ -120,6 +147,28 @@
+ {% else %} +
+
+

{% trans "Users are currently unable to start new user exports. This is the default setting." %}

+ {% if use_s3 %} +

{% trans "It is not currently possible to provide user exports when using s3 storage. The BookWyrm development team are working on a fix for this." %}

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

{% trans "Book Imports" %}

diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 76e60245b..1a577c84b 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -338,6 +338,16 @@ urlpatterns = [ views.disable_imports, name="settings-imports-disable", ), + re_path( + r"^settings/user-exports/enable/?$", + views.enable_user_exports, + name="settings-user-exports-enable", + ), + re_path( + r"^settings/user-exports/disable/?$", + views.disable_user_exports, + name="settings-user-exports-disable", + ), re_path( r"^settings/imports/enable/?$", views.enable_imports, diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 3be813208..f11c11dd6 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -18,6 +18,8 @@ from .admin.imports import ( set_import_size_limit, set_user_import_completed, set_user_import_limit, + enable_user_exports, + disable_user_exports, ) from .admin.ip_blocklist import IPBlocklist from .admin.invite import ManageInvites, Invite, InviteRequest diff --git a/bookwyrm/views/admin/imports.py b/bookwyrm/views/admin/imports.py index a85d6c79e..0924536bf 100644 --- a/bookwyrm/views/admin/imports.py +++ b/bookwyrm/views/admin/imports.py @@ -9,7 +9,7 @@ from django.views.decorators.http import require_POST from bookwyrm import models from bookwyrm.views.helpers import redirect_to_referer -from bookwyrm.settings import PAGE_LENGTH +from bookwyrm.settings import PAGE_LENGTH, USE_S3 # pylint: disable=no-self-use @@ -59,6 +59,7 @@ class ImportList(View): "import_size_limit": site_settings.import_size_limit, "import_limit_reset": site_settings.import_limit_reset, "user_import_time_limit": site_settings.user_import_time_limit, + "use_s3": USE_S3, } return TemplateResponse(request, "settings/imports/imports.html", data) @@ -126,3 +127,25 @@ def set_user_import_limit(request): site.user_import_time_limit = int(request.POST.get("limit")) site.save(update_fields=["user_import_time_limit"]) return redirect("settings-imports") + + +@require_POST +@permission_required("bookwyrm.edit_instance_settings", raise_exception=True) +# pylint: disable=unused-argument +def enable_user_exports(request): + """Allow users to export account data""" + site = models.SiteSettings.objects.get() + site.user_exports_enabled = True + site.save(update_fields=["user_exports_enabled"]) + return redirect("settings-imports") + + +@require_POST +@permission_required("bookwyrm.edit_instance_settings", raise_exception=True) +# pylint: disable=unused-argument +def disable_user_exports(request): + """Don't allow users to export account data""" + site = models.SiteSettings.objects.get() + site.user_exports_enabled = False + site.save(update_fields=["user_exports_enabled"]) + return redirect("settings-imports") diff --git a/nginx/development b/nginx/development index 841db0124..ac663053c 100644 --- a/nginx/development +++ b/nginx/development @@ -64,13 +64,18 @@ server { # directly serve images and static files from the # bookwyrm filesystem using sendfile. # make the logs quieter by not reporting these requests - location ~ ^/(images|static)/ { + location ~ \.(bmp|ico|jpg|jpeg|png|tif|tiff|webp)$ { root /app; try_files $uri =404; add_header X-Cache-Status STATIC; access_log off; } + # block access to any non-image files from images or static + location ~ ^/(images|static)/ { + return 403; + } + # monitor the celery queues with flower, no caching enabled location /flower/ { proxy_pass http://flower:8888; diff --git a/nginx/production b/nginx/production index 9018ab9de..4e40f32a0 100644 --- a/nginx/production +++ b/nginx/production @@ -96,12 +96,17 @@ server { # # directly serve images and static files from the # # bookwyrm filesystem using sendfile. # # make the logs quieter by not reporting these requests -# location ~ ^/(images|static)/ { +# location ~ \.(bmp|ico|jpg|jpeg|png|tif|tiff|webp)$ { # root /app; # try_files $uri =404; # add_header X-Cache-Status STATIC; # access_log off; # } + +# # block access to any non-image files from images or static +# location ~ ^/(images|static)/ { +# return 403; +# } # # # monitor the celery queues with flower, no caching enabled # location /flower/ { From ea7f3c297e6f92ca82c06b6fb3ace0d37ebdd53f Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Wed, 17 Jan 2024 20:12:06 +1100 Subject: [PATCH 14/15] allow js and css --- nginx/development | 4 ++-- nginx/production | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nginx/development b/nginx/development index ac663053c..64cd1b911 100644 --- a/nginx/development +++ b/nginx/development @@ -64,7 +64,7 @@ server { # directly serve images and static files from the # bookwyrm filesystem using sendfile. # make the logs quieter by not reporting these requests - location ~ \.(bmp|ico|jpg|jpeg|png|tif|tiff|webp)$ { + location ~ \.(bmp|ico|jpg|jpeg|png|tif|tiff|webp|css|js)$ { root /app; try_files $uri =404; add_header X-Cache-Status STATIC; @@ -72,7 +72,7 @@ server { } # block access to any non-image files from images or static - location ~ ^/(images|static)/ { + location ~ ^/images/ { return 403; } diff --git a/nginx/production b/nginx/production index 4e40f32a0..76ed19449 100644 --- a/nginx/production +++ b/nginx/production @@ -96,7 +96,7 @@ server { # # directly serve images and static files from the # # bookwyrm filesystem using sendfile. # # make the logs quieter by not reporting these requests -# location ~ \.(bmp|ico|jpg|jpeg|png|tif|tiff|webp)$ { +# location ~ \.(bmp|ico|jpg|jpeg|png|tif|tiff|webp|css|js)$ { # root /app; # try_files $uri =404; # add_header X-Cache-Status STATIC; @@ -104,7 +104,7 @@ server { # } # # block access to any non-image files from images or static -# location ~ ^/(images|static)/ { +# location ~ ^/images/ { # return 403; # } # From b990d9ccd8f2bff4990b79f7dc7cd494190d0536 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Wed, 17 Jan 2024 21:06:04 +1100 Subject: [PATCH 15/15] Pass correct user id in Move notification We were passing the *requesting* user's moved_to value to the Move notification template, instead of the id of the user that they are being notified about. Additionally, the id_to_username template tag had no fallback for if the user_id is None. This resolves both problems and removes an unnecessary space in a template for when the logged in user made the move. Fixes #3196 --- bookwyrm/templates/moved.html | 2 +- bookwyrm/templates/notifications/items/move_user.html | 2 +- bookwyrm/templatetags/utilities.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/moved.html b/bookwyrm/templates/moved.html index 545fc3d87..382b752be 100644 --- a/bookwyrm/templates/moved.html +++ b/bookwyrm/templates/moved.html @@ -23,7 +23,7 @@

- {% id_to_username request.user.moved_to as username %} + {% id_to_username request.user.moved_to as username %} {% blocktrans trimmed with moved_to=user.moved_to %} You have moved your account to {{ username }} {% endblocktrans %} diff --git a/bookwyrm/templates/notifications/items/move_user.html b/bookwyrm/templates/notifications/items/move_user.html index b94d96dc4..3121d3f45 100644 --- a/bookwyrm/templates/notifications/items/move_user.html +++ b/bookwyrm/templates/notifications/items/move_user.html @@ -14,7 +14,7 @@ {% block description %} {% if related_user_moved_to %} - {% id_to_username request.user.moved_to as username %} + {% id_to_username related_user_moved_to as username %} {% blocktrans trimmed %} {{ related_user }} has moved to {{ username }} {% endblocktrans %} diff --git a/bookwyrm/templatetags/utilities.py b/bookwyrm/templatetags/utilities.py index fca66688a..230db366e 100644 --- a/bookwyrm/templatetags/utilities.py +++ b/bookwyrm/templatetags/utilities.py @@ -125,7 +125,8 @@ def id_to_username(user_id): name = parts[-1] value = f"{name}@{domain}" - return value + return value + return "a new user account" @register.filter(name="get_file_size")