diff --git a/templates/tutorialv2/messages/add_contribution_pm.md b/templates/tutorialv2/messages/add_contribution_pm.md index 01099e3747..3bd75581c2 100644 --- a/templates/tutorialv2/messages/add_contribution_pm.md +++ b/templates/tutorialv2/messages/add_contribution_pm.md @@ -1,9 +1,9 @@ {% load i18n %} -{% blocktrans with title=content.title|safe type=type|safe user=user|safe %} +{% blocktrans with title=content.title|safe user=user|safe %} Bonjour {{ user }}, -Vous avez été ajouté à la liste des contributeurs {{type}} « {{ title }} », en tant que {{role}}. +Vous avez été ajouté à la liste des contributeurs de la publication « {{ title }} », en tant que {{ role }}. Merci pour votre participation ! {% endblocktrans %} diff --git a/zds/tutorialv2/tests/tests_views/tests_addcontributor.py b/zds/tutorialv2/tests/tests_views/tests_addcontributor.py index abd6293471..9577fbc0d8 100644 --- a/zds/tutorialv2/tests/tests_views/tests_addcontributor.py +++ b/zds/tutorialv2/tests/tests_views/tests_addcontributor.py @@ -8,6 +8,7 @@ from zds.member.tests.factories import ProfileFactory, StaffProfileFactory +from zds.tutorialv2.models import CONTENT_TYPE_LIST from zds.tutorialv2.tests.factories import ContentContributionRoleFactory, PublishableContentFactory from zds.tutorialv2.views.contributors import ContributionForm from zds.tutorialv2.models.database import ContentContribution @@ -61,26 +62,14 @@ def test_authenticated_author(self): response = self.client.post(self.form_url, self.form_data) self.assertRedirects(response, self.content_url) - def test_authenticated_staff_tutorial(self): + def test_authenticated_staff(self): self.client.force_login(self.staff) - self.content.type = "TUTORIAL" - self.content.save() - response = self.client.post(self.form_url, self.form_data) - self.assertRedirects(response, self.content_url) - - def test_authenticated_staff_article(self): - self.client.force_login(self.staff) - self.content.type = "ARTICLE" - self.content.save() - response = self.client.post(self.form_url, self.form_data) - self.assertRedirects(response, self.content_url) - - def test_authenticated_staff_opinion(self): - self.client.force_login(self.staff) - self.content.type = "OPINION" - self.content.save() - response = self.client.post(self.form_url, self.form_data) - self.assertEqual(response.status_code, 403) + for type in CONTENT_TYPE_LIST: + with self.subTest(type): + self.content.type = type + self.content.save() + response = self.client.post(self.form_url, self.form_data) + self.assertRedirects(response, self.content_url) class AddContributorWorkflowTests(TutorialTestMixin, TestCase): diff --git a/zds/tutorialv2/tests/tests_views/tests_removecontributor.py b/zds/tutorialv2/tests/tests_views/tests_removecontributor.py index 700775af12..a26706f960 100644 --- a/zds/tutorialv2/tests/tests_views/tests_removecontributor.py +++ b/zds/tutorialv2/tests/tests_views/tests_removecontributor.py @@ -79,7 +79,7 @@ def test_authenticated_staff_opinion(self): self.content.type = "OPINION" self.content.save() response = self.client.post(self.form_url, self.form_data) - self.assertEqual(response.status_code, 403) + self.assertRedirects(response, self.content_url) class RemoveContributorWorkflowTests(TutorialTestMixin, TestCase): diff --git a/zds/tutorialv2/views/contributors.py b/zds/tutorialv2/views/contributors.py index aa810822d8..ea63246d70 100644 --- a/zds/tutorialv2/views/contributors.py +++ b/zds/tutorialv2/views/contributors.py @@ -3,17 +3,15 @@ from crispy_forms.bootstrap import StrictButton from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout, Field -from django import forms +from django import forms from django.conf import settings from django.contrib import messages from django.contrib.auth.models import User -from django.core.exceptions import PermissionDenied from django.http import Http404 from django.shortcuts import redirect, get_object_or_404 from django.template.loader import render_to_string from django.urls import reverse -from django.utils.text import format_lazy from django.utils.translation import gettext_lazy as _ from zds.member.decorator import LoggedWithReadWriteHability @@ -80,13 +78,6 @@ def clean_username(self): return cleaned_data -class RemoveContributionForm(forms.Form): - pk_contribution = forms.CharField( - label=_("Contributeur"), - required=True, - ) - - class AddContributorToContent(LoggedWithReadWriteHability, SingleContentFormViewMixin): must_be_author = True form_class = ContributionForm @@ -103,18 +94,11 @@ def get(self, request, *args, **kwargs): return redirect(url, self.request.user) def form_valid(self, form): - _type = _("à l'article") - - if self.object.is_tutorial: - _type = _("au tutoriel") - elif self.object.is_opinion: - raise PermissionDenied - bot = get_bot_account() all_authors_pk = [author.pk for author in self.object.authors.all()] user = form.cleaned_data["user"] if user.pk in all_authors_pk: - messages.error(self.request, _("Un auteur ne peut pas être désigné comme contributeur")) + messages.error(self.request, _("Un auteur ne peut pas être désigné comme contributeur.")) return redirect(self.object.get_absolute_url()) else: contribution_role = form.cleaned_data.get("contribution_role") @@ -126,7 +110,7 @@ def form_valid(self, form): self.request, _( "Ce membre fait déjà partie des " - 'contributeurs {} avec pour rôle "{}"'.format(_type, contribution_role.title) + 'contributeurs à la publication avec pour rôle "{}"'.format(contribution_role.title) ), ) return redirect(self.object.get_absolute_url()) @@ -139,13 +123,12 @@ def form_valid(self, form): send_mp( bot, [user], - format_lazy("{} {}", _("Contribution"), _type), + _("Contribution à la publication"), self.versioned_object.title, render_to_string( "tutorialv2/messages/add_contribution_pm.md", { "content": self.object, - "type": _type, "url": self.object.get_absolute_url(), "index": url_index, "user": user.username, @@ -168,18 +151,19 @@ def form_invalid(self, form): return super().form_valid(form) +class RemoveContributionForm(forms.Form): + pk_contribution = forms.CharField( + label=_("Contributeur"), + required=True, + ) + + class RemoveContributorFromContent(LoggedWithReadWriteHability, SingleContentFormViewMixin): form_class = RemoveContributionForm must_be_author = True authorized_for_staff = True def form_valid(self, form): - _type = _("cet article") - if self.object.is_tutorial: - _type = _("ce tutoriel") - elif self.object.is_opinion: - raise PermissionDenied - contribution = get_object_or_404(ContentContribution, pk=form.cleaned_data["pk_contribution"]) user = contribution.user contribution.delete() @@ -187,7 +171,8 @@ def form_valid(self, form): sender=self.__class__, content=self.object, performer=self.request.user, contributor=user, action="remove" ) messages.success( - self.request, _("Vous avez enlevé {} de la liste des contributeurs de {}.").format(user.username, _type) + self.request, + _("Vous avez enlevé {} de la liste des contributeurs de cette publication.").format(user.username), ) self.success_url = self.object.get_absolute_url() diff --git a/zds/tutorialv2/views/display/config.py b/zds/tutorialv2/views/display/config.py index a57840e0bc..767952b5b6 100644 --- a/zds/tutorialv2/views/display/config.py +++ b/zds/tutorialv2/views/display/config.py @@ -174,7 +174,7 @@ def show_categories_management(self) -> bool: return self.enabled and self.is_allowed def show_contributors_management(self) -> bool: - return self.enabled and self.is_allowed and self.requires_validation + return self.enabled and self.is_allowed def show_ready_to_publish(self) -> bool: return self.enabled and self.is_allowed and self.requires_validation