Skip to content

Commit

Permalink
feat(BlockedPost): utilisateurs authentifié traqués sur le modèle
Browse files Browse the repository at this point in the history
  • Loading branch information
calummackervoy committed Jun 7, 2024
1 parent 434373c commit deae2d2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lacommunaute/forum_conversation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def clean(self):
if not post.approved:
self.add_error(None, "Votre message ne respecte pas les règles de la communauté.")

if self.user.is_authenticated:
post.poster = self.user

if post.update_reason in BlockedPostReason.reasons_tracked_for_stats():
BlockedPost.create_from_post(post)
return cleaned_data
Expand Down
1 change: 1 addition & 0 deletions lacommunaute/forum_conversation/tests/tests_views_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ def test_create_post_with_nonfr_content(self):

# the blocked post should be recorded in the database
blocked_post = BlockedPost.objects.get()
assert blocked_post.poster == self.user
assert blocked_post.content == "популярные лучшие песни слушать онлайн"
assert blocked_post.block_reason == BlockedPostReason.ALTERNATIVE_LANGUAGE.value

Expand Down
12 changes: 12 additions & 0 deletions lacommunaute/forum_moderation/migrations/0003_blockedpost.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 5.0.6 on 2024-06-07 10:09

from django.conf import settings
from django.db import migrations, models


Expand All @@ -15,6 +16,17 @@ class Migration(migrations.Migration):
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("created", models.DateTimeField(auto_now_add=True, verbose_name="Creation date")),
("updated", models.DateTimeField(auto_now=True, verbose_name="Update date")),
(
"poster",
models.ForeignKey(
blank=True,
null=True,
on_delete=models.deletion.CASCADE,
related_name="blocked_posts",
to=settings.AUTH_USER_MODEL,
verbose_name="Poster",
),
),
("username", models.EmailField(blank=True, max_length=254, null=True, verbose_name="Adresse email")),
("content", models.CharField(verbose_name="Content")),
("block_reason", models.CharField(blank=True, null=True, verbose_name="Block Reason")),
Expand Down
10 changes: 10 additions & 0 deletions lacommunaute/forum_moderation/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
from machina.models.abstract_models import DatedModel
Expand Down Expand Up @@ -35,6 +36,14 @@ class BlockedPost(DatedModel):
It is built of a subset of fields from django-machina's model AbstractPost
"""

poster = models.ForeignKey(
settings.AUTH_USER_MODEL,
related_name="blocked_posts",
blank=True,
null=True,
on_delete=models.CASCADE,
verbose_name=_("Poster"),
)
username = models.EmailField(blank=True, null=True, verbose_name=("Adresse email"))
content = models.CharField(verbose_name=_("Content"))
block_reason = models.CharField(
Expand All @@ -56,6 +65,7 @@ def create_from_post(cls, post):
Creates a BlockedPost object from parameterised Post (machina)
"""
return cls.objects.create(
poster=post.poster,
username=getattr(post, "username", ""),
content=post.content,
block_reason=post.update_reason,
Expand Down
Binary file modified locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
18 changes: 11 additions & 7 deletions locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,26 @@ msgstr "Messages certifié"
msgid "Certified Posts"
msgstr "Message certifié"

#: lacommunaute/forum_conversation/models.py
#: lacommunaute/forum_moderation/models.py
msgid "Content"
msgstr "Contenu"

#: lacommunaute/forum_moderation/models.py
msgid "Blocked Post"
msgstr "Message bloqué"

#: lacommunaute/forum_conversation/models.py
#: lacommunaute/forum_moderation/models.py
msgid "Blocked Posts"
msgstr "Messages bloqués"

#: lacommunaute/forum_conversation/models.py
msgid "Content"
msgstr "Contenu"

#: lacommunaute/forum_conversation/models.py
#: lacommunaute/forum_moderation/models.py
msgid "Block Reason"
msgstr "Motif du blocage"

#: lacommunaute/forum_moderation/models.py
msgid "Poster"
msgstr "Auteur"

#: lacommunaute/search/forms.py:24
msgid "Keywords or phrase"
msgstr "Mots clés ou phrase"
Expand Down

0 comments on commit deae2d2

Please sign in to comment.