From 1fe52db89440ab53cedbca16faa47fbed860af1a Mon Sep 17 00:00:00 2001 From: BOUKERFA Mohamed El Amine Date: Tue, 15 Sep 2026 19:29:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(backend)=20skip=20notification=20o?= =?UTF-8?q?n=20self=20mention?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users mentioning themselves got an email about something they just did, which is noise. Keep recording the mention, skip the email. Signed-off-by: BOUKERFA Mohamed El Amine --- src/backend/core/models.py | 4 ++++ .../documents/test_api_documents_mention.py | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/backend/core/models.py b/src/backend/core/models.py index 5b9867e82..78636e09e 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -2058,6 +2058,10 @@ class Mention(BaseModel): Set `notified_at` on the mention and return True if an email was sent, return False otherwise. """ + + if self.mentioned_user_id == self.mentioned_by_user_id: + return False + user = self.mentioned_user if user is None or not user.email or self.is_notification_in_cooldown(): return False diff --git a/src/backend/core/tests/documents/test_api_documents_mention.py b/src/backend/core/tests/documents/test_api_documents_mention.py index b57c38d95..81e42820b 100644 --- a/src/backend/core/tests/documents/test_api_documents_mention.py +++ b/src/backend/core/tests/documents/test_api_documents_mention.py @@ -606,6 +606,27 @@ def test_api_documents_mention_cooldown_only_considers_notified_mentions(): assert len(mail.outbox) == 1 +def test_api_documents_mention_self(): + """ + Users mentioning themselves should get the mention recorded without + being notified. + """ + user = factories.UserFactory() + document = factories.DocumentFactory() + factories.UserDocumentAccessFactory(document=document, user=user, role="commenter") + + client = APIClient() + client.force_login(user) + response = client.post( + f"/api/v1.0/documents/{document.id!s}/mention/", + {"anchor_id": str(uuid4()), "mentioned_user_id": str(user.id)}, + ) + + assert response.status_code == 201 + assert models.Mention.objects.get().notified_at is None + assert len(mail.outbox) == 0 + + def test_api_documents_mention_soft_deleted_document(): """Mentions should not be allowed on soft deleted documents.""" user = factories.UserFactory()