mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
security: Use AppView for app page
Tests: - Enable/disable button is not shown. - Diagnostics are shown and work. - Initial status of the configuration is show properly. - Enabling/disabling configuration options reflects correct status. - Status of frequent features updates shows properly. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
a7eb5e8f0e
commit
29bf55dedb
@ -32,6 +32,8 @@ class SecurityApp(app_module.App):
|
||||
|
||||
_version = 7
|
||||
|
||||
can_be_disabled = False
|
||||
|
||||
def __init__(self):
|
||||
"""Create components for the app."""
|
||||
super().__init__()
|
||||
|
||||
@ -4,6 +4,7 @@ Functional, browser based tests for security app.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from plinth.tests import functional
|
||||
|
||||
pytestmark = [pytest.mark.system, pytest.mark.essential, pytest.mark.security]
|
||||
@ -44,7 +45,7 @@ def _enable_restricted_logins(browser, should_enable):
|
||||
else:
|
||||
browser.uncheck('security-restricted_access')
|
||||
|
||||
functional.submit(browser)
|
||||
functional.submit(browser, form_class='form-configuration')
|
||||
|
||||
|
||||
def _get_restricted_logins(browser):
|
||||
|
||||
@ -8,6 +8,6 @@ from django.urls import re_path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r'^sys/security/$', views.index, name='index'),
|
||||
re_path(r'^sys/security/$', views.SecurityAppView.as_view(), name='index'),
|
||||
re_path(r'^sys/security/report$', views.report, name='report'),
|
||||
]
|
||||
|
||||
@ -8,34 +8,37 @@ from django.template.response import TemplateResponse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from plinth import action_utils, actions
|
||||
from plinth import app as app_module
|
||||
from plinth.modules import security
|
||||
from plinth.modules.upgrades import is_backports_requested
|
||||
from plinth.views import AppView
|
||||
|
||||
from .forms import SecurityForm
|
||||
|
||||
|
||||
def index(request):
|
||||
"""Serve the security configuration form"""
|
||||
status = get_status(request)
|
||||
class SecurityAppView(AppView):
|
||||
"""Show security app main page."""
|
||||
|
||||
form = None
|
||||
app_id = 'security'
|
||||
template_name = 'security.html'
|
||||
form_class = SecurityForm
|
||||
prefix = 'security'
|
||||
|
||||
if request.method == 'POST':
|
||||
form = SecurityForm(request.POST, initial=status, prefix='security')
|
||||
if form.is_valid():
|
||||
_apply_changes(request, status, form.cleaned_data)
|
||||
status = get_status(request)
|
||||
form = SecurityForm(initial=status, prefix='security')
|
||||
else:
|
||||
form = SecurityForm(initial=status, prefix='security')
|
||||
def get_initial(self):
|
||||
"""Return the values to fill in the form."""
|
||||
initial = super().get_initial()
|
||||
initial.update(get_status(self.request))
|
||||
return initial
|
||||
|
||||
return TemplateResponse(
|
||||
request, 'security.html', {
|
||||
'app_info': app_module.App.get('security').info,
|
||||
'form': form,
|
||||
'is_backports_requested': is_backports_requested(),
|
||||
})
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
"""Add additional context data for template."""
|
||||
context = super().get_context_data(*args, **kwargs)
|
||||
context['is_backports_requested'] = is_backports_requested()
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
"""Apply the changes submitted in the form."""
|
||||
_apply_changes(self.request, form.initial, form.cleaned_data)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
def get_status(request):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user