names: Create a generic TLS domain selection form

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati authored and James Valleroy committed 2021-11-21 19:04:35 -05:00
1 parent 5c62fc7599
commit a912c867c8
5 files changed
+32 -37

No files matched your search

+11
View File
@@ -93,3 +93,14 @@ def on_domain_removed(sender, domain_type, name='', **kwargs):
logger.info('Remove domain %s of type %s', domain_name.name,
domain_type)
######################################################
# Domain utilities meant to be used by other modules #
######################################################
def get_available_tls_domains():
"""Return an iterator with all domains able to have a certificate."""
return (domain.name for domain in components.DomainName.list()
if domain.domain_type.can_have_certificate)
+1 -7
View File
@@ -114,12 +114,6 @@ def setup(helper, old_version=None):
app.get_component('letsencrypt-quassel').setup_certificates()
def get_available_domains():
"""Return an iterator with all domains able to have a certificate."""
return (domain.name for domain in names.components.DomainName.list()
if domain.domain_type.can_have_certificate)
def set_domain(domain):
"""Set the TLS domain by writing a file to data directory."""
if domain:
@@ -136,7 +130,7 @@ def get_domain():
pass
if not domain:
domain = next(get_available_domains(), None)
domain = next(names.get_available_tls_domains(), None)
set_domain(domain)
return domain
-27
View File
@@ -1,27 +0,0 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Forms for Quassel app.
"""
from django import forms
from django.utils.translation import gettext_lazy as _
from plinth.modules import quassel
def get_domain_choices():
"""Double domain entries for inclusion in the choice field."""
return ((domain, domain) for domain in quassel.get_available_domains())
class QuasselForm(forms.Form):
"""Form to select a TLS domain for Quassel."""
domain = forms.ChoiceField(
choices=get_domain_choices,
label=_('TLS domain'),
help_text=_(
'Select a domain to use TLS with. If the list is empty, please '
'configure at least one domain with certificates.'),
required=False,
)
+2 -3
View File
@@ -3,15 +3,14 @@
from django.contrib import messages
from django.utils.translation import gettext_lazy as _
from plinth.forms import TLSDomainForm
from plinth.modules import quassel
from plinth.views import AppView
from .forms import QuasselForm
class QuasselAppView(AppView):
app_id = 'quassel'
form_class = QuasselForm
form_class = TLSDomainForm
def get_initial(self):
"""Return the values to fill in the form."""