mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-06 18:15:17 +00:00
Fix #608
This commit is contained in:
parent
dfe892d418
commit
f52ec66946
@ -26,7 +26,6 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from wsgiref.util import FileWrapper
|
from wsgiref.util import FileWrapper
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.core.exceptions import PermissionDenied
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -34,7 +33,14 @@ import os
|
|||||||
from ajax_select import make_ajax_field
|
from ajax_select import make_ajax_field
|
||||||
|
|
||||||
from core.models import SithFile, RealGroup, Notification
|
from core.models import SithFile, RealGroup, Notification
|
||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, can_view, not_found
|
from core.views import (
|
||||||
|
CanViewMixin,
|
||||||
|
CanEditMixin,
|
||||||
|
CanEditPropMixin,
|
||||||
|
can_view,
|
||||||
|
forbidden,
|
||||||
|
not_found,
|
||||||
|
)
|
||||||
from counter.models import Counter
|
from counter.models import Counter
|
||||||
|
|
||||||
|
|
||||||
@ -55,9 +61,14 @@ def send_file(request, file_id, file_class=SithFile, file_attr="file"):
|
|||||||
).exists()
|
).exists()
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
raise PermissionDenied
|
return forbidden(request, _("You are not allowed to view this file"))
|
||||||
name = f.__getattribute__(file_attr).name
|
name = f.__getattribute__(file_attr).name
|
||||||
filepath = os.path.join(settings.MEDIA_ROOT, name)
|
filepath = os.path.join(settings.MEDIA_ROOT, name)
|
||||||
|
|
||||||
|
# check if file exists on disk
|
||||||
|
if not os.path.exists(filepath.encode("utf-8")):
|
||||||
|
return not_found(request, _("File not found"))
|
||||||
|
|
||||||
with open(filepath.encode("utf-8"), "rb") as filename:
|
with open(filepath.encode("utf-8"), "rb") as filename:
|
||||||
wrapper = FileWrapper(filename)
|
wrapper = FileWrapper(filename)
|
||||||
response = HttpResponse(wrapper, content_type=f.mime_type)
|
response = HttpResponse(wrapper, content_type=f.mime_type)
|
||||||
|
@ -2519,6 +2519,14 @@ msgstr "Laverie"
|
|||||||
msgid "Files"
|
msgid "Files"
|
||||||
msgstr "Fichiers"
|
msgstr "Fichiers"
|
||||||
|
|
||||||
|
#: core/views/files.py:70
|
||||||
|
msgid "File not found"
|
||||||
|
msgstr "Fichier introuvable"
|
||||||
|
|
||||||
|
#: core/views/files.py:64
|
||||||
|
msgid "You are not allowed to view this file"
|
||||||
|
msgstr "Vous n'êtes pas autorisé à voir ce fichier"
|
||||||
|
|
||||||
#: core/templates/core/base.jinja:202 core/templates/core/user_tools.jinja:109
|
#: core/templates/core/base.jinja:202 core/templates/core/user_tools.jinja:109
|
||||||
msgid "Pedagogy"
|
msgid "Pedagogy"
|
||||||
msgstr "Pédagogie"
|
msgstr "Pédagogie"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user