Single user domain mode

This commit is contained in:
Andrew Godwin 2023-05-03 14:35:41 -06:00
parent 6c5e7929b6
commit 1b25ce3bb6
4 changed files with 17 additions and 0 deletions

View file

@ -296,3 +296,4 @@ class Config(models.Model):
site_icon: UploadedImage | None = None site_icon: UploadedImage | None = None
hide_login: bool = False hide_login: bool = False
custom_css: str = "" custom_css: str = ""
single_user: str = ""

View file

@ -18,6 +18,8 @@ from core.models import Config
def homepage(request): def homepage(request):
if request.user.is_authenticated: if request.user.is_authenticated:
return Home.as_view()(request) return Home.as_view()(request)
elif request.domain.config_domain.single_user:
return redirect(f"/@{request.domain.config_domain.single_user}/")
else: else:
return About.as_view()(request) return About.as_view()(request)

View file

@ -21,6 +21,7 @@
{% include "forms/_field.html" with field=form.site_name %} {% include "forms/_field.html" with field=form.site_name %}
{% include "forms/_field.html" with field=form.site_icon %} {% include "forms/_field.html" with field=form.site_icon %}
{% include "forms/_field.html" with field=form.hide_login %} {% include "forms/_field.html" with field=form.hide_login %}
{% include "forms/_field.html" with field=form.single_user %}
{% include "forms/_field.html" with field=form.custom_css %} {% include "forms/_field.html" with field=form.custom_css %}
</fieldset> </fieldset>
<fieldset> <fieldset>

View file

@ -1,4 +1,5 @@
from django import forms from django import forms
from django.contrib import messages
from django.core.files import File from django.core.files import File
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
from django.db import models from django.db import models
@ -183,6 +184,12 @@ class DomainEdit(FormView):
required=False, required=False,
) )
single_user = forms.CharField(
label="Single User Profile Redirect",
help_text="If provided, redirect the homepage of this domain to this identity's profile for logged-out users\nUse the identity's full handle - for example, <tt>takahe@jointakahe.org</tt>",
required=False,
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.fields["domain"].disabled = True self.fields["domain"].disabled = True
@ -194,6 +201,9 @@ class DomainEdit(FormView):
def clean_service_domain(self): def clean_service_domain(self):
return self.cleaned_data["service_domain"] return self.cleaned_data["service_domain"]
def clean_single_user(self):
return self.cleaned_data["single_user"].lstrip("@")
def dispatch(self, request, domain): def dispatch(self, request, domain):
self.domain = get_object_or_404( self.domain = get_object_or_404(
Domain.objects.filter(local=True), domain=domain Domain.objects.filter(local=True), domain=domain
@ -218,6 +228,8 @@ class DomainEdit(FormView):
if isinstance(form.cleaned_data["site_icon"], File): if isinstance(form.cleaned_data["site_icon"], File):
Config.set_domain(self.domain, "site_icon", form.cleaned_data["site_icon"]) Config.set_domain(self.domain, "site_icon", form.cleaned_data["site_icon"])
Config.set_domain(self.domain, "custom_css", form.cleaned_data["custom_css"]) Config.set_domain(self.domain, "custom_css", form.cleaned_data["custom_css"])
Config.set_domain(self.domain, "single_user", form.cleaned_data["single_user"])
messages.success(self.request, f"Domain {self.domain} saved.")
return redirect(Domain.urls.root) return redirect(Domain.urls.root)
def get_initial(self): def get_initial(self):
@ -232,6 +244,7 @@ class DomainEdit(FormView):
"site_icon": self.domain.config_domain.site_icon, "site_icon": self.domain.config_domain.site_icon,
"hide_login": self.domain.config_domain.hide_login, "hide_login": self.domain.config_domain.hide_login,
"custom_css": self.domain.config_domain.custom_css, "custom_css": self.domain.config_domain.custom_css,
"single_user": self.domain.config_domain.single_user,
} }