equal
deleted
inserted
replaced
17 |
17 |
18 def notify(sender, **kwargs): |
18 def notify(sender, **kwargs): |
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 #import pdb;pdb.set_trace() |
22 activity = kwargs['instance'] |
23 activity = kwargs['instance'] |
23 if activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_users'): # user activity: only viewed by managers |
24 if activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_users'): # user activity: only viewed by managers |
24 notifications = Notification.objects.filter(text=None, active=True) |
25 notifications = Notification.objects.filter(text=None, active=True).exclude(type='own') |
25 for notification in notifications: |
26 for notification in notifications: |
26 if notification.user: |
27 if notification.user: |
27 from cm.security import user_has_perm # import here! |
28 from cm.security import user_has_perm # import here! |
28 if user_has_perm(notification.user, 'can_manage_workspace'): |
29 if user_has_perm(notification.user, 'can_manage_workspace'): |
29 send_notification(activity, notification) |
30 send_notification(activity, notification) |
39 (notification.type != 'own')): |
40 (notification.type != 'own')): |
40 if not notification.user in allready_notified: |
41 if not notification.user in allready_notified: |
41 send_notification(activity, notification) |
42 send_notification(activity, notification) |
42 allready_notified.add(notification.user) |
43 allready_notified.add(notification.user) |
43 elif activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_texts'): |
44 elif activity.type in Activity.VIEWABLE_ACTIVITIES.get('view_texts'): |
44 notifications = Notification.objects.filter(Q(text=activity.text) | Q(text=None), active=True) |
45 notifications = Notification.objects.filter(Q(text=activity.text) | Q(text=None), active=True).exclude(type='own') |
45 for notification in notifications: |
46 for notification in notifications: |
46 if notification.user: |
47 if notification.user: |
47 from cm.security import user_has_perm # import here! |
48 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: |
49 if user_has_perm(notification.user, 'can_view_text', text=activity.text) and not notification.user in allready_notified: |
49 send_notification(activity, notification) |
50 send_notification(activity, notification) |