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

further coverage bump, remove debug code

Rafał Pitoń 8 лет назад
Родитель
Сommit
870b095193

+ 3 - 3
misago/threads/api/threadendpoints/patch.py

@@ -16,7 +16,8 @@ from ...participants import (
     add_participant, change_owner, make_participants_aware, remove_participant)
 from ...permissions import (
     allow_add_participants, allow_add_participant,
-    allow_change_owner, allow_remove_participant, allow_start_thread)
+    allow_change_owner, allow_edit_thread,
+    allow_remove_participant, allow_start_thread)
 from ...serializers import ThreadParticipantSerializer
 from ...utils import add_categories_to_items
 from ...validators import validate_title
@@ -46,8 +47,7 @@ def patch_title(request, thread, value):
     except ValidationError as e:
         raise PermissionDenied(e.args[0])
 
-    if not thread.acl.get('can_edit'):
-        raise PermissionDenied(_("You don't have permission to edit this thread."))
+    allow_edit_thread(request.user, thread)
 
     moderation.change_thread_title(request, thread, value_cleaned)
     return {'title': thread.title}

+ 0 - 1
misago/threads/permissions/threads.py

@@ -585,7 +585,6 @@ def allow_edit_post(user, target):
             raise PermissionDenied(_("This post is protected. You can't edit it."))
 
         if not has_time_to_edit_post(user, target):
-            raise Exception()
             message = ungettext(
                 "You can't edit posts that are older than %(minutes)s minute.",
                 "You can't edit posts that are older than %(minutes)s minutes.",

+ 23 - 2
misago/threads/tests/test_thread_patch_api.py

@@ -1,6 +1,7 @@
+from datetime import timedelta
 import json
 
-from django.utils import six
+from django.utils import six, timezone
 
 from misago.acl.testutils import override_acl
 from misago.categories.models import Category
@@ -64,7 +65,27 @@ class ThreadChangeTitleApiTests(ThreadPatchApiTestCase):
 
         response_json = response.json()
         self.assertEqual(response_json['detail'][0],
-            "You don't have permission to edit this thread.")
+            "You can't edit threads in this category.")
+
+    def test_change_thread_title_after_edit_time(self):
+        """api cleans, validates and rejects too short title"""
+        self.override_acl({
+            'thread_edit_time': 1,
+            'can_edit_threads': 1
+        })
+
+        self.thread.starter = self.user
+        self.thread.started_on = timezone.now() - timedelta(minutes=10)
+        self.thread.save()
+
+        response = self.patch(self.api_link, [
+            {'op': 'replace', 'path': 'title', 'value': "Lorem ipsum change!"}
+        ])
+        self.assertEqual(response.status_code, 400)
+
+        response_json = response.json()
+        self.assertEqual(response_json['detail'][0],
+            "You can't edit threads that are older than 1 minute.")
 
     def test_change_thread_title_invalid(self):
         """api cleans, validates and rejects too short title"""