diff options
author | Andrew Godwin | 2022-11-25 17:52:43 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-25 17:52:57 -0700 |
commit | 8ca36fd95800907a1c7f3c9efedd0085b8f0ec9b (patch) | |
tree | faf67cf203e54f5907839531112c3d5739fa5082 /users | |
parent | 2a8cb8f8617d618c8d2777cccd823b28a3edc812 (diff) | |
download | takahe-8ca36fd95800907a1c7f3c9efedd0085b8f0ec9b.tar.gz takahe-8ca36fd95800907a1c7f3c9efedd0085b8f0ec9b.tar.bz2 takahe-8ca36fd95800907a1c7f3c9efedd0085b8f0ec9b.zip |
Add federation admin page
Diffstat (limited to 'users')
-rw-r--r-- | users/models/domain.py | 2 | ||||
-rw-r--r-- | users/views/admin/__init__.py | 1 | ||||
-rw-r--r-- | users/views/admin/federation.py | 57 |
3 files changed, 60 insertions, 0 deletions
diff --git a/users/models/domain.py b/users/models/domain.py index 40a3e22..622085d 100644 --- a/users/models/domain.py +++ b/users/models/domain.py @@ -56,6 +56,8 @@ class Domain(models.Model): create = "/admin/domains/create/" edit = "/admin/domains/{self.domain}/" delete = "{edit}delete/" + root_federation = "/admin/federation/" + edit_federation = "/admin/federation/{self.domain}/" @classmethod def get_remote_domain(cls, domain: str) -> "Domain": diff --git a/users/views/admin/__init__.py b/users/views/admin/__init__.py index 231e027..d1a4db1 100644 --- a/users/views/admin/__init__.py +++ b/users/views/admin/__init__.py @@ -10,6 +10,7 @@ from users.views.admin.domains import ( # noqa DomainEdit, Domains, ) +from users.views.admin.federation import FederationEdit, FederationRoot # noqa from users.views.admin.settings import BasicSettings # noqa diff --git a/users/views/admin/federation.py b/users/views/admin/federation.py new file mode 100644 index 0000000..da8209a --- /dev/null +++ b/users/views/admin/federation.py @@ -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, + } |