mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-22 23:18:08 +00:00
cooldown period for user exports
add USER_EXPORT_COOLDOWN_HOURS setting for controlling user exports and imports
This commit is contained in:
parent
20114b0059
commit
836127f369
5 changed files with 32 additions and 23 deletions
|
@ -423,3 +423,6 @@ 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"
|
||||
|
||||
# exports
|
||||
USER_EXPORT_COOLDOWN_HOURS = 48
|
|
@ -15,28 +15,12 @@
|
|||
{% endif %}
|
||||
|
||||
|
||||
{% if import_size_limit and import_limit_reset %}
|
||||
<div class="notification">
|
||||
<p>{% blocktrans %}Currently you are allowed to import one user every {{ user_import_limit_reset }} days.{% endblocktrans %}</p>
|
||||
<p>{% blocktrans %}You have {{ allowed_imports }} left.{% endblocktrans %}</p>
|
||||
{% if next_available %}
|
||||
<div class="notification is-warning">
|
||||
<p>{% blocktrans %}Currently you are allowed to import one user every {{ user_import_hours }} hours.{% endblocktrans %}</p>
|
||||
<p>{% blocktrans %}You will next be able to import a user file at {{ next_available }}{% endblocktrans %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if recent_avg_hours or recent_avg_minutes %}
|
||||
<div class="notification">
|
||||
<p>
|
||||
{% if recent_avg_hours %}
|
||||
{% blocktrans trimmed with hours=recent_avg_hours|floatformat:0|intcomma %}
|
||||
On average, recent imports have taken {{ hours }} hours.
|
||||
{% endblocktrans %}
|
||||
{% else %}
|
||||
{% blocktrans trimmed with minutes=recent_avg_minutes|floatformat:0|intcomma %}
|
||||
On average, recent imports have taken {{ minutes }} minutes.
|
||||
{% endblocktrans %}
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<form class="box" name="import-user" action="/user-import" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
|
||||
|
@ -100,6 +84,7 @@
|
|||
<p>{% trans "You've reached the import limit." %}</p>
|
||||
{% endif%}
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -9,6 +9,13 @@
|
|||
|
||||
{% block panel %}
|
||||
<div class="block content">
|
||||
{% if next_available %}
|
||||
<p class="notification is-warning">
|
||||
{% blocktrans %}
|
||||
You will be able to create a new export file at {{ next_available }}
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
{% else %}
|
||||
<p class="notification">
|
||||
{% trans "Your exported archive file will include all user data for import into another Bookwyrm server" %}
|
||||
</p>
|
||||
|
@ -19,6 +26,8 @@
|
|||
<span>{% trans "Create user export file" %}</span>
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
<div class="content block">
|
||||
<h2 class="title">{% trans "Recent Exports" %}</h2>
|
||||
|
|
|
@ -23,7 +23,7 @@ from bookwyrm.importers import (
|
|||
OpenLibraryImporter,
|
||||
)
|
||||
from bookwyrm.models.bookwyrm_import_job import BookwyrmImportJob
|
||||
from bookwyrm.settings import PAGE_LENGTH
|
||||
from bookwyrm.settings import PAGE_LENGTH, USER_EXPORT_COOLDOWN_HOURS
|
||||
from bookwyrm.utils.cache import get_or_set
|
||||
|
||||
# pylint: disable= no-self-use
|
||||
|
@ -142,11 +142,16 @@ class UserImport(View):
|
|||
jobs = BookwyrmImportJob.objects.filter(user=request.user).order_by(
|
||||
"-created_date"
|
||||
)
|
||||
hours = USER_EXPORT_COOLDOWN_HOURS
|
||||
allowed = jobs.first().created_date < timezone.now() - datetime.timedelta(hours=hours)
|
||||
next_available = jobs.first().created_date + datetime.timedelta(hours=hours) if not allowed else False
|
||||
paginated = Paginator(jobs, PAGE_LENGTH)
|
||||
page = paginated.get_page(request.GET.get("page"))
|
||||
data = {
|
||||
"import_form": forms.ImportUserForm(),
|
||||
"jobs": page,
|
||||
"user_import_hours": hours,
|
||||
"next_available": next_available,
|
||||
"page_range": paginated.get_elided_page_range(
|
||||
page.number, on_each_side=2, on_ends=1
|
||||
),
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
""" Let users export their book data """
|
||||
from datetime import timedelta
|
||||
import csv
|
||||
import io
|
||||
|
||||
|
@ -7,11 +8,12 @@ from django.core.paginator import Paginator
|
|||
from django.db.models import Q
|
||||
from django.http import HttpResponse
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils import timezone
|
||||
from django.views import View
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.shortcuts import redirect
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm import models, settings
|
||||
from bookwyrm.models.bookwyrm_export_job import BookwyrmExportJob
|
||||
from bookwyrm.settings import PAGE_LENGTH
|
||||
|
||||
|
@ -101,10 +103,15 @@ class ExportUser(View):
|
|||
jobs = BookwyrmExportJob.objects.filter(user=request.user).order_by(
|
||||
"-created_date"
|
||||
)
|
||||
hours = settings.USER_EXPORT_COOLDOWN_HOURS
|
||||
allowed = jobs.first().created_date < timezone.now() - timedelta(hours=hours)
|
||||
next_available = jobs.first().created_date + timedelta(hours=hours) if not allowed else False
|
||||
|
||||
paginated = Paginator(jobs, PAGE_LENGTH)
|
||||
page = paginated.get_page(request.GET.get("page"))
|
||||
data = {
|
||||
"jobs": page,
|
||||
"next_available": next_available,
|
||||
"page_range": paginated.get_elided_page_range(
|
||||
page.number, on_each_side=2, on_ends=1
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue