Skip to content

Commit

Permalink
Merge branch 'dev' into passez_votre_chemin_refacto_urls_en_cours_4
Browse files Browse the repository at this point in the history
  • Loading branch information
philippemilink authored Jul 14, 2022
2 parents 6a83d67 + 7c61904 commit 0aa5fd5
Show file tree
Hide file tree
Showing 30 changed files with 553 additions and 301 deletions.
6 changes: 6 additions & 0 deletions assets/scss/components/_topic-message.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ div.msg-are-hidden {
}
}

&:target {
/* Force l'affichage des messages masqués s'ils sont la cible d'une ancre (par exemple en venant via une notification) */
display: block !important;
visibility: visible !important;
}

.user {
@include until-desktop {
display: none;
Expand Down
6 changes: 3 additions & 3 deletions templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
<div class="notifs-links">
{# MESSAGERIE PRIVEE #}
<div>
<a href="{% url "mp-list" %}" class="ico-link" title="{% trans 'Messagerie privée' %}">
<a href="{% url "mp:list" %}" class="ico-link" title="{% trans 'Messagerie privée' %}">
{% if header_private_topic_notifications.total > 0 %}
<span class="notif-count">{{ header_private_topic_notifications.total }}</span>
{% endif %}
Expand All @@ -229,7 +229,7 @@
<div class="header-dropdown">
<span class="dropdown-title dropdown-pm">
<h1>{% trans "Messagerie privée" %}</h1>
<a href="{% url "mp-new" %}" class="ico-after pm-new white" title="{% trans 'Envoyer un nouveau message privé' %}"></a>
<a href="{% url "mp:create" %}" class="ico-after pm-new white" title="{% trans 'Envoyer un nouveau message privé' %}"></a>
</span>

<ul class="dropdown-list">
Expand All @@ -252,7 +252,7 @@ <h1>{% trans "Messagerie privée" %}</h1>
</li>
{% endif %}
</ul>
<a href="{% url "mp-list" %}" class="dropdown-link-all">
<a href="{% url "mp:list" %}" class="dropdown-link-all">
{% trans "Toutes les conversations" %}
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/member/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ <h1>
</a>
{% endif %}
{% if usr != user and not profile.is_private and profile.can_read_now %}
<a href="{% url 'mp-new' %}?username={{ usr.username }}" class="btn-ico btn ico-after cite light">
<a href="{% url "mp:create" %}?username={{ usr.username }}" class="btn-ico btn ico-after cite light">
{% trans "Envoyer un message" %}
</a>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion templates/member/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h3>{% trans "Actions" %}</h3>
<ul>
{% if usr != user and not profile.is_private and profile.can_read_now %}
<li>
<a href="{% url 'mp-new' %}?username={{ usr.username }}" class="ico-after cite blue">
<a href="{% url "mp:create" %}?username={{ usr.username }}" class="ico-after cite blue">
{% trans "Envoyer un message privé" %}
</a>
</li>
Expand Down
4 changes: 2 additions & 2 deletions templates/mp/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@


{% block breadcrumb_base %}
<li><a href="{% url "mp-list" %}">{% trans "Messagerie privée" %}</a></li>
<li><a href="{% url "mp:list" %}">{% trans "Messagerie privée" %}</a></li>
{% endblock %}



{% block sidebar %}
<aside class="sidebar mobile-menu-hide">
<a href="{% url 'mp-new' %}" class="new-btn ico-after more blue">
<a href="{% url "mp:create" %}" class="new-btn ico-after more blue">
{% trans "Nouvelle conversation" %}
</a>
{% block sidebar_actions %}{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion templates/mp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h3>{% trans "Actions" %}</h3>
{% trans "Supprimer les conversations sélectionnées" %}
</a>

<form action="{% url "mp-list-delete" %}" method="post" id="delete-conversations" class="modal modal-flex">
<form action="{% url "mp:list-delete" %}" method="post" id="delete-conversations" class="modal modal-flex">
<p>
{% trans "Attention, vous vous apprêtez à supprimer toutes les conversations sélectionnées" %}.
</p>
Expand Down
2 changes: 1 addition & 1 deletion templates/mp/post/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h3>{% trans "Actions" %}</h3>
<ul>
<li>
<a href="#add-participant" class="open-modal">{% trans "Ajouter un membre" %}</a>
<form action="{% url "mp-edit-participant" topic.pk topic.slug %}" method="post" id="add-participant" class="modal modal-flex">
<form action="{% url "mp:edit-participant" topic.pk topic.slug %}" method="post" id="add-participant" class="modal modal-flex">
<p>
{% trans "Vous allez rajouter un nouveau membre dans la conversation privée" %}.
</p>
Expand Down
6 changes: 3 additions & 3 deletions templates/mp/post/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{% endif %}

{% captureas form_action %}
{% url "private-posts-new" topic.pk topic.slug %}
{% url "mp:answer" topic.pk topic.slug %}
{% endcaptureas %}

{% include "misc/message_form.html" with member=user text=form.text.value %}
Expand All @@ -55,11 +55,11 @@
<div class="content-wrapper">
{% for message in posts %}
{% captureas edit_link %}
{% url "private-posts-edit" topic.pk topic.slug message.pk %}
{% url "mp:post-edit" message.pk %}
{% endcaptureas %}

{% captureas cite_link %}
{% url "private-posts-new" topic.pk topic.slug %}?cite={{ message.pk }}
{% url "mp:answer" topic.pk topic.slug %}?cite={{ message.pk }}
{% endcaptureas %}

{% include "misc/message.part.html" with can_hide=False is_mp=True %}
Expand Down
14 changes: 7 additions & 7 deletions templates/mp/topic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
{% for message in posts %}
{% if not topic.one_participant_remaining %}
{% captureas edit_link %}
{% url "private-posts-edit" topic.pk topic.slug message.pk %}
{% url "mp:post-edit" message.pk %}
{% endcaptureas %}

{% captureas cite_link %}
{% url "private-posts-new" topic.pk topic.slug %}?cite={{ message.pk }}
{% url "mp:answer" topic.pk topic.slug %}?cite={{ message.pk }}
{% endcaptureas %}
{% endif %}

Expand All @@ -73,7 +73,7 @@
{% endcaptureas %}

{% captureas unread_link %}
{% url "private-post-unread" %}?message={{ message.pk }}
{% url "mp:mark-post-unread" message.pk %}
{% endcaptureas %}

{% if forloop.first and page_obj.number > 1 %}
Expand All @@ -98,7 +98,7 @@


{% captureas form_action %}
{% url "private-posts-new" topic.pk topic.slug %}
{% url "mp:answer" topic.pk topic.slug %}
{% endcaptureas %}

{% include "misc/message_form.html" with member=user %}
Expand All @@ -115,7 +115,7 @@ <h3>{% trans "Actions" %}</h3>
<a href="#add-participant" class="open-modal ico-after more blue">
{% trans "Ajouter un membre" %}
</a>
<form action="{% url "mp-edit-participant" topic.pk topic.slug %}" method="post" id="add-participant" class="modal modal-flex">
<form action="{% url "mp:edit-participant" topic.pk topic.slug %}" method="post" id="add-participant" class="modal modal-flex">
<p>
{% trans "Vous allez rajouter un nouveau membre dans la conversation privée." %}
</p>
Expand All @@ -132,7 +132,7 @@ <h3>{% trans "Actions" %}</h3>
</li>

<li>
<a href="{% url "mp-edit-topic" topic.pk topic.slug %}" class="ico-after edit blue">
<a href="{% url "mp:edit" topic.pk topic.slug %}" class="ico-after edit blue">
{% trans "Éditer la conversation" %}
</a>
</li>
Expand All @@ -142,7 +142,7 @@ <h3>{% trans "Actions" %}</h3>
<a href="#leave-conversation" class="open-modal ico-after cross blue">
{% trans "Quitter la conversation" %}
</a>
<form action="{% url "mp-delete" topic.pk topic.slug %}" method="post" id="leave-conversation" class="modal modal-flex">
<form action="{% url "mp:leave" topic.pk topic.slug %}" method="post" id="leave-conversation" class="modal modal-flex">
<p>
{% trans "Attention, vous vous apprêtez à quitter définitivement cette conversation." %}
</p>
Expand Down
2 changes: 1 addition & 1 deletion templates/tutorialv2/view/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ <h3>{{ content.is_opinion|yesno:_("Modération,Validation") }}</h3>
</li>
{% endif %}
<li>
<a href="{% url 'mp-new' %}?{% for username in content.authors.all %}&amp;username={{ username }}{% endfor %}"
<a href="{% url "mp:create" %}?{% for username in content.authors.all %}&amp;username={{ username }}{% endfor %}"
class="ico-after cite blue"
>
{% trans "Envoyer un MP" %}
Expand Down
11 changes: 6 additions & 5 deletions zds/forum/feeds.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.contrib.syndication.views import Feed

from django.utils.feedgenerator import Atom1Feed
from django.conf import settings
from django.utils.timezone import make_aware
from pytz import AmbiguousTimeError, NonExistentTimeError

from zds.utils.feeds import DropControlCharsRss201rev2Feed, DropControlCharsAtom1Feed
from .models import Post, Topic


Expand Down Expand Up @@ -40,7 +39,8 @@ def request_object(request):
class LastPostsFeedRSS(Feed, ItemMixin):
title = "Derniers messages sur {}".format(settings.ZDS_APP["site"]["literal_name"])
link = "/forums/"
description = "Les derniers messages " "parus sur le forum de {}.".format(settings.ZDS_APP["site"]["literal_name"])
description = "Les derniers messages parus sur le forum de {}.".format(settings.ZDS_APP["site"]["literal_name"])
feed_type = DropControlCharsRss201rev2Feed

def get_object(self, request):
return request_object(request)
Expand All @@ -65,14 +65,15 @@ def item_description(self, item):


class LastPostsFeedATOM(LastPostsFeedRSS):
feed_type = Atom1Feed
feed_type = DropControlCharsAtom1Feed
subtitle = LastPostsFeedRSS.description


class LastTopicsFeedRSS(Feed, ItemMixin):
title = "Derniers sujets sur {}".format(settings.ZDS_APP["site"]["literal_name"])
link = "/forums/"
description = "Les derniers sujets créés sur le forum de {}.".format(settings.ZDS_APP["site"]["literal_name"])
feed_type = DropControlCharsRss201rev2Feed

def get_object(self, request):
return request_object(request)
Expand All @@ -97,5 +98,5 @@ def item_description(self, item):


class LastTopicsFeedATOM(LastTopicsFeedRSS):
feed_type = Atom1Feed
feed_type = DropControlCharsAtom1Feed
subtitle = LastTopicsFeedRSS.description
49 changes: 43 additions & 6 deletions zds/forum/tests/tests_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from zds.member.tests.factories import ProfileFactory


class LastTopicsFeedRSSTest(TestCase):
class LastTopicsFeedTest(TestCase):
def setUp(self):
# prepare a user and 2 Topic (with and without tags)

Expand All @@ -35,7 +35,7 @@ def test_is_well_setup(self):
self.assertEqual(self.topicfeed.link, "/forums/")
reftitle = "Derniers sujets sur {}".format(settings.ZDS_APP["site"]["literal_name"])
self.assertEqual(self.topicfeed.title, reftitle)
refdescription = "Les derniers sujets créés " "sur le forum de {}.".format(
refdescription = "Les derniers sujets créés sur le forum de {}.".format(
settings.ZDS_APP["site"]["literal_name"]
)
self.assertEqual(self.topicfeed.description, refdescription)
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_items_success(self):
def test_items_bad_cases(self):
"""test that right items are sent back according to obj"""

# test empty values, return value shoulb be empty
# test empty values, return value should be empty
obj = {"forum": -1, "tag": -1}
topics = self.topicfeed.items(obj=obj)
self.assertEqual(len(topics), 0)
Expand Down Expand Up @@ -139,8 +139,26 @@ def test_get_item_link(self):
ret = self.topicfeed.item_link(item=topics[0])
self.assertEqual(ret, ref)

def test_content_control_chars(self):
"""
Test 'control characters' in content of the feed doesn't break it.
The '\u0007' character in the post content belongs to a character
family that is not supported in RSS or Atom feeds and will break their
generation.
"""
buggy_topic = TopicFactory(forum=self.forum2, author=self.user)
buggy_topic.title = "Strange char: \u0007"
buggy_topic.save()

request = self.client.get(reverse("topic-feed-rss"))
self.assertEqual(request.status_code, 200)

request = self.client.get(reverse("topic-feed-atom"))
self.assertEqual(request.status_code, 200)


class LastPostFeedTest(TestCase):
class LastPostsFeedTest(TestCase):
def setUp(self):
# prepare a user and 2 Topic (with and without tags)

Expand All @@ -160,7 +178,7 @@ def setUp(self):
self.topic2.tags.add(self.tag)
self.topic2.save()

# create 2 posts un each forum
# create 2 posts in each forum
PostFactory(topic=self.topic1, author=self.user, position=1)
PostFactory(topic=self.topic1, author=self.user, position=2)
PostFactory(topic=self.topic2, author=self.user, position=1)
Expand All @@ -181,7 +199,7 @@ def test_is_well_setup(self):
self.assertEqual(self.postfeed.link, "/forums/")
reftitle = "Derniers messages sur {}".format(settings.ZDS_APP["site"]["literal_name"])
self.assertEqual(self.postfeed.title, reftitle)
refdescription = "Les derniers messages " "parus sur le forum de {}.".format(
refdescription = "Les derniers messages parus sur le forum de {}.".format(
settings.ZDS_APP["site"]["literal_name"]
)
self.assertEqual(self.postfeed.description, refdescription)
Expand Down Expand Up @@ -284,3 +302,22 @@ def test_get_item_link(self):
posts = self.postfeed.items(obj={"tag": self.tag2.pk})
ret = self.postfeed.item_link(item=posts[0])
self.assertEqual(ret, ref)

def test_content_control_chars(self):
"""
Test 'control characters' in content of the feed doesn't break it.
The '\u0007' character in the post content belongs to a character
family that is not supported in RSS or Atom feeds and will break their
generation.
"""
buggy_topic = TopicFactory(forum=self.forum2, author=self.user)
post = PostFactory(topic=buggy_topic, author=self.user, position=1)
post.update_content("Strange char: \u0007")
post.save()

request = self.client.get(reverse("post-feed-rss"))
self.assertEqual(request.status_code, 200)

request = self.client.get(reverse("post-feed-atom"))
self.assertEqual(request.status_code, 200)
45 changes: 0 additions & 45 deletions zds/mp/commons.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from datetime import datetime

from django.views.generic.detail import SingleObjectMixin
from django.http import Http404
from django.shortcuts import get_object_or_404

from zds.mp.models import PrivateTopicRead, PrivatePost
from zds.utils.templatetags.emarkdown import emarkdown
from zds.mp import signals


class LeavePrivateTopic:
Expand Down Expand Up @@ -37,42 +31,3 @@ def perform_update(self, instance, data, hat=None):
instance.update = datetime.now()
instance.save()
return instance

@staticmethod
def perform_unread_private_post(post, user):
"""
Mark the private post as unread. If it is in first position, the whole topic is marked as unread.
"""
# mark the previous post as read
try:
previous_post = PrivatePost.objects.get(
privatetopic=post.privatetopic, position_in_topic=post.position_in_topic - 1
)
# update the record, if it exists
try:
topic = PrivateTopicRead.objects.get(privatetopic=post.privatetopic, user=user)
topic.privatepost = previous_post
# no existing record to update, create a new record
except PrivateTopicRead.DoesNotExist:
topic = PrivateTopicRead(privatepost=previous_post, privatetopic=post.privatetopic, user=user)
topic.save()
# no previous post to mark as read, remove the topic from read list instead
except PrivatePost.DoesNotExist:
try:
topic = PrivateTopicRead.objects.get(privatetopic=post.privatetopic, user=user)
topic.delete()
except PrivateTopicRead.DoesNotExist: # record already removed, nothing to do
pass

signals.message_unread.send(sender=post.privatetopic.__class__, instance=post, user=user)


class SinglePrivatePostObjectMixin(SingleObjectMixin):
object = None

def get_object(self, queryset=None):
try:
post_pk = int(self.request.GET.get("message"))
except (KeyError, ValueError, TypeError):
raise Http404
return get_object_or_404(PrivatePost, pk=post_pk)
2 changes: 1 addition & 1 deletion zds/mp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class PrivatePostForm(forms.Form):
def __init__(self, topic, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_action = reverse("private-posts-new", args=[topic.pk, topic.slug()])
self.helper.form_action = reverse("mp:answer", args=[topic.pk, topic.slug()])
self.helper.form_method = "post"

self.helper.layout = Layout(
Expand Down
Loading

0 comments on commit 0aa5fd5

Please sign in to comment.