Commit 654d69a3 authored by Joseph Nuthalapati's avatar Joseph Nuthalapati Committed by James Valleroy

sharing: Simplify --is-public option

Use store_true with default=False to toggle public status based on whether
'--is-public' argument is passed or not.
Signed-off-by: Joseph Nuthalapati's avatarJoseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy's avatarJames Valleroy <jvalleroy@mailbox.org>
parent 9fc8c360
......@@ -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')
......
......@@ -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):
......
......@@ -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."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment