def InitFromObj_(self, notification_type, reference, message=None): self.CreateUser(self.token.username) notification.Notify(self.token.username, notification_type, message or "", reference) ns = self.GetUserNotifications(self.token.username) if data_store.RelationalDBReadEnabled(): # Treat the notification as an object coming from REL_DB. return user_plugin.ApiNotification().InitFromUserNotification(ns[0]) else: # Treat the notification as an old-style notification object. return user_plugin.ApiNotification().InitFromNotification(ns[0])
def testUnknownNotificationIsParsedCorrectly(self): n = user_plugin.ApiNotification().InitFromNotification( rdf_flows.Notification(type="ViewObject", subject=self.client_id.Add("foo/bar"))) self.assertEqual(n.reference.type, "UNKNOWN") self.assertEqual(n.reference.unknown.subject_urn, self.client_id.Add("foo/bar")) n = user_plugin.ApiNotification().InitFromNotification( rdf_flows.Notification(type="FlowStatus", subject="foo/bar")) self.assertEqual(n.reference.type, "UNKNOWN") self.assertEqual(n.reference.unknown.subject_urn, "foo/bar")
def InitFromObj_(self, notification_type, reference, message=None): self.CreateUser(self.token.username) notification.Notify(self.token.username, notification_type, message or "", reference) ns = self.GetUserNotifications(self.token.username) return user_plugin.ApiNotification().InitFromNotification(ns[0])
def InitFromObj_(self, notification_type, subject, message=None): self._SendNotification(notification_type=notification_type, subject=subject, message=message, client_id=self.client_id) user_record = aff4.FACTORY.Open(aff4.ROOT_URN.Add("users").Add( self.token.username), token=self.token) pending_notifications = user_record.Get( user_record.Schema.PENDING_NOTIFICATIONS) result = user_plugin.ApiNotification().InitFromNotification( pending_notifications.Pop()) aff4.FACTORY.Delete(aff4.ROOT_URN.Add("users").Add( self.token.username), token=self.token) return result
def testNotificationWithoutSubject(self): n = user_plugin.ApiNotification().InitFromNotification( rdf_flows.Notification(type="ViewObject")) self.assertEqual(n.reference.type, "UNKNOWN")