Skip to content

Commit

Permalink
Ajoute une option sur le profil pour masquer l'activité sur le forum …
Browse files Browse the repository at this point in the history
…/ les commentaires (#6307)
  • Loading branch information
Migwel authored May 22, 2022
1 parent 1e0aae2 commit 3a3e3bc
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 62 deletions.
124 changes: 64 additions & 60 deletions templates/member/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ <h3>{% trans 'Liens' %}</h3>
</div>
{% endif %}

{% if public_tutos_count > 0 or articles_public_count > 0 or opinions_public_count > 0 or content_reactions_count > 0 %}
{% if public_tutos_count > 0 or articles_public_count > 0 or opinions_public_count > 0 or content_reactions_count > 0 and not hide_forum_activity %}
<div class="linkbox-item primary">
<div class="head">
<h3>{% trans 'Contenus' %}</h3>
Expand Down Expand Up @@ -373,7 +373,7 @@ <h3>{% trans 'Contenus' %}</h3>
</p>
</a>
{% endif %}
{% if content_reactions_count > 0 %}
{% if content_reactions_count > 0 and not hide_forum_activity %}
<a href="{% url "content:list-content-reactions" usr.pk %}" class="tail">
<p>
{% blocktrans count content_reactions_count=content_reactions_count %}
Expand Down Expand Up @@ -458,49 +458,51 @@ <h3>{% trans 'En bêta' %}</h3>
{% endif %}
{% endif %}

{% if topics_count > 0 or messages_count > 0 or followed_topics_count > 0 and profile.user == user %}
<div class="linkbox-item primary">
<div class="head">
<h3>{% trans 'Forum' %}</h3>
</div>
{% if not hide_forum_activity %}
{% if topics_count > 0 or messages_count > 0 or followed_topics_count > 0 and profile.user == user %}
<div class="linkbox-item primary">
<div class="head">
<h3>{% trans 'Forum' %}</h3>
</div>

{% if topics_count > 0 %}
<a href="{% url 'topic-find' usr.pk %}" class="tail">
<p>
{% blocktrans count topics_count=topics_count %}
<span class="bold">{{ topics_count }}</span> sujet créé
{% plural %}
<span class="bold">{{ topics_count }}</span> sujets créés
{% endblocktrans %}
</p>
</a>
{% endif %}
{% if topics_count > 0 %}
<a href="{% url 'topic-find' usr.pk %}" class="tail">
<p>
{% blocktrans count topics_count=topics_count %}
<span class="bold">{{ topics_count }}</span> sujet créé
{% plural %}
<span class="bold">{{ topics_count }}</span> sujets créés
{% endblocktrans %}
</p>
</a>
{% endif %}

{% if followed_topics_count > 0 and profile.user == user %}
<a href="{% url 'followed-topic-find' %}" class="tail">
<p>
{% if followed_topics_count > 0 and profile.user == user %}
<a href="{% url 'followed-topic-find' %}" class="tail">
<p>

{% blocktrans count followed_topics_count=followed_topics_count %}
<span class="bold">{{ followed_topics_count }}</span> sujet suivi
{% plural %}
<span class="bold">{{ followed_topics_count }}</span> sujets suivis
{% endblocktrans %}
</p>
</a>
{% endif %}
{% blocktrans count followed_topics_count=followed_topics_count %}
<span class="bold">{{ followed_topics_count }}</span> sujet suivi
{% plural %}
<span class="bold">{{ followed_topics_count }}</span> sujets suivis
{% endblocktrans %}
</p>
</a>
{% endif %}

{% if messages_count > 0 %}
<a href="{% url 'post-find' usr.pk %}" class="tail">
<p>
{% blocktrans count messages_count=messages_count %}
<span class="bold">{{ messages_count }}</span> message posté
{% plural %}
<span class="bold">{{ messages_count }}</span> messages postés
{% endblocktrans %}
</p>
</a>
{% endif %}
</div>
{% if messages_count > 0 %}
<a href="{% url 'post-find' usr.pk %}" class="tail">
<p>
{% blocktrans count messages_count=messages_count %}
<span class="bold">{{ messages_count }}</span> message posté
{% plural %}
<span class="bold">{{ messages_count }}</span> messages postés
{% endblocktrans %}
</p>
</a>
{% endif %}
</div>
{% endif %}
{% endif %}
</div>
</div>
Expand Down Expand Up @@ -547,25 +549,27 @@ <h2 itemprop="name">
{% endif %}

{% if topics %}
<section>
<h2 itemprop="name">
<span>{% trans 'Derniers sujets créés' %}</span>
<a href="{% url 'topic-find' usr.pk %}" class="btn btn-grey">{% trans 'Voir tout' %}</a>
</h2>

{% if topics %}
<div class="content-item-list">
{% for topic in topics %}
{% include 'forum/includes/topic_item.part.html' %}
{% if forloop.last %}
<span class="fill"></span>
{% endif %}
{% endfor %}
</div>
{% else %}
<p>{% trans "Aucun sujet créé." %}</p>
{% endif %}
</section>
{% if not hide_forum_activity %}
<section>
<h2 itemprop="name">
<span>{% trans 'Derniers sujets créés' %}</span>
<a href="{% url 'topic-find' usr.pk %}" class="btn btn-grey">{% trans 'Voir tout' %}</a>
</h2>

{% if topics %}
<div class="content-item-list">
{% for topic in topics %}
{% include 'forum/includes/topic_item.part.html' %}
{% if forloop.last %}
<span class="fill"></span>
{% endif %}
{% endfor %}
</div>
{% else %}
<p>{% trans "Aucun sujet créé." %}</p>
{% endif %}
</section>
{% endif %}
{% endif %}

{% if perms.member.change_profile and profile.user.is_active %}
Expand Down
5 changes: 5 additions & 0 deletions zds/member/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Meta:
"sign",
"show_email",
"show_sign",
"hide_forum_activity",
"is_hover_enabled",
"allow_temp_visual_changes",
"email_for_answer",
Expand Down Expand Up @@ -133,6 +134,7 @@ class ProfileValidatorSerializer(serializers.ModelSerializer):
date_joined = serializers.DateTimeField(source="user.date_joined", required=False)
permissions = DRYPermissionsField(additional_actions=["ban"])
show_sign = serializers.NullBooleanField(required=False)
hide_forum_activity = serializers.NullBooleanField(required=False)
is_hover_enabled = serializers.NullBooleanField(required=False)
email_for_answer = serializers.NullBooleanField(required=False)

Expand All @@ -150,6 +152,7 @@ class Meta:
"sign",
"show_email",
"show_sign",
"hide_forum_activity",
"is_hover_enabled",
"email_for_answer",
"last_visit",
Expand Down Expand Up @@ -178,6 +181,8 @@ def update(self, instance, validated_data):
instance.show_email = validated_data.get("show_email", instance.show_email)
if validated_data.get("show_sign", instance.show_sign) != instance.show_sign:
instance.show_sign = validated_data.get("show_sign", instance.show_sign)
if validated_data.get("hide_forum_activity", instance.hide_forum_activity) != instance.hide_forum_activity:
instance.hide_forum_activity = validated_data.get("hide_forum_activity", instance.hide_forum_activity)
if validated_data.get("is_hover_enabled", instance.is_hover_enabled) != instance.is_hover_enabled:
instance.is_hover_enabled = validated_data.get("is_hover_enabled", instance.is_hover_enabled)
if validated_data.get("email_for_answer", instance.email_for_answer) != instance.email_for_answer:
Expand Down
17 changes: 17 additions & 0 deletions zds/member/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def test_detail_of_the_member(self):
self.assertEqual(profile.sign, response.data.get("sign"))
self.assertFalse(response.data.get("show_email"))
self.assertEqual(profile.show_sign, response.data.get("show_sign"))
self.assertEqual(profile.hide_forum_activity, response.data.get("hide_forum_activity"))
self.assertEqual(profile.is_hover_enabled, response.data.get("is_hover_enabled"))
self.assertEqual(profile.allow_temp_visual_changes, response.data.get("allow_temp_visual_changes"))
self.assertEqual(profile.email_for_answer, response.data.get("email_for_answer"))
Expand Down Expand Up @@ -425,6 +426,7 @@ def test_detail_of_a_member(self):
self.assertEqual(self.profile.sign, response.data.get("sign"))
self.assertFalse(response.data.get("show_email"))
self.assertEqual(self.profile.show_sign, response.data.get("show_sign"))
self.assertEqual(self.profile.hide_forum_activity, response.data.get("hide_forum_activity"))
self.assertEqual(self.profile.is_hover_enabled, response.data.get("is_hover_enabled"))
self.assertEqual(self.profile.email_for_answer, response.data.get("email_for_answer"))

Expand Down Expand Up @@ -485,6 +487,7 @@ def test_update_member_details_without_any_change(self):
self.assertEqual(self.profile.sign, response.data.get("sign"))
self.assertFalse(response.data.get("show_email"))
self.assertEqual(self.profile.show_sign, response.data.get("show_sign"))
self.assertEqual(self.profile.hide_forum_activity, response.data.get("hide_forum_activity"))
self.assertEqual(self.profile.is_hover_enabled, response.data.get("is_hover_enabled"))
self.assertEqual(self.profile.email_for_answer, response.data.get("email_for_answer"))

Expand Down Expand Up @@ -614,6 +617,20 @@ def test_update_member_details_show_sign(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data.get("show_sign"), data.get("show_sign"))

def test_update_member_details_hide_forum_activity(self):
"""
Updates Hide Comment Activity of a given member.
"""
data = {"hide_forum_activity": True}
response = self.client_authenticated.put(reverse("api:member:detail", args=[self.profile.user.id]), data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data.get("hide_forum_activity"), data.get("hide_forum_activity"))

data = {"hide_forum_activity": False}
response = self.client_authenticated.put(reverse("api:member:detail", args=[self.profile.user.id]), data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data.get("hide_forum_activity"), data.get("hide_forum_activity"))

def test_update_member_details_is_hover_enabled(self):
"""
Updates hover or click of a member given.
Expand Down
10 changes: 10 additions & 0 deletions zds/member/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ class ProfileForm(MiniProfileForm):
("show_markdown_help", _("Afficher l'aide Markdown dans l'éditeur")),
("email_for_answer", _("Recevoir un courriel lors d'une réponse à un message privé")),
("email_for_new_mp", _("Recevoir un courriel lors de la réception d'un nouveau message privé")),
(
"hide_forum_activity",
_(
"Masquer mes activités de forum et commentaires sur mon profil "
"(sauf pour moi et l'équipe de modération)"
),
),
]

options = forms.MultipleChoiceField(
Expand Down Expand Up @@ -272,6 +279,9 @@ def __init__(self, *args, **kwargs):
if "email_for_new_mp" in initial and initial["email_for_new_mp"]:
self.fields["options"].initial += "email_for_new_mp"

if "hide_forum_activity" in initial and initial["hide_forum_activity"]:
self.fields["options"].initial += "hide_forum_activity"

layout = Layout(
IncludeEasyMDE(),
Field("biography"),
Expand Down
4 changes: 2 additions & 2 deletions zds/member/migrations/0019_profile_username_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

from django.db import migrations, models

from zds.member.models import Profile


def init_skeleton(apps, schema_editor):
Profile = apps.get_model("member", "Profile")
profiles = Profile.objects.all()
for profile in profiles:
profile.username_skeleton = Profile.find_username_skeleton(profile.user.username)
profile.save()


def remove_skeleton(apps, schema_editor):
Profile = apps.get_model("member", "Profile")
profiles = Profile.objects.all()
for profile in profiles:
profile.username_skeleton = None
Expand Down
20 changes: 20 additions & 0 deletions zds/member/migrations/0022_add_hide_forum_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.12 on 2022-04-05 17:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("member", "0021_remove_profile_use_old_smileys"),
]

operations = [
migrations.AddField(
model_name="profile",
name="hide_forum_activity",
field=models.BooleanField(
default=False, verbose_name="Masquer l'activité de forum et les commentaires sur la page de profil"
),
),
]
3 changes: 3 additions & 0 deletions zds/member/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class Meta:
)
github_token = models.TextField("GitHub", blank=True)
show_sign = models.BooleanField("Voir les signatures", default=True)
hide_forum_activity = models.BooleanField(
"Masquer l'activité de forum et les commentaires sur la page de profil", default=False
)
# do UI components open by hovering them, or is clicking on them required?
is_hover_enabled = models.BooleanField("Déroulement au survol ?", default=False)
allow_temp_visual_changes = models.BooleanField("Activer les changements visuels temporaires", default=True)
Expand Down
7 changes: 7 additions & 0 deletions zds/member/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ def get_context_data(self, **kwargs):
.count()
)
context["content_reactions_count"] = ContentReaction.objects.filter(author=usr).count()
context["hide_forum_activity"] = (
profile.hide_forum_activity
and not self.request.user.has_perm("member.change_profile")
and not profile.user == self.request.user
)

if self.request.user.has_perm("member.change_profile"):
sanctions = list(Ban.objects.filter(user=usr).select_related("moderator"))
Expand Down Expand Up @@ -213,6 +218,7 @@ def get_form(self, form_class=ProfileForm):
"site": profile.site,
"avatar_url": profile.avatar_url,
"show_sign": profile.show_sign,
"hide_forum_activity": profile.hide_forum_activity,
"is_hover_enabled": profile.is_hover_enabled,
"allow_temp_visual_changes": profile.allow_temp_visual_changes,
"show_markdown_help": profile.show_markdown_help,
Expand Down Expand Up @@ -255,6 +261,7 @@ def update_profile(self, profile, form):
profile.show_markdown_help = "show_markdown_help" in cleaned_data_options
profile.email_for_answer = "email_for_answer" in cleaned_data_options
profile.email_for_new_mp = "email_for_new_mp" in cleaned_data_options
profile.hide_forum_activity = "hide_forum_activity" in cleaned_data_options
profile.avatar_url = form.data["avatar_url"]
profile.sign = form.data["sign"]
profile.licence = form.cleaned_data["licence"]
Expand Down

0 comments on commit 3a3e3bc

Please sign in to comment.