Skip to content

Commit

Permalink
Permet la gestion de contributeurs sur les billets
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed Dec 24, 2022
1 parent 6a31d96 commit 872f9b5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 60 deletions.
4 changes: 2 additions & 2 deletions templates/tutorialv2/includes/tags_authors.part.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
{% with count_contributions=contributions|length %}
{% if count_contributions > 0 %}
<p>
{% trans "Ce contenu a bénéficié des apports de" %}
<a href="#view-contributions" class="open-modal">{{ count_contributions }} {% trans "contributeur" %}{{ count_contributions|pluralize }}</a>
{% trans "Cette publication a bénéficié des apports de" %}
<a href="#view-contributions" class="open-modal">{{ count_contributions }} {% trans "contributeur" %}{{ count_contributions|pluralize }}</a>.

<div class="modal modal-flex" id="view-contributions" data-modal-close="Fermer">
<div class="members is-fullwidth">
Expand Down
4 changes: 2 additions & 2 deletions templates/tutorialv2/messages/add_contribution_pm.md
Original file line number Diff line number Diff line change
@@ -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 %}
4 changes: 2 additions & 2 deletions templates/tutorialv2/view/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ <h2>
{% endif %}
{# END AUTHORS #}
{# CONTRIBUTORS #}
{% if can_add_something and formAddReviewer %}
{% if can_add_something %}
<li>
<a href="#add-contributor" class="open-modal ico-after more blue">
{% trans "Ajouter un contributeur" %}
</a>
{% crispy formAddReviewer %}
{% crispy form_add_contributor %}
</li>
<li>
<a href="#manage-contributions" class="open-modal ico-after gear blue">
Expand Down
26 changes: 7 additions & 19 deletions zds/tutorialv2/tests/tests_views/tests_addcontributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,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)
types = ["TUTORIAL", "ARTICLE", "OPINION"]
for type in types:
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):
Expand Down
19 changes: 7 additions & 12 deletions zds/tutorialv2/tests/tests_views/tests_removecontributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,20 @@ def test_authenticated_author(self):
self.assertRedirects(response, self.content_url)

def test_authenticated_staff_tutorial(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)
self.perform_test_authenticated_staff("TUTORIAL")

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)
self.perform_test_authenticated_staff("ARTICLE")

def test_authenticated_staff_opinion(self):
self.perform_test_authenticated_staff("OPINION")

def perform_test_authenticated_staff(self, type):
self.client.force_login(self.staff)
self.content.type = "OPINION"
self.content.type = type
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):
Expand Down
8 changes: 4 additions & 4 deletions zds/tutorialv2/views/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ def get_context_data(self, **kwargs):

context["gallery"] = self.object.gallery
context["public_content_object"] = self.public_content_object
context["form_add_contributor"] = ContributionForm(content=self.object)
context["contributions"] = ContentContribution.objects.filter(content=self.object).order_by(
"contribution_role__position"
)
if self.object.type.lower() != "opinion":
context["formAddReviewer"] = ContributionForm(content=self.object)
context["contributions"] = ContentContribution.objects.filter(content=self.object).order_by(
"contribution_role__position"
)
context["content_suggestions"] = ContentSuggestion.objects.filter(publication=self.object)
excluded_for_search = [str(x.suggestion.pk) for x in context["content_suggestions"]]
excluded_for_search.append(str(self.object.pk))
Expand Down
24 changes: 5 additions & 19 deletions zds/tutorialv2/views/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,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")
Expand All @@ -64,7 +56,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())
Expand All @@ -77,13 +69,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,
Expand Down Expand Up @@ -114,20 +105,15 @@ class RemoveContributorFromContent(LoggedWithReadWriteHability, SingleContentFor
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()
signals.contributors_management.send(
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()

Expand Down

0 comments on commit 872f9b5

Please sign in to comment.