Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autorise uniquement les requêtes POST pour signaler une faute dans un contenu #6330

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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