diff --git a/templates/tutorialv2/includes/sidebar/administration_actions.part.html b/templates/tutorialv2/includes/sidebar/administration_actions.part.html index 2ae5450331..8e5333d7b9 100644 --- a/templates/tutorialv2/includes/sidebar/administration_actions.part.html +++ b/templates/tutorialv2/includes/sidebar/administration_actions.part.html @@ -1,6 +1,7 @@ {% load i18n %} {% load captureas %} {% load crispy_forms_tags %} +{% load set %} {% if administration_actions.show_block %} {% endif %} diff --git a/zds/tutorialv2/models/database.py b/zds/tutorialv2/models/database.py index a39153f24e..2ae15e734e 100644 --- a/zds/tutorialv2/models/database.py +++ b/zds/tutorialv2/models/database.py @@ -464,6 +464,7 @@ def insert_data_in_versioned(self, versioned): "sha_picked", "converted_to", "type", + "is_locked", ] fns = ["in_beta", "in_validation", "in_public", "get_absolute_contact_url", "get_note_count", "antispam"] diff --git a/zds/tutorialv2/urls/urls_contents.py b/zds/tutorialv2/urls/urls_contents.py index e3299d0db5..d661e42724 100644 --- a/zds/tutorialv2/urls/urls_contents.py +++ b/zds/tutorialv2/urls/urls_contents.py @@ -49,6 +49,7 @@ SendNoteAlert, SolveNoteAlert, FollowContentReaction, + LockContentReactions, ) feeds = [ @@ -139,6 +140,7 @@ def get_version_pages(): ), path("//", ContentDraftView.as_view(public_is_prioritary=False), name="view"), path("telecharger///", DownloadContent.as_view(), name="download-zip"), + path("verrouiller-commentaires//", LockContentReactions.as_view(), name="lock-reactions"), # reactions: path("reactions/ajouter/", SendNoteFormView.as_view(redirection_is_needed=False), name="add-reaction"), path("reactions/editer/", UpdateNoteView.as_view(redirection_is_needed=False), name="update-reaction"), diff --git a/zds/tutorialv2/views/comments.py b/zds/tutorialv2/views/comments.py index 291324ae15..c3a27299ba 100644 --- a/zds/tutorialv2/views/comments.py +++ b/zds/tutorialv2/views/comments.py @@ -366,3 +366,24 @@ def post(self, request, *args, **kwargs): if is_ajax(self.request): return HttpResponse(json_handler.dumps(response), content_type="application/json") return redirect(self.get_object().get_absolute_url()) + + +class LockContentReactions(LoginRequiredMixin, PermissionRequiredMixin, SingleOnlineContentViewMixin, FormView): + """Lock or unlock content reactions for a content""" + + permission_required = "tutorialv2.change_publishablecontent" + http_method_names = ["post"] + + def post(self, request, *args, **kwargs): + response = {} + self.public_content_object = self.get_public_object() + self.object = self.get_object() + if request.POST.get("action") == "lock": + self.object.is_locked = True + self.object.save() + elif request.POST.get("action") == "unlock": + self.object.is_locked = False + self.object.save() + if is_ajax(self.request): + return HttpResponse(json_handler.dumps(response), content_type="application/json") + return redirect(self.public_content_object.get_absolute_url()) diff --git a/zds/tutorialv2/views/display/config.py b/zds/tutorialv2/views/display/config.py index 085da2fe31..bdd6ce9d1f 100644 --- a/zds/tutorialv2/views/display/config.py +++ b/zds/tutorialv2/views/display/config.py @@ -24,6 +24,7 @@ def show_block(self) -> bool: or self.show_opinion_moderated() or self.show_gallery_link() or self.show_jsfiddle() + or self.show_content_reactions_lock() ) ) @@ -48,6 +49,9 @@ def show_gallery_link(self) -> bool: def show_jsfiddle(self) -> bool: return self.enabled and self.is_staff and self.requires_validation + def show_content_reactions_lock(self) -> bool: + return self.enabled and self.is_staff + class PublicActionsState: def __init__(