diff --git a/actions/matrixsynapse b/actions/matrixsynapse index 3ac930f28..f0c115386 100755 --- a/actions/matrixsynapse +++ b/actions/matrixsynapse @@ -16,14 +16,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # - """ Configuration helper for Matrix-Synapse server. """ + import argparse -from ruamel.yaml import round_trip_dump, round_trip_load -from ruamel.yaml.scalarstring import DoubleQuotedScalarString +import yaml from plinth import action_utils from plinth.modules.matrixsynapse import CONFIG_FILE_PATH @@ -37,7 +36,7 @@ def parse_arguments(): subparsers.add_parser('enable', help='Enable matrix-synapse service') subparsers.add_parser('disable', help='Disable matrix-synapse service') help_pubreg = 'Enable/Disable/Status public user registration.' - pubreg = subparsers.add_parser('public_registration', help=help_pubreg) + pubreg = subparsers.add_parser('public-registration', help=help_pubreg) pubreg.add_argument('command', choices=('enable', 'disable', 'status'), help=help_pubreg) setup = subparsers.add_parser('setup', help='Set domain name for Matrix') @@ -52,7 +51,7 @@ def parse_arguments(): def subcommand_post_install(_): """Perform post installation configuration.""" with open(CONFIG_FILE_PATH) as config_file: - config = round_trip_load(config_file) + config = yaml.load(config_file) config['max_upload_size'] = '100M' @@ -61,24 +60,24 @@ def subcommand_post_install(_): listener['bind_address'] = '0.0.0.0' # Setup ldap parameters - __ = DoubleQuotedScalarString config['password_providers'] = [{}] - config['password_providers'][0]['module'] = __( - 'ldap_auth_provider.LdapAuthProvider') + config['password_providers'][0][ + 'module'] = 'ldap_auth_provider.LdapAuthProvider' ldap_config = { 'enabled': True, - 'uri': __('ldap://localhost:389'), + 'uri': 'ldap://localhost:389', 'start_tls': False, - 'base': __('ou=users,dc=thisbox'), + 'base': 'ou=users,dc=thisbox', 'attributes': { - 'uid': __('uid'), - 'name': __('uid'), - 'mail': __('') + 'uid': 'uid', + 'name': 'uid', + 'mail': '' } } config['password_providers'][0]['config'] = ldap_config + with open(CONFIG_FILE_PATH, 'w') as config_file: - round_trip_dump(config, config_file) + yaml.dump(config, config_file) if action_utils.service_is_running('matrix-synapse'): action_utils.service_restart('matrix-synapse') @@ -87,8 +86,9 @@ def subcommand_post_install(_): def subcommand_setup(arguments): """Configure the domain name for matrix-synapse package.""" domain_name = arguments.domain_name - action_utils.dpkg_reconfigure('matrix-synapse', - {'server-name': domain_name}) + action_utils.dpkg_reconfigure('matrix-synapse', { + 'server-name': domain_name + }) subcommand_enable(arguments) @@ -107,7 +107,7 @@ def subcommand_disable(_): def subcommand_public_registration(argument): """Enable/Disable/Status public user registration.""" with open(CONFIG_FILE_PATH) as config_file: - config = round_trip_load(config_file) + config = yaml.load(config_file) if argument.command == 'status': if config['enable_registration']: @@ -122,7 +122,7 @@ def subcommand_public_registration(argument): config['enable_registration'] = False with open(CONFIG_FILE_PATH, 'w') as config_file: - round_trip_dump(config, config_file) + yaml.dump(config, config_file) if action_utils.service_is_running('matrix-synapse'): action_utils.service_restart('matrix-synapse') diff --git a/debian/control b/debian/control index 69bbe28de..0232cc92d 100644 --- a/debian/control +++ b/debian/control @@ -35,6 +35,7 @@ Build-Depends: debhelper (>= 10~) , python3-ruamel.yaml , python3-setuptools , python3-setuptools-git + , python3-yaml , xmlto Standards-Version: 4.1.2 Homepage: https://salsa.debian.org/freedombox-team/plinth @@ -75,6 +76,7 @@ Depends: ${python3:Depends} , python3-psutil , python3-requests , python3-ruamel.yaml + , python3-yaml , sudo Description: web front end for administering every aspect of a FreedomBox The FreedomBox is a net appliance conceived by Eben Moglen. It diff --git a/plinth/modules/matrixsynapse/__init__.py b/plinth/modules/matrixsynapse/__init__.py index a2034a740..d94d2c5f7 100644 --- a/plinth/modules/matrixsynapse/__init__.py +++ b/plinth/modules/matrixsynapse/__init__.py @@ -158,6 +158,6 @@ def get_configured_domain_name(): def get_public_registration_status(): """Return whether public registration is enabled.""" - output = actions.superuser_run('matrixsynapse', ['public_registration', - 'status']) + output = actions.superuser_run('matrixsynapse', + ['public-registration', 'status']) return output.strip() == 'enabled' diff --git a/plinth/modules/matrixsynapse/views.py b/plinth/modules/matrixsynapse/views.py index 21b850853..468cbdeeb 100644 --- a/plinth/modules/matrixsynapse/views.py +++ b/plinth/modules/matrixsynapse/views.py @@ -25,13 +25,13 @@ from django.utils.translation import ugettext_lazy as _ from django.views.generic import FormView from plinth import actions -from plinth.views import ServiceView -from plinth.modules import matrixsynapse from plinth.forms import DomainSelectionForm +from plinth.modules import matrixsynapse from plinth.utils import get_domain_names +from plinth.views import ServiceView -from .forms import MatrixSynapseForm from . import get_public_registration_status +from .forms import MatrixSynapseForm class SetupView(FormView): @@ -111,15 +111,15 @@ class MatrixSynapseServiceView(ServiceView): messages.success(self.request, _('Application disabled')) if not pubreg_same: - # note action public_registration restarts, if running now + # note action public-registration restarts, if running now if new_config['enable_public_registration']: actions.superuser_run('matrixsynapse', - ['public_registration', 'enable']) + ['public-registration', 'enable']) messages.success(self.request, _('Public registration enabled')) else: actions.superuser_run('matrixsynapse', - ['public_registration', 'disable']) + ['public-registration', 'disable']) messages.success(self.request, _('Public registration disabled'))