[damned-lies] Fixed response returned from reserve API in case of error



commit ddd2bb9a4c7d6362991db78dd72f623633715666
Author: Claude Paroz <claude 2xlibre net>
Date:   Sat May 8 12:19:15 2021 +0200

    Fixed response returned from reserve API in case of error

 api/tests.py | 3 +++
 api/views.py | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/api/tests.py b/api/tests.py
index 06658812..0930cec9 100644
--- a/api/tests.py
+++ b/api/tests.py
@@ -124,6 +124,9 @@ class APITests(TestCase):
         self.assertEqual(mail.outbox[0].recipients(), [team.mailing_list])
         state = State.objects.get(person=translator)
         self.assertEqual(state.name, 'Translating')
+        # Test cannot reserve a second time
+        response = self.client.post(url, data={})
+        self.assertEqual(response.status_code, 403)
 
     def test_upload_translation(self):
         translator = Person.objects.create(
diff --git a/api/views.py b/api/views.py
index e8f1df0a..19cbf847 100644
--- a/api/views.py
+++ b/api/views.py
@@ -219,7 +219,7 @@ class ReserveTranslationView(LoginRequiredMixin, VertimusPageMixin, View):
         stats, state = self.get_state_from_kwargs()
         actions = [x.name for x in state.get_available_actions(request.user.person)]
         if 'RT' not in actions:
-            raise PermissionDenied('This module cannot be reserved')
+            return HttpResponseForbidden('This module cannot be reserved')
 
         action = ActionRT(person=request.user.person)
         action.apply_on(state, {'comment': '', 'send_to_ml': True})


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]