Adds warnings about misconfigurations

This commit is contained in:
Mouse Reeve 2022-02-17 13:22:33 -08:00
parent f6e2ec02aa
commit be479fe4cb
2 changed files with 33 additions and 4 deletions

View File

@ -23,6 +23,30 @@
</div> </div>
{% endif %} {% endif %}
{% if warnings.invalid_domain %}
<div class="notification is-danger is-flex is-align-items-start">
<span class="icon icon-warning is-size-4 pr-3" aria-hidden="true"></span>
<span>
{% blocktrans trimmed %}
Your domain appears to be misconfigured.
It should not include protocol or slashes.
{% endblocktrans %}
</span>
</div>
{% endif %}
{% if warnings.protocol %}
<div class="notification is-danger is-flex is-align-items-start">
<span class="icon icon-warning is-size-4 pr-3" aria-hidden="true"></span>
<span>
{% blocktrans trimmed %}
You are running BookWyrm in production mode without https.
<strong>USE_HTTPS</strong> should be enabled in production.
{% endblocktrans %}
</span>
</div>
{% endif %}
<div class="columns"> <div class="columns">
<div class="column is-half is-flex is-flex-direction-column"> <div class="column is-half is-flex is-flex-direction-column">
<h2 class="title is-4">{% trans "Settings" %}</h2> <h2 class="title is-4">{% trans "Settings" %}</h2>
@ -82,14 +106,14 @@
</dd> </dd>
<dt class="is-pulled-left mr-5 has-text-weight-bold"> <dt class="is-pulled-left mr-5 has-text-weight-bold">
{% trans "Enable preview images" %} {% trans "Enable preview images:" %}
</dt> </dt>
<dd> <dd>
{{ info.preview_images|yesno }} {{ info.preview_images|yesno }}
</dd> </dd>
<dt class="is-pulled-left mr-5 has-text-weight-bold"> <dt class="is-pulled-left mr-5 has-text-weight-bold">
{% trans "Enable image thumbnails" %} {% trans "Enable image thumbnails:" %}
</dt> </dt>
<dd> <dd>
{{ info.thumbnails|yesno }} {{ info.thumbnails|yesno }}
@ -104,7 +128,7 @@
<h2 class="title is-4">{% trans "Does everything look right?" %}</h2> <h2 class="title is-4">{% trans "Does everything look right?" %}</h2>
<p class="subtitle help"> <p class="subtitle help">
{% blocktrans trimmed %} {% blocktrans trimmed %}
This is your last change to set your domain and protocol. This is your last chance to set your domain and protocol.
{% endblocktrans %} {% endblocktrans %}
</p> </p>

View File

@ -1,4 +1,6 @@
""" Installation wizard 🧙 """ """ Installation wizard 🧙 """
import re
from django.contrib.auth import login from django.contrib.auth import login
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
@ -9,6 +11,7 @@ from django.views import View
from bookwyrm import forms, models from bookwyrm import forms, models
from bookwyrm import settings from bookwyrm import settings
from bookwyrm.utils import regex
# pylint: disable= no-self-use # pylint: disable= no-self-use
@ -25,8 +28,10 @@ class InstanceConfig(View):
# check for possible problems with the instance configuration # check for possible problems with the instance configuration
warnings = {} warnings = {}
warnings["debug"] = settings.DEBUG warnings["debug"] = settings.DEBUG
warnings["protocol_in_domain"] = settings.DOMAIN.startswith("http") warnings["invalid_domain"] = not re.match(rf"^{regex.DOMAIN}$", settings.DOMAIN)
warnings["protocol"] = not settings.DEBUG and not settings.USE_HTTPS
# pylint: disable=line-too-long
data = { data = {
"warnings": warnings, "warnings": warnings,
"info": { "info": {