mirror of
https://github.com/ae-utbm/sith.git
synced 2026-10-30 22:29:32 +00:00
2 files changed
+15
-14
No files matched your search
+12
-10
@@ -21,7 +21,7 @@ from wsgiref.util import FileWrapper
|
|||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied, ValidationError
|
||||||
from django.db.models import Exists, OuterRef
|
from django.db.models import Exists, OuterRef
|
||||||
from django.forms.models import modelform_factory
|
from django.forms.models import modelform_factory
|
||||||
from django.http import Http404, HttpRequest, HttpResponse
|
from django.http import Http404, HttpRequest, HttpResponse
|
||||||
@@ -233,6 +233,12 @@ class FileEditPropForm(forms.ModelForm):
|
|||||||
|
|
||||||
recursive = forms.BooleanField(label=_("Apply rights recursively"), required=False)
|
recursive = forms.BooleanField(label=_("Apply rights recursively"), required=False)
|
||||||
|
|
||||||
|
def clean_parent(self):
|
||||||
|
parent = self.cleaned_data["parent"]
|
||||||
|
if not self.instance.owner.can_edit(parent):
|
||||||
|
raise ValidationError(_("You cannot move this file there"))
|
||||||
|
return parent
|
||||||
|
|
||||||
|
|
||||||
class FileEditPropView(CanEditPropMixin, UpdateView):
|
class FileEditPropView(CanEditPropMixin, UpdateView):
|
||||||
model = SithFile
|
model = SithFile
|
||||||
@@ -253,10 +259,7 @@ class FileEditPropView(CanEditPropMixin, UpdateView):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse(
|
return reverse("core:file_detail", kwargs={"file_id": self.object.id})
|
||||||
"core:file_detail",
|
|
||||||
kwargs={"file_id": self.object.id},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class FileView(CanViewMixin, DetailView, FormMixin):
|
class FileView(CanViewMixin, DetailView, FormMixin):
|
||||||
@@ -269,7 +272,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
|
|||||||
form_class = AddFilesForm
|
form_class = AddFilesForm
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def handle_clipboard(request, obj):
|
def handle_clipboard(request, obj: SithFile):
|
||||||
"""Handle the clipboard in the view.
|
"""Handle the clipboard in the view.
|
||||||
|
|
||||||
This method can fail, since it does not catch the exceptions coming from
|
This method can fail, since it does not catch the exceptions coming from
|
||||||
@@ -283,10 +286,9 @@ class FileView(CanViewMixin, DetailView, FormMixin):
|
|||||||
where you want to paste the clipboard
|
where you want to paste the clipboard
|
||||||
"""
|
"""
|
||||||
if "delete" in request.POST:
|
if "delete" in request.POST:
|
||||||
for f_id in request.POST.getlist("file_list"):
|
file_ids = request.POST.getlist("file_list")
|
||||||
file = SithFile.objects.filter(id=f_id).first()
|
for file in obj.children.filter(id__in=file_ids):
|
||||||
if file:
|
file.delete()
|
||||||
file.delete()
|
|
||||||
if "clear" in request.POST:
|
if "clear" in request.POST:
|
||||||
request.session["clipboard"] = []
|
request.session["clipboard"] = []
|
||||||
if "cut" in request.POST:
|
if "cut" in request.POST:
|
||||||
|
|||||||
+3
-4
@@ -184,10 +184,9 @@ class DeleteAllForumUserMessagesView(FormView):
|
|||||||
form_class = SelectUserForm
|
form_class = SelectUserForm
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
res = super().dispatch(request, *args, **kwargs)
|
if not request.user.is_root:
|
||||||
if request.user.is_root:
|
raise PermissionDenied
|
||||||
return res
|
return super().dispatch(request, *args, **kwargs)
|
||||||
raise PermissionDenied
|
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
self.user = form.cleaned_data["user"]
|
self.user = form.cleaned_data["user"]
|
||||||
|
|||||||
Reference in new issue
Block a user