mirror of
https://github.com/suitenumerique/docs.git
synced 2026-10-01 22:15:14 +02:00
🐛(backend) skip notification on self mention
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 <boukerfa.ma@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user