Просмотр исходного кода

Deprecate per-type attachment size limit

rafalp 2 лет назад
Родитель
Сommit
837d820b98

+ 2 - 1
misago/threads/admin/forms.py

@@ -70,7 +70,8 @@ class AttachmentTypeForm(forms.ModelForm):
             ),
             "size_limit": _(
                 "Maximum allowed uploaded file size for this type, in kb. "
-                "May be overriden via user permission."
+                "This setting is deprecated and has no effect. It will be "
+                "deleted in Misago 1.0."
             ),
             "status": _("Controls this attachment type availability on your site."),
             "limit_uploads_to": _(

+ 5 - 18
misago/threads/api/attachments.py

@@ -9,7 +9,7 @@ from ...users.audittrail import create_audit_trail
 from ..models import Attachment, AttachmentType
 from ..serializers import AttachmentSerializer
 
-IMAGE_EXTENSIONS = ("jpg", "jpeg", "png", "gif")
+IMAGE_EXTENSIONS = ("jpg", "jpeg", "png", "gif", "webp")
 
 
 class AttachmentViewSet(viewsets.ViewSet):
@@ -29,7 +29,7 @@ class AttachmentViewSet(viewsets.ViewSet):
 
         user_roles = set(r.pk for r in request.user.get_roles())
         filetype = validate_filetype(upload, user_roles)
-        validate_filesize(upload, filetype, request.user_acl["max_attachment_size"])
+        validate_filesize(upload, request.user_acl["max_attachment_size"])
 
         attachment = Attachment(
             secret=Attachment.generate_new_secret(),
@@ -86,8 +86,8 @@ def validate_filetype(upload, user_roles):
     raise ValidationError(_("You can't upload files of this type."))
 
 
-def validate_filesize(upload, filetype, hard_limit):
-    if upload.size > hard_limit * 1024:
+def validate_filesize(upload, upload_limit):
+    if upload.size > upload_limit * 1024:
         message = _(
             "You can't upload files larger than %(limit)s (your file has %(upload)s)."
         )
@@ -95,20 +95,7 @@ def validate_filesize(upload, filetype, hard_limit):
             message
             % {
                 "upload": filesizeformat(upload.size).rstrip(".0"),
-                "limit": filesizeformat(hard_limit * 1024).rstrip(".0"),
-            }
-        )
-
-    if filetype.size_limit and upload.size > filetype.size_limit * 1024:
-        message = _(
-            "You can't upload files of this type larger "
-            "than %(limit)s (your file has %(upload)s)."
-        )
-        raise ValidationError(
-            message
-            % {
-                "upload": filesizeformat(upload.size).rstrip(".0"),
-                "limit": filesizeformat(filetype.size_limit * 1024).rstrip(".0"),
+                "limit": filesizeformat(upload_limit * 1024).rstrip(".0"),
             }
         )
 

+ 0 - 22
misago/threads/tests/test_attachments_api.py

@@ -122,28 +122,6 @@ class AttachmentsApiTestCase(AuthenticatedUserTestCase):
                 response.json(), {"detail": "You can't upload files of this type."}
             )
 
-    def test_upload_too_big_for_type(self):
-        """too big uploads are rejected"""
-        AttachmentType.objects.create(
-            name="Test extension",
-            extensions="png",
-            mimetypes="image/png",
-            size_limit=100,
-        )
-
-        with open(TEST_LARGEPNG_PATH, "rb") as upload:
-            response = self.client.post(self.api_link, data={"upload": upload})
-            self.assertEqual(response.status_code, 400)
-            self.assertEqual(
-                response.json(),
-                {
-                    "detail": (
-                        "You can't upload files of this type larger "
-                        "than 100.0\xa0KB (your file has 253.9\xa0KB)."
-                    )
-                },
-            )
-
     @patch_user_acl({"max_attachment_size": 100})
     def test_upload_too_big_for_user(self):
         """too big uploads are rejected"""