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

Gère les utilisateurs inexistants dans RedirectOldContentOfAuthor #6331

Merged
merged 4 commits into from
Jul 19, 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
23 changes: 23 additions & 0 deletions zds/tutorialv2/tests/tests_views/tests_redirect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.test import TestCase
from django.urls import reverse

from zds.member.tests.factories import ProfileFactory


class RedirectOldContentOfAuthorTest(TestCase):
def test_redirect(self):
user = ProfileFactory().user

response = self.client.get(reverse("content:legacy-find-tutorial", args=[user.pk]))
self.assertRedirects(response, reverse("tutorial:find-tutorial", args=[user]), status_code=301)

response = self.client.get(reverse("content:legacy-find-article", args=[user.pk]))
self.assertRedirects(response, reverse("article:find-article", args=[user]), status_code=301)

response = self.client.get(reverse("content:legacy-find-opinion", args=[user.pk]))
self.assertRedirects(response, reverse("opinion:find-opinion", args=[user]), status_code=301)

# The user with pk=3954 doesn't exist (the view in the redirection
# triggers the 404, so we need to follow the response):
response = self.client.get(reverse("content:legacy-find-tutorial", args=[3954]), follow=True)
self.assertEqual(response.status_code, 404)
6 changes: 3 additions & 3 deletions zds/tutorialv2/urls/urls_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
name="find-contribution-all",
),
path("commentaires/<int:pk>/", ListContentReactions.as_view(), name="list-content-reactions"),
path("tutoriels/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="TUTORIAL")),
path("articles/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="ARTICLE")),
path("tribunes/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="OPINION")),
path("tutoriels/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="TUTORIAL"), name="legacy-find-tutorial"),
path("articles/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="ARTICLE"), name="legacy-find-article"),
path("tribunes/<int:pk>/", RedirectOldContentOfAuthor.as_view(type="OPINION"), name="legacy-find-opinion"),
path("aides/", ContentsWithHelps.as_view(), name="helps"),
path("aides/<int:pk>/change/", ChangeHelp.as_view(), name="helps-change"),
path(
Expand Down
3 changes: 3 additions & 0 deletions zds/tutorialv2/views/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def get_redirect_url(self, **kwargs):
user = User.objects.filter(pk=int(kwargs["pk"])).first()
route = None

if not user:
raise Http404("Cet utilisateur est inconnu dans le système")

if self.type == "TUTORIAL":
route = "tutorial:find-tutorial"
elif self.type == "ARTICLE":
Expand Down