diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index bac1d9b49..226e79e6e 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -59,7 +59,7 @@ urlpatterns = [ name="stream-updates", ), # instance setup - re_path(r"^setup/?$", views.CreateAdmin.as_view(), name="setup-admin"), + re_path(r"^setup/?$", views.CreateAdmin.as_view(), name="setup"), # authentication re_path(r"^login/?$", views.Login.as_view(), name="login"), re_path(r"^login/(?Pconfirmed)/?$", views.Login.as_view(), name="login"), diff --git a/bookwyrm/views/landing/landing.py b/bookwyrm/views/landing/landing.py index cfd9b48b8..87119f465 100644 --- a/bookwyrm/views/landing/landing.py +++ b/bookwyrm/views/landing/landing.py @@ -1,8 +1,9 @@ """ non-interactive pages """ +from django.shortcuts import redirect from django.template.response import TemplateResponse from django.views import View -from bookwyrm import forms +from bookwyrm import forms, models from bookwyrm.views.feed import Feed @@ -15,6 +16,11 @@ class Home(View): if request.user.is_authenticated: feed_view = Feed.as_view() return feed_view(request, "home") + site = models.SiteSettings.objects.get() + + if site.install_mode: + return redirect("setup") + landing_view = Landing.as_view() return landing_view(request) diff --git a/bookwyrm/views/landing/register.py b/bookwyrm/views/landing/register.py index b91d1b5a9..d4d719576 100644 --- a/bookwyrm/views/landing/register.py +++ b/bookwyrm/views/landing/register.py @@ -25,6 +25,10 @@ class Register(View): def post(self, request): """join the server""" settings = models.SiteSettings.get() + # no registration allowed when the site is being installed + if settings.install_mode: + raise PermissionDenied() + if not settings.allow_registration: invite_code = request.POST.get("invite_code") diff --git a/bookwyrm/views/setup.py b/bookwyrm/views/setup.py index be3fb0a32..d370c2f00 100644 --- a/bookwyrm/views/setup.py +++ b/bookwyrm/views/setup.py @@ -1,9 +1,9 @@ """ Installation wizard 🧙 """ +from django.core.exceptions import PermissionDenied from django.template.response import TemplateResponse -from django.utils.decorators import method_decorator from django.views import View -from bookwyrm import emailing, forms, models +from bookwyrm import forms, models # pylint: disable= no-self-use @@ -12,6 +12,11 @@ class CreateAdmin(View): def get(self, request): """Create admin user""" + # only allow this view when an instance is being installed + site = models.SiteSettings.objects.get() + if not site.install_mode: + raise PermissionDenied() + data = { "register_form": forms.RegisterForm() }