diff --git a/actions/sharing b/actions/sharing index d5fc0f6da..d40bd6319 100755 --- a/actions/sharing +++ b/actions/sharing @@ -43,8 +43,9 @@ def parse_arguments(): add_parser.add_argument('--path', required=True, help='Disk path to share') add_parser.add_argument('--groups', nargs='*', help='List of groups that can access the share') - add_parser.add_argument('--is-public', default=False, required=False, - help='1 if public share else 0') + add_parser.add_argument('--is-public', required=False, default=False, + action="store_true", + help='Allow public access to this share') remove_parser = subparsers.add_parser('remove', help='Remove an existing share') @@ -94,7 +95,7 @@ def subcommand_add(arguments): aug.set('$conf/Location[last()]/directive[last()]/arg', 'includes/freedombox-sharing.conf') - if is_public != "true": + if not is_public: aug.set('$conf/Location[last()]/directive[last() + 1]', 'Include') aug.set('$conf/Location[last()]/directive[last()]/arg', 'includes/freedombox-single-sign-on.conf') diff --git a/plinth/modules/sharing/__init__.py b/plinth/modules/sharing/__init__.py index 843bce10a..a6de7ac6a 100644 --- a/plinth/modules/sharing/__init__.py +++ b/plinth/modules/sharing/__init__.py @@ -71,10 +71,10 @@ def list_shares(): def add_share(name, path, groups, is_public): """Add a new share by called the action script.""" - actions.superuser_run('sharing', [ - 'add', '--name', name, '--path', path, '--is-public', is_public, - '--groups' - ] + groups) + args = ['add', '--name', name, '--path', path, '--groups'] + groups + if is_public: + args.append('--is-public') + actions.superuser_run('sharing', args) def remove_share(name): diff --git a/plinth/modules/sharing/views.py b/plinth/modules/sharing/views.py index 9d4fcfc8f..48b7ddf64 100644 --- a/plinth/modules/sharing/views.py +++ b/plinth/modules/sharing/views.py @@ -61,9 +61,7 @@ class AddShareView(SuccessMessageMixin, FormView): def form_valid(self, form): """Add the share on valid form submission.""" - data = form.cleaned_data - sharing.add_share(data['name'], data['path'], data['groups'], - str(data['is_public']).lower()) + _add_share(form.cleaned_data) return super().form_valid(form) @@ -95,13 +93,16 @@ class EditShareView(SuccessMessageMixin, FormView): """Add the share on valid form submission.""" if form.initial != form.cleaned_data: sharing.remove_share(form.initial['name']) - data = form.cleaned_data - sharing.add_share(data['name'], data['path'], data['groups'], - str(data['is_public']).lower()) + _add_share(form.cleaned_data) return super().form_valid(form) +def _add_share(form_data): + sharing.add_share(form_data['name'], form_data['path'], + form_data['groups'], form_data['is_public']) + + @require_POST def remove(request, name): """View to remove a share."""