Sunil Mohan Adapa 89a4d25909
radicale: Use privileged decorator for actions
Tests:

- Functional tests work
- When the app is enabled, if the log path does not exist, it is created
  /var/log/radicale.
- Not tested: upgrading from older version to 3.x
- Setting the access rights works. It is reflected in the app page and
  configuration file /etc/radicale/config.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:52:53 -04:00

48 lines
1.1 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Configure Radicale."""
import os
import augeas
from plinth import action_utils
from plinth.actions import privileged
CONFIG_FILE = '/etc/radicale/config'
LOG_PATH = '/var/log/radicale'
@privileged
def configure(rights_type: str):
"""Set the radicale rights type to a particular value."""
if rights_type == 'owner_only':
# Default rights file is equivalent to owner_only.
rights_type = 'from_file'
aug = load_augeas()
aug.set('/files' + CONFIG_FILE + '/rights/type', rights_type)
aug.save()
action_utils.service_try_restart('uwsgi')
@privileged
def fix_paths():
"""Fix log path to work around a bug."""
# Workaround for bug in radicale's uwsgi script (#931201)
if not os.path.exists(LOG_PATH):
os.makedirs(LOG_PATH)
def load_augeas():
"""Initialize Augeas."""
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
augeas.Augeas.NO_MODL_AUTOLOAD)
# INI file lens
aug.set('/augeas/load/Puppet/lens', 'Puppet.lns')
aug.set('/augeas/load/Puppet/incl[last() + 1]', CONFIG_FILE)
aug.load()
return aug