def test_get_by_notification(self): w = CQDEWatchlistStore() w.watch_project(32, 23, "immediate") w.watch_project(34, 23, "daily") watchlist = w.get_by_notification("daily") self.assertTrue(len(watchlist) == 1) self.assertTrue(watchlist[0].user_id == 34) watchlist = w.get_by_notification("weekly") self.assertTrue(len(watchlist) == 0)
def test_get_by_notification(self): w = CQDEWatchlistStore() w.watch_project(32, 23, "immediate") w.watch_project(34, 23, "daily") watchlist = w.get_by_notification("daily") self.assertTrue(len(watchlist) == 1) self.assertTrue(watchlist[0].user_id == 34) watchlist = w.get_by_notification("weekly") self.assertTrue(len(watchlist) == 0)
def notify_now(self, notification_frequency): """ Send notification email to project watchers. :param str notification_frequency: The notification frequency, used to fetch users which have something on that watchlist. """ store = CQDEWatchlistStore() watches = store.get_by_notification(notification_frequency) notifylist = {} for w in watches: if notifylist.get(w.project_id) is None: notifylist[w.project_id] = [] notifylist[w.project_id].append(w.user_id) userstore = get_userstore() counter = 0 for project_id in notifylist.keys(): project = Project.get(id=project_id) # Get all events for this project events = self._get_project_events(project, notification_frequency) # Send one email per user, because everyone may have a different # set of permissions (i.e. which events he/she has permission to see) for user_id in notifylist[project_id]: user = userstore.getUserWhereId(user_id) if user: # filter eventlist by user's permissions filtered_events = WatchlistEvents(self.env).filter_events( events, user, project) if filtered_events: addresses = [user.mail] message = self._format_message(user, project, filtered_events) title = "Project updated: %s" % project.env_name mail = EmailNotifier(self.env, subject=title, data={'body': message}) mail.notify_emails(addresses) self.env.log.debug('Sent email notification to: %s' % user) counter += 1 else: if notification_frequency != 'immediate': self.env.log.debug( 'No events to sent to %s about %s' % (user, project)) else: self.env.log.warning( 'User %d in notification list was not found in userstore' % user_id) # Log the results self.env.log.info('Sent %s watchlist notifications (%s)' % (counter, notification_frequency))
def notify_now(self, notification_frequency): """ Send notification email to project watchers. :param str notification_frequency: The notification frequency, used to fetch users which have something on that watchlist. """ store = CQDEWatchlistStore() watches = store.get_by_notification(notification_frequency) notifylist = {} for w in watches: if notifylist.get(w.project_id) is None: notifylist[w.project_id] = [] notifylist[w.project_id].append(w.user_id) userstore = get_userstore() counter = 0 for project_id in notifylist.keys(): project = Project.get(id=project_id) # Get all events for this project events = self._get_project_events(project, notification_frequency) # Send one email per user, because everyone may have a different # set of permissions (i.e. which events he/she has permission to see) for user_id in notifylist[project_id]: user = userstore.getUserWhereId(user_id) if user: # filter eventlist by user's permissions filtered_events = WatchlistEvents(self.env).filter_events(events, user, project) if filtered_events: addresses = [user.mail] message = self._format_message(user, project, filtered_events) title = "Project updated: %s" % project.env_name mail = EmailNotifier(self.env, subject=title, data={'body':message}) mail.notify_emails(addresses) self.env.log.debug('Sent email notification to: %s' % user) counter += 1 else: if notification_frequency != 'immediate': self.env.log.debug('No events to sent to %s about %s' % (user, project)) else: self.env.log.warning('User %d in notification list was not found in userstore' % user_id) # Log the results self.env.log.info('Sent %s watchlist notifications (%s)' % (counter, notification_frequency))