Adds unscheduler

This commit is contained in:
Mouse Reeve 2022-02-26 10:24:23 -08:00
parent 2a436800c4
commit 0870eccad9
4 changed files with 31 additions and 3 deletions

View file

@ -50,6 +50,19 @@
</span>
</dd>
</dl>
<div class="is-flex is-justify-content-space-between">
<form name="unschedule-scan" method="POST" action="{% url 'settings-automod-unschedule' task.id %}">
{% csrf_token %}
<button class="button is-danger">{% trans "Delete schedule" %}</button>
</form>
<form name="run-scan" method="POST" action="{% url 'settings-automod-run' %}">
{% csrf_token %}
<button class="button">{% trans "Run now" %}</button>
<p class="help">{% trans "Last run date will not be updated" %}</p>
</form>
</div>
{% else %}
<form name="schedule-scan" method="POST" action="{% url 'settings-automod-schedule' %}">
{% csrf_token %}

View file

@ -226,6 +226,11 @@ urlpatterns = [
views.schedule_automod_task,
name="settings-automod-schedule",
),
re_path(
r"^settings/automod/unschedule/(?P<task_id>\d+)/?$",
views.unschedule_automod_task,
name="settings-automod-unschedule",
),
re_path(
r"^settings/automod/run/?$", views.run_automod, name="settings-automod-run"
),

View file

@ -2,7 +2,8 @@
# site admin
from .admin.announcements import Announcements, Announcement
from .admin.announcements import EditAnnouncement, delete_announcement
from .admin.automod import AutoMod, automod_delete, run_automod, schedule_automod_task
from .admin.automod import AutoMod, automod_delete, run_automod
from .admin.automod import schedule_automod_task, unschedule_automod_task
from .admin.dashboard import Dashboard
from .admin.federation import Federation, FederatedServer
from .admin.federation import AddFederatedServer, ImportServerBlocklist

View file

@ -64,14 +64,23 @@ def schedule_automod_task(request):
return redirect("settings-automod")
@require_POST
@permission_required("bookwyrm.moderate_user", raise_exception=True)
@permission_required("bookwyrm.moderate_post", raise_exception=True)
# pylint: disable=unused-argument
def unschedule_automod_task(request, task_id):
"""unscheduler"""
get_object_or_404(PeriodicTask, id=task_id).delete()
return redirect("settings-automod")
@require_POST
@permission_required("bookwyrm.moderate_user", raise_exception=True)
@permission_required("bookwyrm.moderate_post", raise_exception=True)
# pylint: disable=unused-argument
def automod_delete(request, rule_id):
"""Remove a rule"""
rule = get_object_or_404(models.AutoMod, id=rule_id)
rule.delete()
get_object_or_404(models.AutoMod, id=rule_id).delete()
return redirect("settings-automod")