Added admin notes field to domains (#530)

This commit is contained in:
Christof Dorner 2023-03-07 00:37:05 +01:00 committed by GitHub
parent 5ea3d5d143
commit 85b4910829
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 0 deletions

View file

@ -30,6 +30,10 @@
{% include "forms/_field.html" with field=form.default %}
{% include "forms/_field.html" with field=form.users %}
</fieldset>
<fieldset>
<legend>Admin Notes</legend>
{% include "forms/_field.html" with field=form.notes %}
</fieldset>
<div class="buttons">
<a href="{% url "admin_domains" %}" class="button secondary left">Back</a>
<button>Create</button>

View file

@ -16,6 +16,10 @@
{% include "forms/_field.html" with field=form.default %}
{% include "forms/_field.html" with field=form.users %}
</fieldset>
<fieldset>
<legend>Admin Notes</legend>
{% include "forms/_field.html" with field=form.notes %}
</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>

View file

@ -10,6 +10,10 @@
<legend>Federation Controls</legend>
{% include "forms/_field.html" with field=form.blocked %}
</fieldset>
<fieldset>
<legend>Admin Notes</legend>
{% include "forms/_field.html" with field=form.notes %}
</fieldset>
<div class="buttons">
<a href="{{ domain.urls.root_federation }}" class="button secondary left">Back</a>
<a href="{{ domain.urls.delete }}" class="button delete">Delete</a>

View file

@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2023-03-06 21:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("users", "0013_stator_indexes"),
]
operations = [
migrations.AddField(
model_name="domain",
name="notes",
field=models.TextField(blank=True, null=True),
),
]

View file

@ -92,6 +92,9 @@ class Domain(StatorModel):
# This should be display domains ONLY
users = models.ManyToManyField("users.User", related_name="domains", blank=True)
# Free-form notes field for admins
notes = models.TextField(blank=True, null=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)

View file

@ -74,6 +74,15 @@ class DomainCreate(FormView):
widget=forms.Textarea,
required=False,
)
notes = forms.CharField(
label="Notes",
widget=forms.Textarea(
attrs={
"rows": 3,
},
),
required=False,
)
def clean_domain(self):
if Domain.objects.filter(
@ -131,6 +140,7 @@ class DomainCreate(FormView):
domain = Domain.objects.create(
domain=form.cleaned_data["domain"],
service_domain=form.cleaned_data["service_domain"] or None,
notes=form.cleaned_data["notes"] or None,
public=form.cleaned_data["public"],
default=form.cleaned_data["default"],
local=True,
@ -173,6 +183,7 @@ class DomainEdit(FormView):
def form_valid(self, form):
self.domain.public = form.cleaned_data["public"]
self.domain.default = form.cleaned_data["default"]
self.domain.notes = form.cleaned_data["notes"] or None
self.domain.save()
self.domain.users.set(form.cleaned_data["users"])
if self.domain.default:
@ -183,6 +194,7 @@ class DomainEdit(FormView):
return {
"domain": self.domain.domain,
"service_domain": self.domain.service_domain,
"notes": self.domain.notes,
"public": self.domain.public,
"default": self.domain.default,
"users": "\n".join(sorted(user.email for user in self.domain.users.all())),

View file

@ -45,6 +45,15 @@ class FederationEdit(FormView):
widget=forms.Select(choices=[(True, "Blocked"), (False, "Not Blocked")]),
required=False,
)
notes = forms.CharField(
label="Notes",
widget=forms.Textarea(
attrs={
"rows": 3,
},
),
required=False,
)
def dispatch(self, request, domain):
self.domain = get_object_or_404(
@ -59,10 +68,12 @@ class FederationEdit(FormView):
def form_valid(self, form):
self.domain.blocked = form.cleaned_data["blocked"]
self.domain.notes = form.cleaned_data["notes"] or None
self.domain.save()
return redirect(Domain.urls.root_federation)
def get_initial(self):
return {
"blocked": self.domain.blocked,
"notes": self.domain.notes,
}