Sunil Mohan Adapa 85a694f20f
names: Retrieve the most important domain in a more generic way
- The get_domain_name() has some problem. It returns only static domain names
but not a dynamic domain name. It may not always return the same domain when
multiple static domains are configured. It may return return an empty string.

Tests:

- JSXC page shows the alphabetically first static domain. If no static domain is
configured, first dynamic domain is shown, next pagekite domain, next pagekite
domain, next tor onion domain, and finally .local domain.

- Downloading profile from OpenVPN will set the first domain in it.

- When ejabberd is installed, the first domain is configured by default.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2025-02-16 10:45:05 -05:00

29 lines
917 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Views for the JSXC module."""
from django.http import Http404
from django.views.generic import TemplateView
import plinth.app as app_module
from plinth.modules.names.components import DomainName
class JsxcView(TemplateView):
"""A simple page to embed Javascript XMPP Client library."""
template_name = 'jsxc_launch.html'
def dispatch(self, request, *args, **kwargs):
"""Don't serve the view when app is disabled."""
app = app_module.App.get('jsxc')
if not app.is_enabled():
raise Http404
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, *args, **kwargs) -> dict[str, object]:
"""Add domain information to view context."""
context = super().get_context_data(*args, **kwargs)
context['domain_name'] = DomainName.list_names()[0]
return context