Skip to content

Commit

Permalink
Merge 98a80f4 into ffd9d0f
Browse files Browse the repository at this point in the history
  • Loading branch information
GCodeur committed Apr 22, 2017
2 parents ffd9d0f + 98a80f4 commit 31ee970
Show file tree
Hide file tree
Showing 16 changed files with 523 additions and 16 deletions.
4 changes: 4 additions & 0 deletions assets/scss/components/_topic-message.scss
Expand Up @@ -223,6 +223,10 @@
font-style: italic;
color: #999;

& > a {
color: #999;
}

&:after {
opacity: .5;
}
Expand Down
6 changes: 6 additions & 0 deletions templates/forum/topic/index.html
Expand Up @@ -120,6 +120,12 @@
{% set True as answer_schema %}
{% endif %}

{% if user == message.author or is_staff %}
{% set True as can_view_history %}
{% else %}
{% set False as can_view_history %}
{% endif %}

{% include "misc/message.part.html" with answer_schema=answer_schema can_unread=True unread_link=unread_link perms_change=is_staff%}
{% endfor %}

Expand Down
18 changes: 12 additions & 6 deletions templates/misc/message.part.html
Expand Up @@ -188,13 +188,19 @@
</p>
{% elif message.update %}
<p class="message-edited ico-after edit">
{% trans "Édité" %}
{% if message.editor %}
{% trans "par" %} {{ message.editor }}
{% if can_view_history %}
<a href="{% url 'comment-edits-history' message.pk %}">
{% endif %}
{% trans "Édité" %}
{% if message.editor %}
{% trans "par" %} {{ message.editor }}
{% endif %}
<time itemprop="dateModified" datetime="{{ message.update|date:"c" }}">
{{ message.update|format_date }}
</time>
{% if can_view_history %}
</a>
{% endif %}
<time itemprop="dateModified" datetime="{{ message.update|date:"c" }}">
{{ message.update|format_date }}
</time>
</p>
{% endif %}
</div>
Expand Down
69 changes: 69 additions & 0 deletions templates/pages/comment_edits_history.html
@@ -0,0 +1,69 @@
{% extends "pages/base.html" %}
{% load date %}
{% load i18n %}



{% block title %}
{% trans "Historique des éditions du message" %}
{% endblock %}



{% block breadcrumb %}
<li>
<a href="{{ comment.get_absolute_url }}">
{% trans "Message de" %} {{ comment.author.username }}
</a>
</li>
<li>{% trans "Historique des éditions" %}</li>
{% endblock %}



{% block headline %}
<h1>{% trans "Historique des éditions du message" %}</h1>
{% endblock %}



{% block content_page %}
{% if edits %}
<table class="fullwidth">
<thead>
<th>{% trans "Date" %}</th>
<th>{% trans "Éditeur" %}</th>
<th class="wide">{% trans "Version avant édition" %}</th>
</thead>
<tbody>
{% for edit in edits %}
<tr>
<td>{{ edit.date|format_date|capfirst }}</td>
<td>{% include 'misc/member_item.part.html' with member=edit.editor avatar=True %}</td>
<td class="wide">
{% if edit.deleted_by %}
{% trans "Supprimée par" %} {% include 'misc/member_item.part.html' with member=edit.deleted_by avatar=True %} ({{ edit.deleted_at|format_date }})
{% else %}
{% if is_staff %}
<form method="post" action="{% url 'delete-edit-content' edit.pk %}">
{% csrf_token %}
<button type="submit" class="btn btn-grey ico-after red cross">{% trans "Supprimer" %}</button>
</form>
{% endif %}
{% if comment.is_visible %}
<form method="post" action="{% url 'restore-edit' edit.pk %}">
{% csrf_token %}
<button type="submit" class="btn btn-grey ico-after blue history">{% trans "Restaurer" %}</button>
</form>
{% endif %}
<a href="{% url 'edit-detail' edit.pk %}" class="btn btn-grey ico-after hide">{% trans "Voir" %}</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<em>{% trans "Ce message n'a jamais été édité." %}</em>
{% endif %}
{% endblock %}
56 changes: 56 additions & 0 deletions templates/pages/edit_detail.html
@@ -0,0 +1,56 @@
{% extends "pages/base.html" %}
{% load date %}
{% load i18n %}
{% load emarkdown %}



{% block title %}
{% trans "Version avant édition" %} &bull; {% trans "Historique des éditions du message" %}
{% endblock %}



{% block breadcrumb %}
<li>
<a href="{{ comment.get_absolute_url }}">
{% trans "Message de" %} {{ comment.author.username }}
</a>
</li>
<li>
<a href="{% url 'comment-edits-history' comment.pk %}">
{% trans "Historique des éditions" %}
</a>
</li>
<li>
{% trans "Version avant édition" %}
</li>
{% endblock %}



{% block headline %}
<h1>{% trans "Version avant édition" %}</h1>
{% endblock %}



{% block content_page %}
<div class="message-content">
{{ edit.original_text|emarkdown }}
</div>

