Adds admin view

This commit is contained in:
Mouse Reeve 2022-01-10 10:11:00 -08:00
parent 0bfa15bb47
commit 32e3fdb438
8 changed files with 140 additions and 6 deletions

View file

@ -297,6 +297,7 @@ class Link(ActivityObject):
"""for tagging a book in a status"""
href: str
name: str
mediaType: str = None
id: str = None
type: str = "Link"

View file

@ -83,6 +83,7 @@ class Migration(migrations.Migration):
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="links",
to="bookwyrm.linkdomain",
),
),

View file

@ -15,7 +15,7 @@ class Link(ActivitypubMixin, BookWyrmModel):
url = fields.URLField(max_length=255, activitypub_field="href")
domain = models.ForeignKey(
"LinkDomain", on_delete=models.CASCADE, null=True, blank=True
"LinkDomain", on_delete=models.CASCADE, null=True, blank=True, related_name="links"
)
activity_serializer = activitypub.Link

View file

@ -62,6 +62,10 @@
{% url 'settings-ip-blocks' as url %}
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "IP Address Blocklist" %}</a>
</li>
<li>
{% url 'settings-link-domain' status='pending' as url %}
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Link Domains" %}</a>
</li>
</ul>
{% endif %}
{% if perms.bookwyrm.edit_instance_settings %}

View file

@ -0,0 +1,95 @@
{% extends 'settings/layout.html' %}
{% load humanize %}
{% load i18n %}
{% block title %}{% trans "Link Domains" %}{% endblock %}
{% block header %}{% trans "Link Domains" %}{% endblock %}
{% block panel %}
<p class="notification block">
{% trans "Link domains must be approved before they are shown on book pages. Please make sure that the domains are not hosting spam, malicious code, or deceptive links before approving." %}
</p>
<div class="block">
<div class="tabs">
<ul>
{% url 'settings-link-domain' status='pending' as url %}
<li {% if request.path in url %}class="is-active" aria-current="page"{% endif %}>
<a href="{{ url }}">{% trans "Pending" %}</a>
</li>
{% url 'settings-link-domain' status='approved' as url %}
<li {% if url in request.path %}class="is-active" aria-current="page"{% endif %}>
<a href="{{ url }}">{% trans "Approved" %}</a>
</li>
{% url 'settings-link-domain' status='blocked' as url %}
<li {% if url in request.path %}class="is-active" aria-current="page"{% endif %}>
<a href="{{ url }}">{% trans "Blocked" %}</a>
</li>
</ul>
</div>
{% for domain in domains %}
<div class="box content">
<div class="columns is-mobile">
<header class="column">
<h3 class="title is-5">
{{ domain.name }}
(<a href="http://{{ domain.domain }}" target="_blank" rel="noopener">{{ domain.domain }}</a>)
</h3>
</header>
<div class="column is-narrow">
{% trans "Set name" as button_text %}
{% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="pencil" controls_text="edit_domain" controls_uid=domain.id focus="id_description" %}
</div>
</div>
<div class="block">
<details class="details-panel">
<summary>
<span>
{% trans "View links" %}
({{ domain.links.count }})
</span>
<span class="details-close icon icon-x" aria-hidden></span>
</summary>
<ul>
{% for link in domain.links.all|slice:10 %}
<li>
<a href="{{ link.url }}" target="_blank" rel="noopener">{{ link.url }}</a>
{% if link.filelink.filetype %}
({{ link.filelink.filetype }})
{% endif %}
</li>
{% endfor %}
</ul>
</details>
</div>
<form name="domain-{{ domain.id }}">
{% csrf_token %}
<div class="field has-addons">
<div class="control">
<button type="submit" class="button is-success is-light">{% trans "Approve" %}</button>
</div>
<div class="control">
<button type="submit" class="button is-danger is-light">{% trans "Block" %}</button>
</div>
</div>
</form>
</div>
{% endfor %}
{% if not domains.exists %}
{% if status == "approved" %}
<em>{% trans "No domains currently approved" %}</em>
{% elif status == "pending" %}
<em>{% trans "No domains currently pending" %}</em>
{% else %}
<em>{% trans "No domains currently blocked" %}</em>
{% endif %}
{% endif %}
</div>
{% endblock %}

View file

@ -96,11 +96,6 @@ urlpatterns = [
re_path(
r"^settings/users/?$", views.UserAdminList.as_view(), name="settings-users"
),
re_path(
r"^settings/users/(?P<user>\d+)/?$",
views.UserAdmin.as_view(),
name="settings-user",
),
re_path(
r"^settings/federation/(?P<status>(federated|blocked))?/?$",
views.Federation.as_view(),
@ -158,6 +153,11 @@ urlpatterns = [
views.EmailBlocklist.as_view(),
name="settings-email-blocks-delete",
),
re_path(
r"^setting/link-domains/(?P<status>(pending|approved|blocked))/?",
views.LinkDomain.as_view(),
name="settings-link-domain",
),
re_path(
r"^settings/ip-blocklist/?$",
views.IPBlocklist.as_view(),

View file

@ -9,6 +9,7 @@ from .admin.email_blocklist import EmailBlocklist
from .admin.ip_blocklist import IPBlocklist
from .admin.invite import ManageInvites, Invite, InviteRequest
from .admin.invite import ManageInviteRequests, ignore_invite_request
from .admin.link_domains import LinkDomain
from .admin.reports import (
Report,
Reports,

View file

@ -0,0 +1,32 @@
""" Manage link domains"""
from django.contrib.auth.decorators import login_required, permission_required
from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views import View
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"""
def get(self, request, status="pending"):
"""view pending domains"""
data = {
"domains": models.LinkDomain.objects.filter(
status=status
).prefetch_related("links"),
"form": forms.EmailBlocklistForm(),
"status": status,
}
return TemplateResponse(
request, "settings/link_domains/link_domains.html", data
)
def post(self, request):
"""post?"""