2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 19:50:59 +00:00

Fix email notification setting (#3832)

* Coerce setting value to a boolean

* Ignore inactive users when sending notification emails

* Only send UI notifications to active users

* Fixes for unit tests
This commit is contained in:
Oliver
2022-10-22 18:56:38 +11:00
committed by GitHub
parent c120de90ae
commit a898ebce40
6 changed files with 24 additions and 9 deletions

View File

@ -243,8 +243,9 @@ class UIMessageNotification(SingleNotificationMethod):
METHOD_NAME = 'ui_message'
def get_targets(self):
"""Just return the targets - no tricks here."""
return self.targets
"""Only send notifications for active users"""
return [target for target in self.targets if target.is_active]
def send(self, target):
"""Send a UI notification to a user."""

View File

@ -778,7 +778,8 @@ class NotificationTest(InvenTreeAPITestCase):
messages = NotificationMessage.objects.all()
# As there are three staff users (including the 'test' user) we expect 30 notifications
self.assertEqual(messages.count(), 30)
# However, one user is marked as i nactive
self.assertEqual(messages.count(), 20)
# Only 10 messages related to *this* user
my_notifications = messages.filter(user=self.user)
@ -822,7 +823,7 @@ class NotificationTest(InvenTreeAPITestCase):
# Only 7 notifications should have been deleted,
# as the notifications associated with other users must remain untouched
self.assertEqual(NotificationMessage.objects.count(), 23)
self.assertEqual(NotificationMessage.objects.count(), 13)
self.assertEqual(NotificationMessage.objects.filter(user=self.user).count(), 3)