mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
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 <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
9fc8c3604c
commit
654d69a389
@ -43,8 +43,9 @@ def parse_arguments():
|
|||||||
add_parser.add_argument('--path', required=True, help='Disk path to share')
|
add_parser.add_argument('--path', required=True, help='Disk path to share')
|
||||||
add_parser.add_argument('--groups', nargs='*',
|
add_parser.add_argument('--groups', nargs='*',
|
||||||
help='List of groups that can access the share')
|
help='List of groups that can access the share')
|
||||||
add_parser.add_argument('--is-public', default=False, required=False,
|
add_parser.add_argument('--is-public', required=False, default=False,
|
||||||
help='1 if public share else 0')
|
action="store_true",
|
||||||
|
help='Allow public access to this share')
|
||||||
|
|
||||||
remove_parser = subparsers.add_parser('remove',
|
remove_parser = subparsers.add_parser('remove',
|
||||||
help='Remove an existing share')
|
help='Remove an existing share')
|
||||||
@ -94,7 +95,7 @@ def subcommand_add(arguments):
|
|||||||
aug.set('$conf/Location[last()]/directive[last()]/arg',
|
aug.set('$conf/Location[last()]/directive[last()]/arg',
|
||||||
'includes/freedombox-sharing.conf')
|
'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() + 1]', 'Include')
|
||||||
aug.set('$conf/Location[last()]/directive[last()]/arg',
|
aug.set('$conf/Location[last()]/directive[last()]/arg',
|
||||||
'includes/freedombox-single-sign-on.conf')
|
'includes/freedombox-single-sign-on.conf')
|
||||||
|
|||||||
@ -71,10 +71,10 @@ def list_shares():
|
|||||||
|
|
||||||
def add_share(name, path, groups, is_public):
|
def add_share(name, path, groups, is_public):
|
||||||
"""Add a new share by called the action script."""
|
"""Add a new share by called the action script."""
|
||||||
actions.superuser_run('sharing', [
|
args = ['add', '--name', name, '--path', path, '--groups'] + groups
|
||||||
'add', '--name', name, '--path', path, '--is-public', is_public,
|
if is_public:
|
||||||
'--groups'
|
args.append('--is-public')
|
||||||
] + groups)
|
actions.superuser_run('sharing', args)
|
||||||
|
|
||||||
|
|
||||||
def remove_share(name):
|
def remove_share(name):
|
||||||
|
|||||||
@ -61,9 +61,7 @@ class AddShareView(SuccessMessageMixin, FormView):
|
|||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
"""Add the share on valid form submission."""
|
"""Add the share on valid form submission."""
|
||||||
data = form.cleaned_data
|
_add_share(form.cleaned_data)
|
||||||
sharing.add_share(data['name'], data['path'], data['groups'],
|
|
||||||
str(data['is_public']).lower())
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
@ -95,13 +93,16 @@ class EditShareView(SuccessMessageMixin, FormView):
|
|||||||
"""Add the share on valid form submission."""
|
"""Add the share on valid form submission."""
|
||||||
if form.initial != form.cleaned_data:
|
if form.initial != form.cleaned_data:
|
||||||
sharing.remove_share(form.initial['name'])
|
sharing.remove_share(form.initial['name'])
|
||||||
data = form.cleaned_data
|
_add_share(form.cleaned_data)
|
||||||
sharing.add_share(data['name'], data['path'], data['groups'],
|
|
||||||
str(data['is_public']).lower())
|
|
||||||
|
|
||||||
return super().form_valid(form)
|
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
|
@require_POST
|
||||||
def remove(request, name):
|
def remove(request, name):
|
||||||
"""View to remove a share."""
|
"""View to remove a share."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user