Add function to change root chanel name of mumble server

Show the current name of the root channel

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
[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 <jvalleroy@mailbox.org>
This commit is contained in:
Kolja Gorter 2022-05-14 18:22:13 +02:00 committed by James Valleroy
parent 411f42edb2
commit 561ba00f18
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
5 changed files with 57 additions and 2 deletions

View File

@ -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 +

View File

@ -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'])

View File

@ -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,
)

View File

@ -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'

View File

@ -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)