mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Creates admin views for owner and admin registration settings
This commit is contained in:
parent
dd9fbca7d7
commit
933cb6440f
7 changed files with 266 additions and 1 deletions
|
@ -77,6 +77,23 @@ class SiteForm(CustomForm):
|
||||||
"instance_short_description": forms.TextInput(
|
"instance_short_description": forms.TextInput(
|
||||||
attrs={"aria-describedby": "desc_instance_short_description"}
|
attrs={"aria-describedby": "desc_instance_short_description"}
|
||||||
),
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class RegistrationForm(CustomForm):
|
||||||
|
class Meta:
|
||||||
|
model = models.SiteSettings
|
||||||
|
fields = [
|
||||||
|
"allow_registration",
|
||||||
|
"allow_invite_requests",
|
||||||
|
"registration_closed_text",
|
||||||
|
"invite_request_text",
|
||||||
|
"invite_request_question",
|
||||||
|
"invite_question_text",
|
||||||
|
"require_confirm_email",
|
||||||
|
]
|
||||||
|
|
||||||
|
widgets = {
|
||||||
"require_confirm_email": forms.CheckboxInput(
|
"require_confirm_email": forms.CheckboxInput(
|
||||||
attrs={"aria-describedby": "desc_require_confirm_email"}
|
attrs={"aria-describedby": "desc_require_confirm_email"}
|
||||||
),
|
),
|
||||||
|
@ -86,6 +103,23 @@ class SiteForm(CustomForm):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class RegistrationLimitedForm(CustomForm):
|
||||||
|
class Meta:
|
||||||
|
model = models.SiteSettings
|
||||||
|
fields = [
|
||||||
|
"registration_closed_text",
|
||||||
|
"invite_request_text",
|
||||||
|
"invite_request_question",
|
||||||
|
"invite_question_text",
|
||||||
|
]
|
||||||
|
|
||||||
|
widgets = {
|
||||||
|
"invite_request_text": forms.Textarea(
|
||||||
|
attrs={"aria-describedby": "desc_invite_request_text"}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ThemeForm(CustomForm):
|
class ThemeForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Theme
|
model = models.Theme
|
||||||
|
|
|
@ -101,6 +101,15 @@
|
||||||
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Site Settings" %}</a>
|
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Site Settings" %}</a>
|
||||||
{% block site-subtabs %}{% endblock %}
|
{% block site-subtabs %}{% endblock %}
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
{% if perms.bookwyrm.manage_registration %}
|
||||||
|
{% url 'settings-registration' as url %}
|
||||||
|
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Registration" %}</a>
|
||||||
|
{% else %}
|
||||||
|
{% url 'settings-registration-limited' as url %}
|
||||||
|
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Registration" %}</a>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
{% url 'settings-themes' as url %}
|
{% url 'settings-themes' as url %}
|
||||||
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Themes" %}</a>
|
<a href="{{ url }}"{% if url in request.path %} class="is-active" aria-selected="true"{% endif %}>{% trans "Themes" %}</a>
|
||||||
|
|
83
bookwyrm/templates/settings/registration.html
Normal file
83
bookwyrm/templates/settings/registration.html
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
{% extends 'settings/layout.html' %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block title %}{% trans "Registration" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block header %}{% trans "Registration" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block panel %}
|
||||||
|
{% if success %}
|
||||||
|
<div class="notification is-success is-light">
|
||||||
|
<span class="icon icon-check" aria-hidden="true"></span>
|
||||||
|
<span>
|
||||||
|
{% trans "Settings saved" %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if form.errors %}
|
||||||
|
<div class="notification is-danger is-light">
|
||||||
|
<span class="icon icon-x" aria-hidden="true"></span>
|
||||||
|
<span>
|
||||||
|
{% trans "Unable to save settings" %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<form
|
||||||
|
action="{% url 'settings-registration' %}"
|
||||||
|
method="POST"
|
||||||
|
class="content"
|
||||||
|
enctype="multipart/form-data"
|
||||||
|
>
|
||||||
|
{% csrf_token %}
|
||||||
|
<section class="block box" id="registration">
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_allow_registration">
|
||||||
|
{{ form.allow_registration }}
|
||||||
|
{% trans "Allow registration" %}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label mb-0" for="id_require_confirm_email">
|
||||||
|
{{ form.require_confirm_email }}
|
||||||
|
{% trans "Require users to confirm email address" %}
|
||||||
|
</label>
|
||||||
|
<p class="help" id="desc_require_confirm_email">{% trans "(Recommended if registration is open)" %}</p>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_allow_invite_requests">
|
||||||
|
{{ form.allow_invite_requests }}
|
||||||
|
{% trans "Allow invite requests" %}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_invite_requests_question">
|
||||||
|
{{ form.invite_request_question }}
|
||||||
|
{% trans "Set a question for invite requests" %}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_invite_question_text">
|
||||||
|
{% trans "Question:" %}
|
||||||
|
{{ form.invite_question_text }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_registration_closed_text">{% trans "Registration closed text:" %}</label>
|
||||||
|
{{ form.registration_closed_text }}
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_invite_request_text">{% trans "Invite request text:" %}</label>
|
||||||
|
{{ form.invite_request_text }}
|
||||||
|
|
||||||
|
{% include 'snippets/form_errors.html' with errors_list=form.invite_request_text.errors id="desc_invite_request_text" %}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<footer class="block">
|
||||||
|
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
75
bookwyrm/templates/settings/registration_limited.html
Normal file
75
bookwyrm/templates/settings/registration_limited.html
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
{% extends 'settings/layout.html' %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block title %}{% trans "Registration" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block header %}{% trans "Registration" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block panel %}
|
||||||
|
{% if success %}
|
||||||
|
<div class="notification is-success is-light">
|
||||||
|
<span class="icon icon-check" aria-hidden="true"></span>
|
||||||
|
<span>
|
||||||
|
{% trans "Settings saved" %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if form.errors %}
|
||||||
|
<div class="notification is-danger is-light">
|
||||||
|
<span class="icon icon-x" aria-hidden="true"></span>
|
||||||
|
<span>
|
||||||
|
{% trans "Unable to save settings" %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if site.allow_registration %}
|
||||||
|
<div class="notification">
|
||||||
|
{% trans "Registration is enabled on this instance" %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<form
|
||||||
|
action="{% url 'settings-registration-limited' %}"
|
||||||
|
method="POST"
|
||||||
|
class="content"
|
||||||
|
enctype="multipart/form-data"
|
||||||
|
>
|
||||||
|
{% csrf_token %}
|
||||||
|
<section class="block box" id="registration">
|
||||||
|
{% if site.allow_invite_requests %}
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_invite_request_text">{% trans "Invite request text:" %}</label>
|
||||||
|
{{ form.invite_request_text }}
|
||||||
|
|
||||||
|
{% include 'snippets/form_errors.html' with errors_list=form.invite_request_text.errors id="desc_invite_request_text" %}
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_invite_requests_question">
|
||||||
|
{{ form.invite_request_question }}
|
||||||
|
{% trans "Set a question for invite requests" %}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_invite_question_text">
|
||||||
|
{% trans "Question:" %}
|
||||||
|
{{ form.invite_question_text }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if not site.allow_invite_requests and not site.allow_registration %}
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_registration_closed_text">{% trans "Registration closed text:" %}</label>
|
||||||
|
{{ form.registration_closed_text }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<footer class="block">
|
||||||
|
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
|
||||||
|
</footer>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -86,6 +86,16 @@ urlpatterns = [
|
||||||
r"^settings/dashboard/?$", views.Dashboard.as_view(), name="settings-dashboard"
|
r"^settings/dashboard/?$", views.Dashboard.as_view(), name="settings-dashboard"
|
||||||
),
|
),
|
||||||
re_path(r"^settings/site-settings/?$", views.Site.as_view(), name="settings-site"),
|
re_path(r"^settings/site-settings/?$", views.Site.as_view(), name="settings-site"),
|
||||||
|
re_path(
|
||||||
|
r"^settings/site-registration/?$",
|
||||||
|
views.RegistrationLimited.as_view(),
|
||||||
|
name="settings-registration-limited",
|
||||||
|
),
|
||||||
|
re_path(
|
||||||
|
r"^settings/site-registration-admin/?$",
|
||||||
|
views.Registration.as_view(),
|
||||||
|
name="settings-registration",
|
||||||
|
),
|
||||||
re_path(r"^settings/themes/?$", views.Themes.as_view(), name="settings-themes"),
|
re_path(r"^settings/themes/?$", views.Themes.as_view(), name="settings-themes"),
|
||||||
re_path(
|
re_path(
|
||||||
r"^settings/themes/(?P<theme_id>\d+)/delete/?$",
|
r"^settings/themes/(?P<theme_id>\d+)/delete/?$",
|
||||||
|
|
|
@ -23,7 +23,7 @@ from .admin.reports import (
|
||||||
unsuspend_user,
|
unsuspend_user,
|
||||||
moderator_delete_user,
|
moderator_delete_user,
|
||||||
)
|
)
|
||||||
from .admin.site import Site
|
from .admin.site import Site, Registration, RegistrationLimited
|
||||||
from .admin.themes import Themes, delete_theme
|
from .admin.themes import Themes, delete_theme
|
||||||
from .admin.user_admin import UserAdmin, UserAdminList
|
from .admin.user_admin import UserAdmin, UserAdminList
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,60 @@ class Site(View):
|
||||||
return TemplateResponse(request, "settings/site.html", data)
|
return TemplateResponse(request, "settings/site.html", data)
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(login_required, name="dispatch")
|
||||||
|
@method_decorator(
|
||||||
|
permission_required("bookwyrm.edit_instance_settings", raise_exception=True),
|
||||||
|
name="dispatch",
|
||||||
|
)
|
||||||
|
class RegistrationLimited(View):
|
||||||
|
"""Things related to registering that non-admins owners can change"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""edit form"""
|
||||||
|
site = models.SiteSettings.objects.get()
|
||||||
|
data = {"form": forms.RegistrationLimitedForm(instance=site)}
|
||||||
|
return TemplateResponse(request, "settings/registration_limited.html", data)
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
"""edit the site settings"""
|
||||||
|
site = models.SiteSettings.objects.get()
|
||||||
|
form = forms.RegistrationLimitedForm(request.POST, request.FILES, instance=site)
|
||||||
|
if not form.is_valid():
|
||||||
|
data = {"form": form}
|
||||||
|
return TemplateResponse(request, "settings/registration_limited.html", data)
|
||||||
|
site = form.save(request)
|
||||||
|
|
||||||
|
data = {"form": forms.RegistrationLimitedForm(instance=site), "success": True}
|
||||||
|
return TemplateResponse(request, "settings/registration_limited.html", data)
|
||||||
|
|
||||||
|
|
||||||
|
@method_decorator(login_required, name="dispatch")
|
||||||
|
@method_decorator(
|
||||||
|
permission_required("bookwyrm.manage_registration", raise_exception=True),
|
||||||
|
name="dispatch",
|
||||||
|
)
|
||||||
|
class Registration(View):
|
||||||
|
"""Control everything about registration"""
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
"""edit form"""
|
||||||
|
site = models.SiteSettings.objects.get()
|
||||||
|
data = {"form": forms.RegistrationForm(instance=site)}
|
||||||
|
return TemplateResponse(request, "settings/registration.html", data)
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
"""edit the site settings"""
|
||||||
|
site = models.SiteSettings.objects.get()
|
||||||
|
form = forms.RegistrationForm(request.POST, request.FILES, instance=site)
|
||||||
|
if not form.is_valid():
|
||||||
|
data = {"form": form}
|
||||||
|
return TemplateResponse(request, "settings/registration.html", data)
|
||||||
|
site = form.save(request)
|
||||||
|
|
||||||
|
data = {"form": forms.RegistrationForm(instance=site), "success": True}
|
||||||
|
return TemplateResponse(request, "settings/registration.html", data)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@permission_required("bookwyrm.edit_instance_settings", raise_exception=True)
|
@permission_required("bookwyrm.edit_instance_settings", raise_exception=True)
|
||||||
def email_preview(request):
|
def email_preview(request):
|
||||||
|
|
Loading…
Reference in a new issue