sharing: Use privileged decorator for actions

Tests:

- Initial setup works.
  - Empty Apache configuration file is created
- Adding a share works all the information added is shown during editing.
  Configuration file is updated as expected.
- List of shares is shown as expected.
- When editing a share, information about share is shown correctly. Editing
  works are expected.
- Removing a share works.
- Trying to add share with a name that already exists throws a proper error
  message.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2022-10-08 18:53:10 -04:00
1 parent 6e7b31a3cf
commit 637e6b1198
5 files changed
+175 -248

No files matched your search

+1 -25
View File
@@ -1,13 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app to configure sharing.
"""
import json
"""FreedomBox app to configure sharing."""
from django.utils.translation import gettext_lazy as _
from plinth import actions
from plinth import app as app_module
from plinth import cfg, menu
from plinth.modules.apache.components import Webserver
@@ -60,22 +55,3 @@ class SharingApp(app_module.App):
super().setup(old_version)
privileged.setup()
self.enable()
def list_shares():
"""Return a list of shares."""
output = actions.superuser_run('sharing', ['list'])
return json.loads(output)['shares']
def add_share(name, path, groups, is_public):
"""Add a new share by called the action script."""
args = ['add', '--name', name, '--path', path, '--groups'] + groups
if is_public:
args.append('--is-public')
actions.superuser_run('sharing', args)
def remove_share(name):
"""Remove a share by calling the action script."""
actions.superuser_run('sharing', ['remove', '--name', name])