Skip to content

Commit

Permalink
Permet de verrouiller les commentaires d'un contenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Situphen committed Mar 30, 2024
1 parent 2da324a commit 7e8ee01
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load i18n %}
{% load captureas %}
{% load crispy_forms_tags %}
{% load set %}

{% if administration_actions.show_block %}
<div class="mobile-menu-bloc mobile-all-links mobile-show-ico" data-title="Administration">
Expand Down Expand Up @@ -66,6 +67,24 @@ <h3>{% trans "Administration" %}</h3>
</li>
{% crispy form_jsfiddle %}
{% endif %}

{% if administration_actions.show_content_reactions_lock %}
{% if content.is_locked %}
{% trans "Déverrouiller les commentaires" as button_text %}
{% set "unlock" as hidden_action %}
{% else %}
{% trans "Verrouiller les commentaires" as button_text %}
{% set "lock" as hidden_action %}
{% endif %}

<li>
<form action="{% url 'content:lock-reactions' object.pk %}" method="post">
{% csrf_token %}
<input type="hidden" name="action" value="{{ hidden_action }}">
<button class="ico-after lock" type="submit">{{ button_text }}</button>
</form>
</li>
{% endif %}
</ul>
</div>
{% endif %}
1 change: 1 addition & 0 deletions zds/tutorialv2/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions zds/tutorialv2/urls/urls_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
SendNoteAlert,
SolveNoteAlert,
FollowContentReaction,
LockContentReactions,
)

feeds = [
Expand Down Expand Up @@ -139,6 +140,7 @@ def get_version_pages():
),
path("<int:pk>/<slug:slug>/", ContentDraftView.as_view(public_is_prioritary=False), name="view"),
path("telecharger/<int:pk>/<slug:slug>/", DownloadContent.as_view(), name="download-zip"),
path("verrouiller-commentaires/<int:pk>/", 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"),
Expand Down
21 changes: 21 additions & 0 deletions zds/tutorialv2/views/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
4 changes: 4 additions & 0 deletions zds/tutorialv2/views/display/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
)

Expand All @@ -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__(
Expand Down

0 comments on commit 7e8ee01

Please sign in to comment.