Skip to content

Commit 51cadfd

Browse files
mentioning a user: fix notifications (#2565)
1 parent 17288ab commit 51cadfd

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

dojo/notifications/helper.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,28 @@
1010

1111

1212
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)
2613

2714
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.
2916
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):
3118
# kwargs.update({'user': recipient_notifications.user})
3219
process_notifications(event, recipient_notifications, *args, **kwargs)
3320
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+
3435
# Personal but global notifications
3536
# only retrieve users which have at least one notification type enabled for this event type.
3637
logger.debug('creating personal notifications')
@@ -92,7 +93,7 @@ def process_notifications(event, notifications=None, *args, **kwargs):
9293

9394
sync = 'initiator' in kwargs and hasattr(kwargs['initiator'], 'usercontactinfo') and kwargs['initiator'].usercontactinfo.block_execution
9495

95-
logger.debug('sync: %s', sync)
96+
logger.debug('sync: %s %s', sync, notifications.user)
9697
logger.debug('sending notifications ' + ('synchronously' if sync else 'asynchronously'))
9798
# logger.debug(vars(notifications))
9899

dojo/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,21 +1638,24 @@ def send_review_email(request, user, finding, users, new_note):
16381638

16391639
def process_notifications(request, note, parent_url, parent_title):
16401640
regex = re.compile(r'(?:\A|\s)@(\w+)\b')
1641+
16411642
usernames_to_check = set([un.lower() for un in regex.findall(note.entry)])
1643+
16421644
users_to_notify = [
16431645
User.objects.filter(username=username).get()
16441646
for username in usernames_to_check
16451647
if User.objects.filter(is_active=True, username=username).exists()
16461648
] # is_staff also?
1647-
user_posting = request.user
1649+
16481650
if len(note.entry) > 200:
16491651
note.entry = note.entry[:200]
16501652
note.entry += "..."
1653+
16511654
create_notification(
16521655
event='user_mentioned',
16531656
section=parent_title,
16541657
note=note,
1655-
user=request.user,
1658+
initiator=request.user,
16561659
title='%s jotted a note' % request.user,
16571660
url=parent_url,
16581661
icon='commenting',

0 commit comments

Comments
 (0)