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:
Joseph Nuthalapati authored and James Valleroy committed 2019-07-22 17:56:50 -04:00
1 parent 9fc8c3604c
commit 654d69a389
3 files changed
+15 -13

No files matched your search

+4 -4
View File
@@ -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):
+7 -6
View File
@@ -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."""