Exemplo n.º 1
0
def restore_edit(request, edit_pk):
    edit = get_object_or_404(CommentEdit, pk=edit_pk)
    comment = edit.comment

    if not comment.author == request.user \
            and not request.user.has_perm('forum.change_post'):
        raise PermissionDenied

    if not comment.is_visible:  # comment was hidden
        raise PermissionDenied

    if edit.deleted_by:
        raise PermissionDenied

    new_edit = CommentEdit()
    new_edit.comment = comment
    new_edit.editor = request.user
    new_edit.original_text = comment.text
    new_edit.save()

    comment.update = datetime.now()
    comment.editor = request.user
    comment.update_content(edit.original_text)
    # remove hat if the author doesn't have it anymore
    if comment.hat and comment.hat not in comment.author.profile.get_hats():
        comment.hat = None
    comment.save()

    return redirect(comment.get_absolute_url())
Exemplo n.º 2
0
def restore_edit(request, edit_pk):
    edit = get_object_or_404(CommentEdit, pk=edit_pk)
    comment = edit.comment

    if not comment.author == request.user and not request.user.has_perm(
            "forum.change_post"):
        raise PermissionDenied

    if not comment.is_visible:  # comment was hidden
        raise PermissionDenied

    if edit.deleted_by:
        raise PermissionDenied

    new_edit = CommentEdit()
    new_edit.comment = comment
    new_edit.editor = request.user
    new_edit.original_text = comment.text
    new_edit.save()

    comment.update = datetime.now()
    comment.editor = request.user
    comment.update_content(
        edit.original_text, lambda m: messages.error(
            request,
            _("Erreurs dans le markdown: {}").format("\n- ".join(m))))
    # remove hat if the author doesn't have it anymore
    if comment.hat and comment.hat not in comment.author.profile.get_hats():
        comment.hat = None
    comment.save()

    return redirect(comment.get_absolute_url())
Exemplo n.º 3
0
    def perform_edit_post(request, post, user, text):
        original_text = post.text
        # create an archive
        edit = CommentEdit()
        edit.comment = post
        edit.editor = user
        edit.original_text = original_text
        edit.save()

        post.update_content(
            text,
            on_error=lambda m: messages.error(
                request,
                _("Erreur du serveur Markdown:\n{}").format("\n- ".join(m))),
        )
        post.hat = get_hat_from_request(request, post.author)
        post.update = datetime.now()
        post.editor = user
        post.save()

        # Save topic to update update_index_date
        if post.position == 1:
            post.topic.save()

        return post
Exemplo n.º 4
0
    def form_valid(self, form):

        if self.check_as and self.object.antispam(self.request.user):
            raise PermissionDenied

        if "preview" in self.request.POST:
            return self.form_invalid(form)

        is_new = False

        if self.reaction:  # it's an edition
            edit = CommentEdit()
            edit.comment = self.reaction
            edit.editor = self.request.user
            edit.original_text = self.reaction.text
            edit.save()

            self.reaction.update = datetime.now()
            self.reaction.editor = self.request.user
            self.reaction.hat = get_hat_from_request(self.request,
                                                     self.reaction.author)

        else:
            self.reaction = ContentReaction()
            self.reaction.pubdate = datetime.now()
            self.reaction.author = self.request.user
            self.reaction.position = self.object.get_note_count() + 1
            self.reaction.related_content = self.object
            self.reaction.hat = get_hat_from_request(self.request)

            is_new = True

        # also treat alerts if editor is a moderator
        if self.request.user != self.reaction.author and not is_new:
            alerts = Alert.objects.filter(comment__pk=self.reaction.pk,
                                          solved=False)
            for alert in alerts:
                alert.solve(self.request.user, _("Le message a été modéré."))

        self.reaction.update_content(
            form.cleaned_data["text"],
            on_error=lambda m: messages.error(
                self.request,
                _("Erreur du serveur Markdown: {}").format("\n- ".join(m))),
        )
        self.reaction.ip_address = get_client_ip(self.request)
        self.reaction.save()

        if is_new:  # we first need to save the reaction
            self.object.last_note = self.reaction
            self.object.save(update_date=False)

        self.success_url = self.reaction.get_absolute_url()
        return super().form_valid(form)
Exemplo n.º 5
0
    def perform_edit_post(request, post, user, text):
        original_text = post.text
        # create an archive
        edit = CommentEdit()
        edit.comment = post
        edit.editor = user
        edit.original_text = original_text
        edit.save()

        post.update_content(
            text,
            on_error=lambda m: messages.error(
                request,
                _("Erreur du serveur Markdown:\n{}").format("\n- ".join(m))),
        )
        post.hat = get_hat_from_request(request, post.author)
        post.update = datetime.now()
        post.editor = user
        post.save()

        # Save topic to update update_index_date
        if post.position == 1:
            post.topic.save()

        # If this post is marked as potential spam, we open an alert to notify the staff that
        # the post was edited. If an open alert already exists for this reason, we update the
        # date of this alert to avoid lots of them stacking up.
        if original_text != text and post.is_potential_spam and post.editor == post.author:
            bot = get_object_or_404(
                User, username=settings.ZDS_APP["member"]["bot_account"])
            alert_text = _(
                "Ce message, soupçonné d'être un spam, a été modifié.")

            try:
                alert = post.alerts_on_this_comment.filter(
                    author=bot, text=alert_text, solved=False).latest()
                alert.pubdate = datetime.now()
                alert.save()
            except Alert.DoesNotExist:
                Alert(author=bot,
                      comment=post,
                      scope="FORUM",
                      text=alert_text,
                      pubdate=datetime.now()).save()

        return post
Exemplo n.º 6
0
    def perform_edit_post(request, post, user, text):
        # create an archive
        edit = CommentEdit()
        edit.comment = post
        edit.editor = user
        edit.original_text = post.text
        edit.save()

        post.update_content(text)
        post.hat = get_hat_from_request(request, post.author)
        post.update = datetime.now()
        post.editor = user
        post.save()

        if post.position == 1:
            # Save topic to update update_index_date
            post.topic.save()
        return post