Skip to content

Commit

Permalink
Autorise uniquement les requêtes POST pour signaler une faute dans un…
Browse files Browse the repository at this point in the history
… contenu (#6330)

Et s'assure que le paramètre `target` existe avant de l'utiliser.
  • Loading branch information
philippemilink authored Jun 16, 2022
1 parent d861945 commit d43fa12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions zds/tutorialv2/tests/tests_views/tests_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.models import Group
from django.http import HttpResponseNotAllowed
from django.urls import reverse
from django.test import TestCase
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -2760,6 +2761,22 @@ def test_warn_typo(self):

self.client.force_login(self.user_guest)

# check the request to warn about a typo can't be a GET
result = self.client.get(
reverse("content:warn-typo") + f"?pk={tuto.pk}",
{"pk": tuto.pk, "version": sha_beta, "text": typo_text, "target": ""},
follow=True,
)
self.assertEqual(result.status_code, HttpResponseNotAllowed.status_code)

# check the 'target' field in the request isn't mandatory
result = self.client.post(
reverse("content:warn-typo") + f"?pk={tuto.pk}",
{"pk": tuto.pk, "version": sha_beta, "text": typo_text},
follow=True,
)
self.assertEqual(result.status_code, 200)

# check if user can warn typo in tutorial
result = self.client.post(
reverse("content:warn-typo") + f"?pk={tuto.pk}",
Expand Down
3 changes: 2 additions & 1 deletion zds/tutorialv2/views/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class WarnTypo(SingleContentFormViewMixin):
must_be_author = False
only_draft_version = False

http_method_names = ["post"]
object = None

def get_form_kwargs(self):
Expand All @@ -90,7 +91,7 @@ def get_form_kwargs(self):
kwargs["content"] = versioned
kwargs["targeted"] = versioned

if self.request.POST["target"]:
if "target" in self.request.POST and self.request.POST["target"] != "":
kwargs["targeted"] = search_container_or_404(versioned, self.request.POST["target"])

kwargs["public"] = True
Expand Down

0 comments on commit d43fa12

Please sign in to comment.