|
10 | 10 |
|
11 | 11 |
|
12 | 12 | def create_notification(event=None, *args, **kwargs): |
13 | | - # System notifications |
14 | | - try: |
15 | | - system_notifications = Notifications.objects.get(user=None) |
16 | | - except Exception: |
17 | | - system_notifications = Notifications() |
18 | | - |
19 | | - logger.debug('creating system notifications') |
20 | | - |
21 | | - # send system notifications to all admin users |
22 | | - admin_users = Dojo_User.objects.filter(is_staff=True) |
23 | | - for admin_user in admin_users: |
24 | | - system_notifications.user = admin_user |
25 | | - process_notifications(event, system_notifications, *args, **kwargs) |
26 | 13 |
|
27 | 14 | if 'recipients' in kwargs: |
28 | | - # mimic existing code so that when recipients is specified, no other personal notifications are sent. |
| 15 | + # mimic existing code so that when recipients is specified, no other system or personal notifications are sent. |
29 | 16 | logger.debug('creating notifications for recipients') |
30 | | - for recipient_notifications in Notifications.objects.filter(user__username__in=kwargs['recipients'], user__is_active=True): |
| 17 | + for recipient_notifications in Notifications.objects.filter(user__username__in=kwargs['recipients'], user__is_active=True, product=None): |
31 | 18 | # kwargs.update({'user': recipient_notifications.user}) |
32 | 19 | process_notifications(event, recipient_notifications, *args, **kwargs) |
33 | 20 | else: |
| 21 | + logger.debug('creating system notifications') |
| 22 | + # send system notifications to all admin users |
| 23 | + |
| 24 | + # System notifications |
| 25 | + try: |
| 26 | + system_notifications = Notifications.objects.get(user=None) |
| 27 | + except Exception: |
| 28 | + system_notifications = Notifications() |
| 29 | + |
| 30 | + admin_users = Dojo_User.objects.filter(is_staff=True) |
| 31 | + for admin_user in admin_users: |
| 32 | + system_notifications.user = admin_user |
| 33 | + process_notifications(event, system_notifications, *args, **kwargs) |
| 34 | + |
34 | 35 | # Personal but global notifications |
35 | 36 | # only retrieve users which have at least one notification type enabled for this event type. |
36 | 37 | logger.debug('creating personal notifications') |
@@ -92,7 +93,7 @@ def process_notifications(event, notifications=None, *args, **kwargs): |
92 | 93 |
|
93 | 94 | sync = 'initiator' in kwargs and hasattr(kwargs['initiator'], 'usercontactinfo') and kwargs['initiator'].usercontactinfo.block_execution |
94 | 95 |
|
95 | | - logger.debug('sync: %s', sync) |
| 96 | + logger.debug('sync: %s %s', sync, notifications.user) |
96 | 97 | logger.debug('sending notifications ' + ('synchronously' if sync else 'asynchronously')) |
97 | 98 | # logger.debug(vars(notifications)) |
98 | 99 |
|
|
0 commit comments