19 from cm.security import get_viewable_comments, has_perm |
19 from cm.security import get_viewable_comments, has_perm |
20 allready_notified = set() # avoid sending multiple notifications to same user |
20 allready_notified = set() # avoid sending multiple notifications to same user |
21 |
21 |
22 activity = kwargs['instance'] |
22 activity = kwargs['instance'] |
23 if activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_users'): # user activity: only viewed by managers |
23 if activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_users'): # user activity: only viewed by managers |
24 notifications = Notification.objects.filter(text=None) |
24 notifications = Notification.objects.filter(text=None, active=True) |
25 for notification in notifications: |
25 for notification in notifications: |
26 if notification.user: |
26 if notification.user: |
27 from cm.security import user_has_perm # import here! |
27 from cm.security import user_has_perm # import here! |
28 if user_has_perm(notification.user, 'can_manage_workspace'): |
28 if user_has_perm(notification.user, 'can_manage_workspace'): |
29 send_notification(activity, notification) |
29 send_notification(activity, notification) |
30 allready_notified.add(notification.user) |
30 allready_notified.add(notification.user) |
31 elif activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_comments'): |
31 elif activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_comments'): |
32 notifications = Notification.objects.filter(Q(text=activity.text) | Q(text=None)) |
32 notifications = Notification.objects.filter(Q(text=activity.text) | Q(text=None), active=True) |
33 for notification in notifications: |
33 for notification in notifications: |
34 viewable = get_viewable_comments(FakeRequest(notification.user), |
34 viewable = get_viewable_comments(FakeRequest(notification.user), |
35 Comment.objects.filter(id__in = [activity.comment.id]), |
35 Comment.objects.filter(id__in = [activity.comment.id]), |
36 text=activity.text) |
36 text=activity.text) |
37 if viewable and \ |
37 if viewable and \ |
39 (notification.type != 'own')): |
39 (notification.type != 'own')): |
40 if not notification.user in allready_notified: |
40 if not notification.user in allready_notified: |
41 send_notification(activity, notification) |
41 send_notification(activity, notification) |
42 allready_notified.add(notification.user) |
42 allready_notified.add(notification.user) |
43 elif activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_texts'): |
43 elif activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_texts'): |
44 notifications = Notification.objects.filter(Q(text=activity.text) | Q(text=None)) |
44 notifications = Notification.objects.filter(Q(text=activity.text) | Q(text=None), active=True) |
45 for notification in notifications: |
45 for notification in notifications: |
46 if notification.user: |
46 if notification.user: |
47 from cm.security import user_has_perm # import here! |
47 from cm.security import user_has_perm # import here! |
48 if user_has_perm(notification.user, 'can_view_text', text=activity.text) and not notification.user in allready_notified: |
48 if user_has_perm(notification.user, 'can_view_text', text=activity.text) and not notification.user in allready_notified: |
49 send_notification(activity, notification) |
49 send_notification(activity, notification) |