{% if is_staff %}
<form method="post" action="{% url 'delete-edit-content' edit.pk %}">
{% csrf_token %}
<button type="submit" class="btn btn-grey ico-after red cross">{% trans "Supprimer" %}</button>
</form>
{% endif %}

{% if comment.is_visible %}
<form method="post" action="{% url 'restore-edit' edit.pk %}">
{% csrf_token %}
<button type="submit" class="btn btn-grey ico-after blue history">{% trans "Restaurer" %}</button>
</form>
{% endif %}
{% endblock %}
10 changes: 9 additions & 1 deletion templates/tutorialv2/view/content_online.html
Expand Up @@ -315,6 +315,8 @@ <h3 class="comments-title" id="comments">

{% include "misc/paginator.html" with position="top" topic=content is_online=True anchor="comments" %}

{% set perms.tutorialv2.change_contentreaction as is_staff %}

{% for message in reactions %}

{% captureas edit_link %}
Expand Down Expand Up @@ -349,7 +351,13 @@ <h3 class="comments-title" id="comments">
{% set False as is_repeated_message %}
{% endif %}

{% include "misc/message.part.html" with perms_change=perms.tutorialv2.change_contentreaction topic=object %}
{% if user == message.author or is_staff %}
{% set True as can_view_history %}
{% else %}
{% set False as can_view_history %}
{% endif %}

{% include "misc/message.part.html" with perms_change=is_staff topic=object %}
{% endfor %}


Expand Down
9 changes: 8 additions & 1 deletion zds/forum/commons.py
Expand Up @@ -12,7 +12,7 @@
from zds.forum.models import Forum, Post, TopicRead
from zds.notification import signals
from zds.notification.models import TopicAnswerSubscription, Notification, NewTopicSubscription
from zds.utils.models import Alert
from zds.utils.models import Alert, CommentEdit


class ForumEditMixin(object):
Expand Down Expand Up @@ -163,6 +163,13 @@ def perform_unread_message(post, user):

@staticmethod
def perform_edit_post(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.update = datetime.now()
post.editor = user
Expand Down
27 changes: 27 additions & 0 deletions zds/forum/tests/tests_views.py
Expand Up @@ -9,6 +9,7 @@
from zds.forum.models import Topic, Post
from zds.notification.models import TopicAnswerSubscription
from zds.member.factories import ProfileFactory, StaffProfileFactory
from zds.utils.models import CommentEdit


class CategoriesForumsListViewTests(TestCase):
Expand Down Expand Up @@ -1340,6 +1341,32 @@ def test_failure_edit_post_hidden_message_by_non_staff(self):
response = self.client.get(reverse('topic-edit') + '?topic={}'.format(topic.pk), follow=False)
self.assertEqual(403, response.status_code)

def test_creation_archive_on_edit(self):
profile = ProfileFactory()
category, forum = create_category()
topic = add_topic_in_a_forum(forum, profile)
post_before_edit = Post.objects.get(pk=topic.last_message.pk)

edits_count = CommentEdit.objects.count()

# Edit post
self.assertTrue(self.client.login(username=profile.user.username, password='hostel77'))
data = {
'text': 'A new post!'
}
response = self.client.post(
reverse('post-edit') + '?message={}'.format(topic.last_message.pk), data, follow=False)
self.assertEqual(302, response.status_code)

# Check that an archive was created
self.assertEqual(CommentEdit.objects.count(), edits_count + 1)

# Check the archive content
edit = CommentEdit.objects.latest('date')
self.assertEqual(post_before_edit.pk, edit.comment.pk)
self.assertEqual(post_before_edit.text, edit.original_text)
self.assertEqual(profile.user, edit.editor)


class PostUsefulTest(TestCase):
def test_failure_post_useful_require_method_post(self):
Expand Down
4 changes: 3 additions & 1 deletion zds/member/views.py
Expand Up @@ -40,7 +40,7 @@
from zds.tutorialv2.models.models_database import PublishableContent
from zds.notification.models import TopicAnswerSubscription, NewPublicationSubscription
from zds.tutorialv2.models.models_database import PublishedContent, PickListOperation
from zds.utils.models import Comment, CommentVote, Alert
from zds.utils.models import Comment, CommentVote, Alert, CommentEdit
from zds.utils.mps import send_mp
from zds.utils.paginator import ZdSPagingListView
from zds.utils.tokens import generate_token
Expand Down Expand Up @@ -448,6 +448,8 @@ def unregister(request):
# all messages anonymisation (forum, article and tutorial posts)
Comment.objects.filter(author=current).update(author=anonymous)
PrivatePost.objects.filter(author=current).update(author=anonymous)
CommentEdit.objects.filter(editor=current).update(editor=anonymous)
CommentEdit.objects.filter(deleted_by=current).update(deleted_by=anonymous)
# karma notes, alerts and sanctions anonymisation (to keep them)
KarmaNote.objects.filter(moderator=current).update(moderator=anonymous)
Ban.objects.filter(moderator=current).update(moderator=anonymous)
Expand Down

0 comments on commit 31ee970

Please sign in to comment.