2022-01-10 18:11:00 +00:00
|
|
|
""" Manage link domains"""
|
|
|
|
from django.contrib.auth.decorators import login_required, permission_required
|
2022-01-10 18:48:27 +00:00
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
2022-01-10 18:11:00 +00:00
|
|
|
from django.template.response import TemplateResponse
|
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from django.views import View
|
2022-01-10 19:19:20 +00:00
|
|
|
from django.views.decorators.http import require_POST
|
2022-01-10 18:11:00 +00:00
|
|
|
|
|
|
|
from bookwyrm import forms, models
|
|
|
|
|
|
|
|
# pylint: disable=no-self-use
|
|
|
|
@method_decorator(login_required, name="dispatch")
|
|
|
|
@method_decorator(
|
|
|
|
permission_required("bookwyrm.moderate_user", raise_exception=True),
|
|
|
|
name="dispatch",
|
|
|
|
)
|
|
|
|
class LinkDomain(View):
|
|
|
|
"""Moderate links"""
|
|
|
|
|
2022-01-10 23:27:33 +00:00
|
|
|
def get(self, request, status="pending"):
|
2022-01-10 18:11:00 +00:00
|
|
|
"""view pending domains"""
|
|
|
|
data = {
|
2022-01-17 16:14:13 +00:00
|
|
|
"domains": models.LinkDomain.objects.filter(status=status)
|
|
|
|
.prefetch_related("links")
|
|
|
|
.order_by("-created_date"),
|
2022-01-10 19:52:00 +00:00
|
|
|
"counts": {
|
|
|
|
"pending": models.LinkDomain.objects.filter(status="pending").count(),
|
|
|
|
"approved": models.LinkDomain.objects.filter(status="approved").count(),
|
|
|
|
"blocked": models.LinkDomain.objects.filter(status="blocked").count(),
|
|
|
|
},
|
2022-01-10 18:11:00 +00:00
|
|
|
"form": forms.EmailBlocklistForm(),
|
|
|
|
"status": status,
|
|
|
|
}
|
|
|
|
return TemplateResponse(
|
|
|
|
request, "settings/link_domains/link_domains.html", data
|
|
|
|
)
|
|
|
|
|
2022-01-10 18:48:27 +00:00
|
|
|
def post(self, request, status, domain_id):
|
|
|
|
"""Set display name"""
|
|
|
|
domain = get_object_or_404(models.LinkDomain, id=domain_id)
|
|
|
|
form = forms.LinkDomainForm(request.POST, instance=domain)
|
|
|
|
form.save()
|
2022-01-10 19:21:03 +00:00
|
|
|
return redirect("settings-link-domain", status=status)
|
2022-01-10 19:19:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
@require_POST
|
|
|
|
@login_required
|
|
|
|
def update_domain_status(request, domain_id, status):
|
|
|
|
"""This domain seems fine"""
|
|
|
|
domain = get_object_or_404(models.LinkDomain, id=domain_id)
|
|
|
|
domain.raise_not_editable(request.user)
|
|
|
|
|
|
|
|
domain.status = status
|
|
|
|
domain.save()
|
2022-01-10 19:21:03 +00:00
|
|
|
return redirect("settings-link-domain", status="pending")
|