mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
deprecate CanCreateMixin
Les motifs de cette déprécation sont indiqués dans la documentation. Le mixin a été remplacé par `PermissionRequiredMixin` dans les endroits où ce remplacement était aisé.
This commit is contained in:
@ -26,6 +26,7 @@ from django.conf import settings
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from pytest_django.asserts import assertRedirects
|
||||
|
||||
from core.models import Notification, User
|
||||
from pedagogy.models import UV, UVComment, UVCommentReport
|
||||
@ -106,7 +107,7 @@ class TestUVCreation(TestCase):
|
||||
def test_create_uv_unauthorized_fail(self):
|
||||
# Test with anonymous user
|
||||
response = self.client.post(self.create_uv_url, create_uv_template(0))
|
||||
assert response.status_code == 403
|
||||
assertRedirects(response, reverse("core:login") + f"?next={self.create_uv_url}")
|
||||
|
||||
# Test with subscribed user
|
||||
self.client.force_login(self.sli)
|
||||
@ -815,11 +816,11 @@ class TestUVCommentReportCreate(TestCase):
|
||||
self.create_report_test("guy", success=False)
|
||||
|
||||
def test_create_report_anonymous_fail(self):
|
||||
url = reverse("pedagogy:comment_report", kwargs={"comment_id": self.comment.id})
|
||||
response = self.client.post(
|
||||
reverse("pedagogy:comment_report", kwargs={"comment_id": self.comment.id}),
|
||||
{"comment": self.comment.id, "reporter": 0, "reason": "C'est moche"},
|
||||
url, {"comment": self.comment.id, "reporter": 0, "reason": "C'est moche"}
|
||||
)
|
||||
assert response.status_code == 403
|
||||
assertRedirects(response, reverse("core:login") + f"?next={url}")
|
||||
assert not UVCommentReport.objects.all().exists()
|
||||
|
||||
def test_notifications(self):
|
||||
|
@ -22,7 +22,7 @@
|
||||
#
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db.models import Exists, OuterRef
|
||||
from django.shortcuts import get_object_or_404
|
||||
@ -35,12 +35,7 @@ from django.views.generic import (
|
||||
UpdateView,
|
||||
)
|
||||
|
||||
from core.auth.mixins import (
|
||||
CanCreateMixin,
|
||||
CanEditPropMixin,
|
||||
CanViewMixin,
|
||||
FormerSubscriberMixin,
|
||||
)
|
||||
from core.auth.mixins import CanEditPropMixin, CanViewMixin, FormerSubscriberMixin
|
||||
from core.models import Notification, User
|
||||
from core.views import DetailFormView
|
||||
from pedagogy.forms import (
|
||||
@ -136,12 +131,13 @@ class UVGuideView(LoginRequiredMixin, FormerSubscriberMixin, TemplateView):
|
||||
}
|
||||
|
||||
|
||||
class UVCommentReportCreateView(CanCreateMixin, CreateView):
|
||||
class UVCommentReportCreateView(PermissionRequiredMixin, CreateView):
|
||||
"""Create a new report for an inapropriate comment."""
|
||||
|
||||
model = UVCommentReport
|
||||
form_class = UVCommentReportForm
|
||||
template_name = "core/edit.jinja"
|
||||
permission_required = "pedagogy.add_uvcommentreport"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.uv_comment = get_object_or_404(UVComment, pk=kwargs["comment_id"])
|
||||
@ -202,12 +198,13 @@ class UVModerationFormView(FormView):
|
||||
return reverse_lazy("pedagogy:moderation")
|
||||
|
||||
|
||||
class UVCreateView(CanCreateMixin, CreateView):
|
||||
class UVCreateView(PermissionRequiredMixin, CreateView):
|
||||
"""Add a new UV (Privileged)."""
|
||||
|
||||
model = UV
|
||||
form_class = UVForm
|
||||
template_name = "pedagogy/uv_edit.jinja"
|
||||
permission_required = "pedagogy.add_uv"
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
|
Reference in New Issue
Block a user