feat: make sure owner also gets notified, add test
This commit is contained in:
parent
71ef17dc97
commit
36a979954c
@ -7,7 +7,7 @@ from .mail import send_notification_email
|
|||||||
from .tools.admin import clean_locations, deactivate_unchecked_adoption_notices, deactivate_404_adoption_notices
|
from .tools.admin import clean_locations, deactivate_unchecked_adoption_notices, deactivate_404_adoption_notices
|
||||||
from .tools.misc import healthcheck_ok
|
from .tools.misc import healthcheck_ok
|
||||||
from .models import Location, AdoptionNotice, Timestamp
|
from .models import Location, AdoptionNotice, Timestamp
|
||||||
from .tools.notifications import notify_moderators_of_AN_to_be_checked
|
from .tools.notifications import notify_of_AN_to_be_checked
|
||||||
from .tools.search import notify_search_subscribers
|
from .tools.search import notify_search_subscribers
|
||||||
|
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ def post_adoption_notice_save(pk):
|
|||||||
logging.info(f"Location was added to Adoption notice {pk}")
|
logging.info(f"Location was added to Adoption notice {pk}")
|
||||||
|
|
||||||
notify_search_subscribers(instance, only_if_active=True)
|
notify_search_subscribers(instance, only_if_active=True)
|
||||||
notify_moderators_of_AN_to_be_checked(instance)
|
notify_of_AN_to_be_checked(instance)
|
||||||
|
|
||||||
@celery_app.task(name="tools.healthcheck")
|
@celery_app.task(name="tools.healthcheck")
|
||||||
def task_healthcheck():
|
def task_healthcheck():
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
from fellchensammlung.models import User, AdoptionNoticeNotification, TrustLevel
|
from fellchensammlung.models import User, AdoptionNoticeNotification, TrustLevel
|
||||||
|
|
||||||
|
|
||||||
def notify_moderators_of_AN_to_be_checked(adoption_notice):
|
def notify_of_AN_to_be_checked(adoption_notice):
|
||||||
if adoption_notice.is_disabled_unchecked:
|
if adoption_notice.is_disabled_unchecked:
|
||||||
for moderator in User.objects.filter(trust_level__gt=TrustLevel.MODERATOR):
|
users_to_notify = set(User.objects.filter(trust_level__gt=TrustLevel.MODERATOR))
|
||||||
|
users_to_notify.add(adoption_notice.owner)
|
||||||
|
for user in users_to_notify:
|
||||||
AdoptionNoticeNotification.objects.create(adoption_notice=adoption_notice,
|
AdoptionNoticeNotification.objects.create(adoption_notice=adoption_notice,
|
||||||
user=moderator,
|
user=user,
|
||||||
title=f" Prüfe Vermittlung {adoption_notice}",
|
title=f" Prüfe Vermittlung {adoption_notice}",
|
||||||
text=f"{adoption_notice} muss geprüft werden bevor sie veröffentlicht wird.",
|
text=f"{adoption_notice} muss geprüft werden bevor sie veröffentlicht wird.",
|
||||||
)
|
)
|
34
src/tests/test_tools_notifications.py
Normal file
34
src/tests/test_tools_notifications.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
from model_bakery import baker
|
||||||
|
|
||||||
|
from fellchensammlung.models import User, TrustLevel, Species, Location, AdoptionNotice, AdoptionNoticeNotification
|
||||||
|
from fellchensammlung.tools.notifications import notify_of_AN_to_be_checked
|
||||||
|
|
||||||
|
|
||||||
|
class TestNotifications(TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpTestData(cls):
|
||||||
|
cls.test_user0 = User.objects.create_user(username='testuser0',
|
||||||
|
first_name="Admin",
|
||||||
|
last_name="BOFH",
|
||||||
|
password='12345')
|
||||||
|
|
||||||
|
cls.test_user1 = User.objects.create_user(username='testuser1',
|
||||||
|
first_name="Max",
|
||||||
|
last_name="Müller",
|
||||||
|
password='12345')
|
||||||
|
cls.test_user2 = User.objects.create_user(username='testuser2',
|
||||||
|
first_name="Miriam",
|
||||||
|
last_name="Müller",
|
||||||
|
password='12345')
|
||||||
|
cls.test_user0.trust_level = TrustLevel.ADMIN
|
||||||
|
cls.test_user0.save()
|
||||||
|
|
||||||
|
cls.adoption1 = baker.make(AdoptionNotice, name="TestAdoption1", owner=cls.test_user1,)
|
||||||
|
cls.adoption1.set_unchecked() # Could also emit notification
|
||||||
|
|
||||||
|
def test_notify_of_AN_to_be_checked(self):
|
||||||
|
notify_of_AN_to_be_checked(self.adoption1)
|
||||||
|
self.assertTrue(AdoptionNoticeNotification.objects.filter(user=self.test_user0).exists())
|
||||||
|
self.assertTrue(AdoptionNoticeNotification.objects.filter(user=self.test_user1).exists())
|
||||||
|
self.assertFalse(AdoptionNoticeNotification.objects.filter(user=self.test_user2).exists())
|
Loading…
x
Reference in New Issue
Block a user