Add federation admin page
This commit is contained in:
parent
2a8cb8f861
commit
8ca36fd958
|
@ -365,6 +365,10 @@ nav a i {
|
||||||
margin: 0 5px 0 5px;
|
margin: 0 5px 0 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.icon-menu .option .pill.bad {
|
||||||
|
background: var(--color-delete);
|
||||||
|
}
|
||||||
|
|
||||||
.handle {
|
.handle {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
|
@ -68,6 +68,16 @@ urlpatterns = [
|
||||||
"admin/domains/<domain>/delete/",
|
"admin/domains/<domain>/delete/",
|
||||||
admin.DomainDelete.as_view(),
|
admin.DomainDelete.as_view(),
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"admin/federation/",
|
||||||
|
admin.FederationRoot.as_view(),
|
||||||
|
name="admin_federation",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"admin/federation/<domain>/",
|
||||||
|
admin.FederationEdit.as_view(),
|
||||||
|
name="admin_federation_edit",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"admin/users/",
|
"admin/users/",
|
||||||
admin.Users.as_view(),
|
admin.Users.as_view(),
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
{% extends "settings/base.html" %}
|
||||||
|
|
||||||
|
{% block subtitle %}Federation{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<section class="icon-menu">
|
||||||
|
{% for domain in domains %}
|
||||||
|
<a class="option" href="{{ domain.urls.edit_federation }}">
|
||||||
|
<i class="fa-solid fa-globe"></i>
|
||||||
|
<span class="handle">
|
||||||
|
{{ domain.domain }}
|
||||||
|
<small>
|
||||||
|
{{ domain.num_users }} remote identit{{ domain.num_users|pluralize:"y,ies" }}
|
||||||
|
</small>
|
||||||
|
</span>
|
||||||
|
{% if domain.blocked %}
|
||||||
|
<span class="pill bad">Blocked</span>
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
|
{% empty %}
|
||||||
|
<p class="option empty">There are no federation links yet.</p>
|
||||||
|
{% endfor %}
|
||||||
|
</section>
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,19 @@
|
||||||
|
{% extends "settings/base.html" %}
|
||||||
|
|
||||||
|
{% block subtitle %}{{ domain.domain }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form action="." method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
<h1>{{ domain }}</h1>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Federation Controls</legend>
|
||||||
|
{% include "forms/_field.html" with field=form.blocked %}
|
||||||
|
</fieldset>
|
||||||
|
<div class="buttons">
|
||||||
|
<a href="{{ domain.urls.root }}" class="button secondary left">Back</a>
|
||||||
|
<a href="{{ domain.urls.delete }}" class="button delete">Delete</a>
|
||||||
|
<button>Save</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -24,6 +24,9 @@
|
||||||
<a href="{% url "admin_domains" %}" {% if section == "domains" %}class="selected"{% endif %} title="Domains">
|
<a href="{% url "admin_domains" %}" {% if section == "domains" %}class="selected"{% endif %} title="Domains">
|
||||||
<i class="fa-solid fa-globe"></i> Domains
|
<i class="fa-solid fa-globe"></i> Domains
|
||||||
</a>
|
</a>
|
||||||
|
<a href="{% url "admin_federation" %}" {% if section == "federation" %}class="selected"{% endif %} title="Federation">
|
||||||
|
<i class="fa-solid fa-diagram-project"></i> Federation
|
||||||
|
</a>
|
||||||
<a href="{% url "admin_users" %}" {% if section == "users" %}class="selected"{% endif %} title="Users">
|
<a href="{% url "admin_users" %}" {% if section == "users" %}class="selected"{% endif %} title="Users">
|
||||||
<i class="fa-solid fa-users"></i> Users
|
<i class="fa-solid fa-users"></i> Users
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -56,6 +56,8 @@ class Domain(models.Model):
|
||||||
create = "/admin/domains/create/"
|
create = "/admin/domains/create/"
|
||||||
edit = "/admin/domains/{self.domain}/"
|
edit = "/admin/domains/{self.domain}/"
|
||||||
delete = "{edit}delete/"
|
delete = "{edit}delete/"
|
||||||
|
root_federation = "/admin/federation/"
|
||||||
|
edit_federation = "/admin/federation/{self.domain}/"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_remote_domain(cls, domain: str) -> "Domain":
|
def get_remote_domain(cls, domain: str) -> "Domain":
|
||||||
|
|
|
@ -10,6 +10,7 @@ from users.views.admin.domains import ( # noqa
|
||||||
DomainEdit,
|
DomainEdit,
|
||||||
Domains,
|
Domains,
|
||||||
)
|
)
|
||||||
|
from users.views.admin.federation import FederationEdit, FederationRoot # noqa
|
||||||
from users.views.admin.settings import BasicSettings # noqa
|
from users.views.admin.settings import BasicSettings # noqa
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
from django import forms
|
||||||
|
from django.db import models
|
||||||
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
|
from django.utils.decorators import method_decorator
|
||||||
|
from django.views.generic import FormView, TemplateView
|
||||||
|
|
||||||
|
from users.decorators import admin_required
|
||||||
|
from users.models import Domain
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(admin_required, name="dispatch")
|
||||||
|
class FederationRoot(TemplateView):
|
||||||
|
|
||||||
|
template_name = "admin/federation.html"
|
||||||
|
|
||||||
|
def get_context_data(self):
|
||||||
|
return {
|
||||||
|
"domains": Domain.objects.filter(local=False)
|
||||||
|
.annotate(num_users=models.Count("identities"))
|
||||||
|
.order_by("domain"),
|
||||||
|
"section": "federation",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(admin_required, name="dispatch")
|
||||||
|
class FederationEdit(FormView):
|
||||||
|
|
||||||
|
template_name = "admin/federation_edit.html"
|
||||||
|
extra_context = {"section": "federation"}
|
||||||
|
|
||||||
|
class form_class(forms.Form):
|
||||||
|
blocked = forms.BooleanField(
|
||||||
|
help_text="If this domain is blocked from interacting with this server",
|
||||||
|
widget=forms.Select(choices=[(True, "Blocked"), (False, "Not Blocked")]),
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
def dispatch(self, request, domain):
|
||||||
|
self.domain = get_object_or_404(
|
||||||
|
Domain.objects.filter(local=False), domain=domain
|
||||||
|
)
|
||||||
|
return super().dispatch(request)
|
||||||
|
|
||||||
|
def get_context_data(self, *args, **kwargs):
|
||||||
|
context = super().get_context_data(*args, **kwargs)
|
||||||
|
context["domain"] = self.domain
|
||||||
|
return context
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
self.domain.blocked = form.cleaned_data["blocked"]
|
||||||
|
self.domain.save()
|
||||||
|
return redirect(Domain.urls.root_federation)
|
||||||
|
|
||||||
|
def get_initial(self):
|
||||||
|
return {
|
||||||
|
"blocked": self.domain.blocked,
|
||||||
|
}
|
Loading…
Reference in New Issue