forked from bookwyrm-social/bookwyrm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge v0.7.2 (production) into spinoza
Conflicts: requirements.txt
- Loading branch information
Showing
260 changed files
with
20,321 additions
and
5,317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.7.0 | ||
0.7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Import data from Bookwyrm export files""" | ||
from django.http import QueryDict | ||
|
||
from bookwyrm.models import User | ||
from bookwyrm.models.bookwyrm_import_job import BookwyrmImportJob | ||
|
||
|
||
class BookwyrmImporter: | ||
"""Import a Bookwyrm User export file. | ||
This is kind of a combination of an importer and a connector. | ||
""" | ||
|
||
# pylint: disable=no-self-use | ||
def process_import( | ||
self, user: User, archive_file: bytes, settings: QueryDict | ||
) -> BookwyrmImportJob: | ||
"""import user data from a Bookwyrm export file""" | ||
|
||
required = [k for k in settings if settings.get(k) == "on"] | ||
|
||
job = BookwyrmImportJob.objects.create( | ||
user=user, archive_file=archive_file, required=required | ||
) | ||
return job |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" Erase any data stored about deleted users """ | ||
import sys | ||
from django.core.management.base import BaseCommand, CommandError | ||
from bookwyrm import models | ||
from bookwyrm.models.user import erase_user_data | ||
|
||
# pylint: disable=missing-function-docstring | ||
class Command(BaseCommand): | ||
"""command-line options""" | ||
|
||
help = "Remove Two Factor Authorisation from user" | ||
|
||
def add_arguments(self, parser): # pylint: disable=no-self-use | ||
parser.add_argument( | ||
"--dryrun", | ||
action="store_true", | ||
help="Preview users to be cleared without altering the database", | ||
) | ||
|
||
def handle(self, *args, **options): # pylint: disable=unused-argument | ||
|
||
# Check for anything fishy | ||
bad_state = models.User.objects.filter(is_deleted=True, is_active=True) | ||
if bad_state.exists(): | ||
raise CommandError( | ||
f"{bad_state.count()} user(s) marked as both active and deleted" | ||
) | ||
|
||
deleted_users = models.User.objects.filter(is_deleted=True) | ||
self.stdout.write(f"Found {deleted_users.count()} deleted users") | ||
if options["dryrun"]: | ||
self.stdout.write("\n".join(u.username for u in deleted_users[:5])) | ||
if deleted_users.count() > 5: | ||
self.stdout.write("... and more") | ||
sys.exit() | ||
|
||
self.stdout.write("Erasing user data:") | ||
for user_id in deleted_users.values_list("id", flat=True): | ||
erase_user_data.delay(user_id) | ||
self.stdout.write(".", ending="") | ||
|
||
self.stdout.write("") | ||
self.stdout.write("Tasks created successfully") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
""" look at all this nice middleware! """ | ||
from .timezone_middleware import TimezoneMiddleware | ||
from .ip_middleware import IPBlocklistMiddleware | ||
from .file_too_big import FileTooBig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Middleware to display a custom 413 error page""" | ||
|
||
from django.http import HttpResponse | ||
from django.shortcuts import render | ||
from django.core.exceptions import RequestDataTooBig | ||
|
||
|
||
class FileTooBig: | ||
"""Middleware to display a custom page when a | ||
RequestDataTooBig exception is thrown""" | ||
|
||
def __init__(self, get_response): | ||
"""boilerplate __init__ from Django docs""" | ||
|
||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
"""If RequestDataTooBig is thrown, render the 413 error page""" | ||
|
||
try: | ||
body = request.body # pylint: disable=unused-variable | ||
|
||
except RequestDataTooBig: | ||
|
||
rendered = render(request, "413.html") | ||
response = HttpResponse(rendered) | ||
return response | ||
|
||
response = self.get_response(request) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.