Sunil Mohan Adapa 20081ee5d1
roundcube: Use privileged to simplify actions
Tests:

- Functional tests pass

- Same tests as previous patch for setting logging to syslog.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-07-17 17:23:18 -04:00

35 lines
975 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Views for roundcube.
"""
from django.contrib import messages
from django.utils.translation import gettext_lazy as _
from plinth.views import AppView
from . import privileged
from .forms import RoundcubeForm
class RoundcubeAppView(AppView):
"""Roundcube configuration page."""
app_id = 'roundcube'
form_class = RoundcubeForm
def get_initial(self):
"""Return the values to fill in the form."""
initial = super().get_initial()
initial['local_only'] = privileged.get_config()['local_only']
return initial
def form_valid(self, form):
"""Change the config of Roundcube app."""
old_data = form.initial
data = form.cleaned_data
if old_data['local_only'] != data['local_only']:
privileged.set_config(data['local_only'])
messages.success(self.request, _('Configuration updated'))
return super().form_valid(form)