mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-22 10:01:45 +00:00
quassel: Use privileged decorator for actions
Tests: - Functional tests work - Setting the domain updates the configuration file, reflects in the app page Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
7870d43c33
commit
8478450467
@ -1,40 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
Configuration helper for Quassel.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import pathlib
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparser = subparsers.add_parser('set-domain',
|
||||
help='Setup Quassel configuration')
|
||||
subparser.add_argument('domain_name', help='Domain name to be allowed')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_set_domain(arguments):
|
||||
"""Write a file containing domain name."""
|
||||
domain_file = pathlib.Path('/var/lib/quassel/domain-freedombox')
|
||||
domain_file.write_text(arguments.domain_name, encoding='utf-8')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
subcommand = arguments.subcommand.replace('-', '_')
|
||||
subcommand_method = globals()['subcommand_' + subcommand]
|
||||
subcommand_method(arguments)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@ -1,14 +1,11 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
FreedomBox app for Quassel.
|
||||
"""
|
||||
"""FreedomBox app for Quassel."""
|
||||
|
||||
import pathlib
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from plinth import actions
|
||||
from plinth import app as app_module
|
||||
from plinth import cfg, frontpage, menu
|
||||
from plinth.daemon import Daemon
|
||||
@ -20,7 +17,7 @@ from plinth.modules.users.components import UsersAndGroups
|
||||
from plinth.package import Packages
|
||||
from plinth.utils import format_lazy
|
||||
|
||||
from . import manifest
|
||||
from . import manifest, privileged
|
||||
|
||||
_description = [
|
||||
format_lazy(
|
||||
@ -108,7 +105,7 @@ class QuasselApp(app_module.App):
|
||||
def set_domain(domain):
|
||||
"""Set the TLS domain by writing a file to data directory."""
|
||||
if domain:
|
||||
actions.superuser_run('quassel', ['set-domain', domain])
|
||||
privileged.set_domain(domain)
|
||||
|
||||
|
||||
def get_domain():
|
||||
|
||||
13
plinth/modules/quassel/privileged.py
Normal file
13
plinth/modules/quassel/privileged.py
Normal file
@ -0,0 +1,13 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Configure Quassel."""
|
||||
|
||||
import pathlib
|
||||
|
||||
from plinth.actions import privileged
|
||||
|
||||
|
||||
@privileged
|
||||
def set_domain(domain_name: str):
|
||||
"""Write a file containing domain name."""
|
||||
domain_file = pathlib.Path('/var/lib/quassel/domain-freedombox')
|
||||
domain_file.write_text(domain_name, encoding='utf-8')
|
||||
Loading…
x
Reference in New Issue
Block a user