mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Add recursive option to apply rights in the SAS
This commit is contained in:
parent
dd2be2a31e
commit
352b8f0b4f
@ -612,6 +612,15 @@ class SithFile(models.Model):
|
||||
if copy_rights:
|
||||
self.copy_rights()
|
||||
|
||||
def apply_rights_recursively(self, only_folders=False):
|
||||
print(self)
|
||||
children = self.children.all()
|
||||
if only_folders:
|
||||
children = children.filter(is_folder=True)
|
||||
for c in children:
|
||||
c.copy_rights()
|
||||
c.apply_rights_recursively(only_folders)
|
||||
|
||||
def copy_rights(self):
|
||||
"""Copy, if possible, the rights of the parent folder"""
|
||||
if self.parent is not None:
|
||||
|
@ -162,7 +162,8 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
self.object.generate_thumbnail()
|
||||
if not self.object.file:
|
||||
self.object.generate_thumbnail()
|
||||
self.form = self.get_form()
|
||||
if 'clipboard' not in request.session.keys():
|
||||
request.session['clipboard'] = []
|
||||
@ -232,6 +233,7 @@ class AlbumEditForm(forms.ModelForm):
|
||||
fields=['name', 'file', 'parent', 'edit_groups']
|
||||
parent = make_ajax_field(Album, 'parent', 'files', help_text="")
|
||||
edit_groups = make_ajax_field(Album, 'edit_groups', 'groups', help_text="")
|
||||
recursive = forms.BooleanField(label=_("Apply rights recursively"), required=False)
|
||||
|
||||
class PictureEditView(CanEditMixin, UpdateView):
|
||||
model=Picture
|
||||
@ -245,3 +247,8 @@ class AlbumEditView(CanEditMixin, UpdateView):
|
||||
template_name='core/edit.jinja'
|
||||
pk_url_kwarg = "album_id"
|
||||
|
||||
def form_valid(self, form):
|
||||
ret = super(AlbumEditView, self).form_valid(form)
|
||||
if form.cleaned_data['recursive']:
|
||||
self.object.apply_rights_recursively(True)
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user