Sunil Mohan Adapa 0881dae665
jsxc: Allow disabling the app
Closes: #1872.

Previously, JSXC can't be disabled and it's shortcut appears on the homepage
forever. Use the EnableState component which stores a flag in the sqlite
database to maintain the status of app being enabled.

Tests:

- Enable/disable button appears. Enabling/disabling the app updates the status
currently.

- Enabling the app shows icon on the homepage and disabling removes it.

- Enabling shows the menu item in the apps page as enabled. Disabling shows the
menu item in the apps page as disabled.

- It is possible the uninstall the app. When app is uninstall it is removed from
homepage and shows as disabled in the apps page.

- When app is disabled or uninstalled, trying to visit the
/plinth/apps/jsxc/jsxc/ throws a 404 error.

- Run functional tests.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
[jvalleroy: Enable JSXC for Ejabberd test]
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-29 21:06:54 -04:00

29 lines
871 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 import config
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):
"""Add domain information to view context."""
context = super().get_context_data(*args, **kwargs)
context['domainname'] = config.get_domainname()
return context