sharing: Allow directories to be publicly shared

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:35 -04:00
1 parent d0ed538bfa
commit 1eec1cf9ce
4 files changed
+54 -20

No files matched your search

+5 -4
View File
@@ -69,11 +69,12 @@ def list_shares():
return json.loads(output)['shares']
def add_share(name, path, groups):
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, '--groups'] + groups)
actions.superuser_run('sharing', [
'add', '--name', name, '--path', path, '--is-public', is_public,
'--groups'
] + groups)
def remove_share(name):
+18 -4
View File
@@ -22,8 +22,8 @@ from django import forms
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from plinth.modules.users.forms import get_group_choices
from plinth.modules import sharing
from plinth.modules.users.forms import get_group_choices
class AddShareForm(forms.Form):
@@ -39,11 +39,15 @@ class AddShareForm(forms.Form):
label=_('Path to share'), strip=True, help_text=_(
'Disk path to a folder on this server that you intend to share.'))
is_public = forms.BooleanField(
label=_('Public share'), required=False, help_text=_(
'Make files in this folder available to anyone with the link.'))
groups = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
label=_('User groups who can read the files in the share'),
widget=forms.CheckboxSelectMultiple, required=False,
label=_('User groups that can read the files in the share'),
help_text=_(
'Users who have these permissions will also be able to read the '
'Users of the selected user groups will be able to read the '
'files in the share.'))
def __init__(self, *args, **kwargs):
@@ -63,3 +67,13 @@ class AddShareForm(forms.Form):
raise ValidationError(_('A share with this name already exists.'))
return name
def clean(self):
"""Check that at least one group is added for non-public shares."""
super(AddShareForm, self).clean()
is_public = self.cleaned_data.get('is_public')
groups = self.cleaned_data.get('groups')
if not is_public and not groups:
raise forms.ValidationError(
_('Shares should be either public or shared with at least one group'
))
+6 -5
View File
@@ -61,8 +61,9 @@ class AddShareView(SuccessMessageMixin, FormView):
def form_valid(self, form):
"""Add the share on valid form submission."""
sharing.add_share(form.cleaned_data['name'], form.cleaned_data['path'],
form.cleaned_data['groups'])
data = form.cleaned_data
sharing.add_share(data['name'], data['path'], data['groups'],
str(data['is_public']).lower())
return super().form_valid(form)
@@ -94,9 +95,9 @@ class EditShareView(SuccessMessageMixin, FormView):
"""Add the share on valid form submission."""
if form.initial != form.cleaned_data:
sharing.remove_share(form.initial['name'])
sharing.add_share(form.cleaned_data['name'],
form.cleaned_data['path'],
form.cleaned_data['groups'])
data = form.cleaned_data
sharing.add_share(data['name'], data['path'], data['groups'],
str(data['is_public']).lower())
return super().form_valid(form)