forked from Fediversity/Fediversity
add enable toggle, let operators have many configuraitons
this commit is a bit of a jumble, but it allows us to disable a configuration so the associated deployment can in principle be garbage-collected, and allows operators to have multiple configurations. it also (as a temporary hack) ties the deployment subdomain to the username so it's clear to operators where we're deploying to.
This commit is contained in:
parent
a97418c30e
commit
da2e7d93a9
4 changed files with 67 additions and 7 deletions
|
@ -11,3 +11,12 @@ class Deployment(forms.ModelForm):
|
||||||
'pixelfed',
|
'pixelfed',
|
||||||
'peertube',
|
'peertube',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
operator = self.instance.operator.username
|
||||||
|
self.fields['domain'].choices = [
|
||||||
|
(code, f"{operator}.{label}")
|
||||||
|
for code, label in self.instance._meta.get_field('domain').choices
|
||||||
|
]
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Generated by Django 4.2.16 on 2025-02-24 09:49
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('panel', '0003_renamemodel'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='configuration',
|
||||||
|
name='user',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='configuration',
|
||||||
|
name='enable',
|
||||||
|
field=models.BooleanField(default=False, help_text='Enable the configuration'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='configuration',
|
||||||
|
name='operator',
|
||||||
|
field=models.ForeignKey(help_text='Operator who owns the configuration', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='configurations', to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='configuration',
|
||||||
|
name='domain',
|
||||||
|
field=models.CharField(choices=[('fediversity_eu', 'fediversity.eu'), ('fediversity_net', 'fediversity.net')], max_length=255),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,15 +1,31 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
DOMAIN_LIST = [("fediversity_eu", "fediversity.eu"), ("fediversity_net", "fediversity.net")]
|
|
||||||
|
|
||||||
|
|
||||||
class Configuration(models.Model):
|
class Configuration(models.Model):
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
|
operator = models.ForeignKey(
|
||||||
domain = models.CharField(choices=DOMAIN_LIST, max_length=255)
|
User,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
null=True,
|
||||||
|
related_name="configurations",
|
||||||
|
help_text="Operator who owns the configuration",
|
||||||
|
)
|
||||||
|
enable = models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
help_text="Enable the configuration",
|
||||||
|
)
|
||||||
|
domain = models.CharField(
|
||||||
|
# XXX: hard-code available apex domains for now,
|
||||||
|
# they will be prefixed by the user name
|
||||||
|
# TODO: map to user's registered domains
|
||||||
|
choices=[
|
||||||
|
("fediversity_eu", "fediversity.eu"),
|
||||||
|
("fediversity_net", "fediversity.net")
|
||||||
|
],
|
||||||
|
max_length=255,
|
||||||
|
)
|
||||||
|
# TODO: map to configuration model per service
|
||||||
mastodon = models.BooleanField(default=False)
|
mastodon = models.BooleanField(default=False)
|
||||||
pixelfed = models.BooleanField(default=False)
|
pixelfed = models.BooleanField(default=False)
|
||||||
peertube = models.BooleanField(default=False)
|
peertube = models.BooleanField(default=False)
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"User: {self.user.username}, Domain: {self.domain}, Mastodon: {self.mastodon}, Pixelfed: {self.pixelfed}, Peertube: {self.peertube}"
|
|
||||||
|
|
|
@ -33,5 +33,5 @@ class ConfigurationForm(LoginRequiredMixin, UpdateView):
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
obj, created = Configuration.objects.get_or_create(
|
obj, created = Configuration.objects.get_or_create(
|
||||||
user=self.request.user)
|
operator=self.request.user)
|
||||||
return obj
|
return obj
|
||||||
|
|
Loading…
Add table
Reference in a new issue