Admin UI to enable and disable importing

This commit is contained in:
Mouse Reeve 2022-11-17 14:22:45 -08:00
parent 7e10b0cd1f
commit 7c7c0e1a93
6 changed files with 103 additions and 1 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 3.2.16 on 2022-11-17 21:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0165_alter_inviterequest_answer"),
]
operations = [
migrations.AddField(
model_name="sitesettings",
name="imports_enabled",
field=models.BooleanField(default=True),
),
]

View file

@ -86,6 +86,9 @@ class SiteSettings(SiteModel):
admin_email = models.EmailField(max_length=255, null=True, blank=True) admin_email = models.EmailField(max_length=255, null=True, blank=True)
footer_item = models.TextField(null=True, blank=True) footer_item = models.TextField(null=True, blank=True)
# controls
imports_enabled = models.BooleanField(default=True)
field_tracker = FieldTracker(fields=["name", "instance_tagline", "logo"]) field_tracker = FieldTracker(fields=["name", "instance_tagline", "logo"])
@classmethod @classmethod

View file

@ -11,6 +11,54 @@
{% block panel %} {% block panel %}
<div class="block">
{% if site.imports_enabled %}
<details class="details-panel box">
<summary>
<span role="heading" aria-level="2" class="title is-6">
{% trans "Disable starting new imports" %}
</span>
<span class="details-close icon icon-x" aria-hidden="true"></span>
</summary>
<form
name="disable-imports"
id="disable-imports"
method="POST"
action="{% url 'settings-imports-disable' %}"
>
<div class="notification">
{% trans "This is only intended to be used when things have gone very wrong with imports and you need to pause the feature while addressing issues." %}
{% trans "While imports are disabled, users will not be allowed to start new imports, but existing imports will not be effected." %}
</div>
{% csrf_token %}
<div class="control">
<button type="submit" class="button is-danger">
{% trans "Disable imports" %}
</button>
</div>
</form>
</details>
{% else %}
<form
name="enable-imports"
id="enable-imports"
method="POST"
action="{% url 'settings-imports-enable' %}"
class="box"
>
<div class="notification is-danger is-light">
{% trans "Users are currently unable to start new imports" %}
</div>
{% csrf_token %}
<div class="control">
<button type="submit" class="button is-success">
{% trans "Enable imports" %}
</button>
</div>
</form>
{% endif %}
</div>
<div class="block"> <div class="block">
<div class="tabs"> <div class="tabs">
<ul> <ul>

View file

@ -301,6 +301,16 @@ urlpatterns = [
views.ImportList.as_view(), views.ImportList.as_view(),
name="settings-imports-complete", name="settings-imports-complete",
), ),
re_path(
r"^settings/imports/disable/?$",
views.disable_imports,
name="settings-imports-disable",
),
re_path(
r"^settings/imports/enable/?$",
views.enable_imports,
name="settings-imports-enable",
),
re_path( re_path(
r"^settings/celery/?$", views.CeleryStatus.as_view(), name="settings-celery" r"^settings/celery/?$", views.CeleryStatus.as_view(), name="settings-celery"
), ),

View file

@ -10,7 +10,7 @@ from .admin.federation import Federation, FederatedServer
from .admin.federation import AddFederatedServer, ImportServerBlocklist from .admin.federation import AddFederatedServer, ImportServerBlocklist
from .admin.federation import block_server, unblock_server, refresh_server from .admin.federation import block_server, unblock_server, refresh_server
from .admin.email_blocklist import EmailBlocklist from .admin.email_blocklist import EmailBlocklist
from .admin.imports import ImportList from .admin.imports import ImportList, disable_imports, enable_imports
from .admin.ip_blocklist import IPBlocklist from .admin.ip_blocklist import IPBlocklist
from .admin.invite import ManageInvites, Invite, InviteRequest from .admin.invite import ManageInvites, Invite, InviteRequest
from .admin.invite import ManageInviteRequests, ignore_invite_request from .admin.invite import ManageInviteRequests, ignore_invite_request

View file

@ -5,6 +5,7 @@ from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views import View from django.views import View
from django.views.decorators.http import require_POST
from bookwyrm import models from bookwyrm import models
from bookwyrm.settings import PAGE_LENGTH from bookwyrm.settings import PAGE_LENGTH
@ -53,3 +54,25 @@ class ImportList(View):
import_job = get_object_or_404(models.ImportJob, id=import_id) import_job = get_object_or_404(models.ImportJob, id=import_id)
import_job.stop_job() import_job.stop_job()
return redirect("settings-imports") return redirect("settings-imports")
@require_POST
@permission_required("bookwyrm.edit_instance_settings", raise_exception=True)
# pylint: disable=unused-argument
def disable_imports(request):
"""When you just need people to please stop starting imports"""
site = models.SiteSettings.objects.get()
site.imports_enabled = False
site.save(update_fields=["imports_enabled"])
return redirect("settings-imports")
@require_POST
@permission_required("bookwyrm.edit_instance_settings", raise_exception=True)
# pylint: disable=unused-argument
def enable_imports(request):
"""When you just need people to please stop starting imports"""
site = models.SiteSettings.objects.get()
site.imports_enabled = True
site.save(update_fields=["imports_enabled"])
return redirect("settings-imports")