From 561ba00f18b1ff9bc2415abcc525be9470146d87 Mon Sep 17 00:00:00 2001 From: Kolja Gorter Date: Sat, 14 May 2022 18:22:13 +0200 Subject: [PATCH] Add function to change root chanel name of mumble server Show the current name of the root channel Reviewed-by: James Valleroy [james: Use augeas for config file operations] [james: Pass channel name on command line] [james: Add functional test for change root channel name] Signed-off-by: James Valleroy --- actions/mumble | 24 +++++++++++++++++++ plinth/modules/mumble/__init__.py | 5 ++++ plinth/modules/mumble/forms.py | 10 ++++++++ .../modules/mumble/tests/test_functional.py | 14 +++++++++-- plinth/modules/mumble/views.py | 6 +++++ 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/actions/mumble b/actions/mumble index e2ec6fba2..288e0072d 100755 --- a/actions/mumble +++ b/actions/mumble @@ -12,6 +12,8 @@ from subprocess import PIPE, Popen import augeas +from plinth import action_utils + CONFIG_FILE = '/etc/mumble-server.ini' DATA_DIR = '/var/lib/mumble-server' @@ -30,6 +32,13 @@ def parse_arguments(): subparser = subparsers.add_parser('set-domain', help='Setup Mumble domain') subparser.add_argument('domain_name', help='Domain name to be allowed') + subparser = subparsers.add_parser('change-root-channel-name', + help='Set the root channel name') + subparser.add_argument('root_channel_name', help='New root channel name') + + subparsers.add_parser('get-root-channel-name', + help='Print the root channel name') + subparsers.required = True return parser.parse_args() @@ -83,6 +92,21 @@ def subcommand_set_domain(arguments): domain_file.write_text(arguments.domain_name) +def subcommand_change_root_channel_name(arguments): + """Change the name of the Root channel.""" + aug = load_augeas() + aug.set('.anon/registerName', arguments.root_channel_name) + aug.save() + action_utils.service_try_restart('mumble-server') + + +def subcommand_get_root_channel_name(_): + aug = load_augeas() + name = aug.get('.anon/registerName') + if name: + print(name) + + def load_augeas(): """Initialize Augeas.""" aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD + diff --git a/plinth/modules/mumble/__init__.py b/plinth/modules/mumble/__init__.py index 2ac3de5ef..9a5005da1 100644 --- a/plinth/modules/mumble/__init__.py +++ b/plinth/modules/mumble/__init__.py @@ -152,3 +152,8 @@ def get_domains(): return [domain] return [] + + +def get_root_channel_name(): + """Return the root channel name.""" + return actions.superuser_run('mumble', ['get-root-channel-name']) diff --git a/plinth/modules/mumble/forms.py b/plinth/modules/mumble/forms.py index 3e2c72ece..bf96be18b 100644 --- a/plinth/modules/mumble/forms.py +++ b/plinth/modules/mumble/forms.py @@ -34,3 +34,13 @@ class MumbleForm(forms.Form): 'SuperUser password can be used to manage permissions in Mumble.'), required=False, ) + + root_channel_name = forms.CharField( + label=_('Set the name for the root channel'), + min_length=1, + max_length=32, + help_text=_( + 'Set the name of the main channel of your mumble server. ' + 'If the name was never changed, the channel is named Root.'), + required=False, + ) diff --git a/plinth/modules/mumble/tests/test_functional.py b/plinth/modules/mumble/tests/test_functional.py index b10109394..4a9912f2e 100644 --- a/plinth/modules/mumble/tests/test_functional.py +++ b/plinth/modules/mumble/tests/test_functional.py @@ -5,12 +5,12 @@ Functional, browser based tests for mumble app. import pytest -from plinth.tests.functional import BaseAppTests +from plinth.tests import functional pytestmark = [pytest.mark.apps, pytest.mark.mumble] -class TestMumbleApp(BaseAppTests): +class TestMumbleApp(functional.BaseAppTests): app_name = 'mumble' has_service = True has_web = False @@ -20,3 +20,13 @@ class TestMumbleApp(BaseAppTests): # TODO: Improve test_backup_restore to actually check that data such # as rooms, identity or certificates are restored. + + def test_change_root_channel_name(self, session_browser): + functional.app_enable(session_browser, 'mumble') + functional.nav_to_module(session_browser, 'mumble') + session_browser.find_by_id('id_root_channel_name').fill('testing123') + functional.submit(session_browser, form_class='form-configuration') + + functional.nav_to_module(session_browser, 'mumble') + assert session_browser.find_by_id( + 'id_root_channel_name').value == 'testing123' diff --git a/plinth/modules/mumble/views.py b/plinth/modules/mumble/views.py index 999579143..7c590a0cb 100644 --- a/plinth/modules/mumble/views.py +++ b/plinth/modules/mumble/views.py @@ -16,6 +16,7 @@ class MumbleAppView(AppView): """Return the values to fill in the form.""" initial = super().get_initial() initial['domain'] = mumble.get_domain() + initial['root_channel_name'] = mumble.get_root_channel_name() return initial def form_valid(self, form): @@ -38,4 +39,9 @@ class MumbleAppView(AppView): messages.success(self.request, _('SuperUser password successfully updated.')) + name = new_config.get('root_channel_name') + if name: + actions.superuser_run('mumble', ['change-root-channel-name', name]) + messages.success(self.request, _('Root channel name changed.')) + return super().form_valid(form)