def emit_to_user(self, profile, event): alerts_on = get_setting(profile, 'alert_notifications_on', 'true') if not asbool(alerts_on): log.debug('alert notifications are disabled, alert not sent.') return alert = event # flag alerts are treated differently. Just send straight to admin # not the flagged user. if isinstance(alert, FlagAlert): log.info('flag alert received. sending directly to admin only.') self._send_immediately(alert) return def action_pref(pref, alert): if pref == IProfile.ALERT_DIGEST: self._queue_digest(alert, profile) elif pref == IProfile.ALERT_IMMEDIATELY: self._send_immediately(alert) alerts_inbox_on = get_setting(profile, 'alert_notifications_inbox_on', 'false') if not asbool(alerts_inbox_on): log.debug('alert inbox notifications are disabled, alert not sent ' 'to inbox.') else: # preferences not used for inbox, alert always sent self._send_to_inbox(alert, profile) # profile alerts are for content that does not belong to a community # such as profile comments if alert.is_profile_alert: log.debug('profile alert') action_pref(profile.get_alerts_preference('profile'), alert) return community = find_community(event['content']) if community: community_pref = profile.get_alerts_preference(community.__name__) log.debug('alert received for user: %s, alert: %s, in community: ' '%s with pref:%s' % (profile.__name__, str(alert), community.__name__, community_pref)) action_pref(community_pref, alert) return # site preference e.g. for hcd stories action_pref(profile.get_alerts_preference('site'), alert)
def messenger_factory(os=os): # accepts 'os' for unit test purposes """Factory method for creating an instance of IMessenger for use by this application. """ settings = queryUtility(ISettings) # If settings utility not present, we are probably testing and should # suppress sending mail. Can also be set explicitly in environment # variable suppress_messenger = asbool(os.environ.get('SUPPRESS_MESSENGER', '')) if settings is None or suppress_messenger: return FakeMessenger() return Messenger()