mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
- This will act as centralized location to set the URL to lookup IP addresses. Tests: - When no value is set initially, the URL for Foundation is shown. This also happens when the value is removed from 'plinth_kvstore' sqlite3 table. - When empty value is set it, the empty value is set in DB and show in the UI. - When no value is changed and form is updated, message is shown that settings have not changed. - When value is changed and form is updated the updated value is shown in the form, message is shown that configuration has been updated. - Updated URL value reflects in the email app and errors change accordingly. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Benedek Nagy <contact@nbenedek.me>
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""Views for privacy app."""
|
|
|
|
from django.contrib import messages
|
|
from django.utils.translation import gettext as _
|
|
|
|
import plinth.modules.names.privileged as names_privileged
|
|
from plinth.modules import names, privacy
|
|
from plinth.modules.privacy.forms import PrivacyForm
|
|
from plinth.views import AppView
|
|
|
|
from . import privileged
|
|
|
|
|
|
class PrivacyAppView(AppView):
|
|
"""Serve configuration page."""
|
|
|
|
app_id = 'privacy'
|
|
form_class = PrivacyForm
|
|
|
|
def get_initial(self):
|
|
"""Return the values to fill in the form."""
|
|
initial = super().get_initial()
|
|
initial.update(privileged.get_configuration())
|
|
initial['ip_lookup_url'] = privacy.get_ip_lookup_url()
|
|
if names.is_resolved_installed():
|
|
initial.update(names_privileged.get_resolved_configuration())
|
|
|
|
return initial
|
|
|
|
def form_valid(self, form):
|
|
"""Change the configurations of Minetest service."""
|
|
new_config = form.cleaned_data
|
|
old_config = form.initial
|
|
|
|
changes = {}
|
|
is_changed = False
|
|
if old_config['enable_popcon'] != new_config['enable_popcon']:
|
|
changes['enable_popcon'] = new_config['enable_popcon']
|
|
|
|
if 'dns_fallback' in old_config:
|
|
if old_config['dns_fallback'] != new_config['dns_fallback']:
|
|
names_privileged.set_resolved_configuration(
|
|
dns_fallback=new_config['dns_fallback'])
|
|
is_changed = True
|
|
|
|
if old_config['ip_lookup_url'] != new_config['ip_lookup_url']:
|
|
privacy.set_ip_lookup_url(new_config['ip_lookup_url'])
|
|
is_changed = True
|
|
|
|
if changes:
|
|
privileged.set_configuration(**changes)
|
|
|
|
if changes or is_changed:
|
|
messages.success(self.request, _('Configuration updated'))
|
|
|
|
return super().form_valid(form)
|