Merge pull request #2766 from bookwyrm-social/redirect-in-admin

Uses referer redirect for some admin views
This commit is contained in:
Jascha Ezra Urbach 2023-04-01 11:06:42 +02:00 committed by GitHub
commit d35b1d91ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View file

@ -8,6 +8,7 @@ from django.views import View
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
@ -57,7 +58,7 @@ class ImportList(View):
"""Mark an import as complete"""
import_job = get_object_or_404(models.ImportJob, id=import_id)
import_job.stop_job()
return redirect("settings-imports")
return redirect_to_referer(request, "settings-imports")
@require_POST

View file

@ -8,6 +8,7 @@ from django.utils.decorators import method_decorator
from django.views import View
from bookwyrm import forms, models
from bookwyrm.views.helpers import redirect_to_referer
from bookwyrm.settings import PAGE_LENGTH
@ -84,26 +85,26 @@ class ReportAdmin(View):
@login_required
@permission_required("bookwyrm.moderate_user")
def suspend_user(_, user_id):
def suspend_user(request, user_id):
"""mark an account as inactive"""
user = get_object_or_404(models.User, id=user_id)
user.is_active = False
user.deactivation_reason = "moderator_suspension"
# this isn't a full deletion, so we don't want to tell the world
user.save(broadcast=False)
return redirect("settings-user", user.id)
return redirect_to_referer(request, "settings-user", user.id)
@login_required
@permission_required("bookwyrm.moderate_user")
def unsuspend_user(_, user_id):
def unsuspend_user(request, user_id):
"""mark an account as inactive"""
user = get_object_or_404(models.User, id=user_id)
user.is_active = True
user.deactivation_reason = None
# this isn't a full deletion, so we don't want to tell the world
user.save(broadcast=False)
return redirect("settings-user", user.id)
return redirect_to_referer(request, "settings-user", user.id)
@login_required
@ -123,7 +124,7 @@ def moderator_delete_user(request, user_id):
if form.is_valid() and moderator.check_password(form.cleaned_data["password"]):
user.deactivation_reason = "moderator_deletion"
user.delete()
return redirect("settings-user", user.id)
return redirect_to_referer(request, "settings-user", user.id)
form.errors["password"] = ["Invalid password"]