def test_include_watchers_not_run_for_minor_edits(self, include_watchers): item = DecisionFactory.build(id=1) item = add_watchers(item) settings_handler = ObservationManager() settings_handler.send_notifications([], item, MINOR_CHANGE, {}, {}, "") self.assertFalse(include_watchers.called)
def send_decision_notifications(decision, users): headers = {'Message-ID' : decision.get_message_id()} headers.update(STANDARD_SENDING_HEADERS) extra_context = {"observed": decision} observation_manager = ObservationManager() observation_manager.send_notifications( users, decision, DECISION_NEW, extra_context, headers, from_email=decision.get_email())
def test_include_watchers_not_run_for_minor_edits(self, include_watchers): item = DecisionFactory.build(id=1) item = add_watchers(item) settings_handler = ObservationManager() settings_handler.send_notifications([], item, MINOR_CHANGE, {}, {}, "") self.assertFalse(include_watchers.called)
def send_decision_notifications(decision, users): headers = {'Message-ID': decision.get_message_id()} headers.update(STANDARD_SENDING_HEADERS) extra_context = {"observed": decision} observation_manager = ObservationManager() observation_manager.send_notifications(users, decision, DECISION_NEW, extra_context, headers, from_email=decision.get_email())
def _send_change_notifications(self, notification_type): headers = {'Message-ID': self.get_message_id()} headers.update(STANDARD_SENDING_HEADERS) org_users = self.organization.users.all() observation_manager = ObservationManager() observation_manager.send_notifications(org_users, self, notification_type, {"observed": self}, headers=headers, from_email=self.get_email())
def send_comment_notifications(comment, users): headers = {'Message-ID' : "comment-%s@%s" % (comment.id, Site.objects.get_current().domain)} headers.update(STANDARD_SENDING_HEADERS) headers.update({'In-Reply-To' : comment.content_object.get_message_id()}) comment.content_object.decision.note_external_modification() observation_manager = ObservationManager() extra_context = dict({"observed": comment}) observation_manager.send_notifications(users, comment, COMMENT_NEW, extra_context, headers, from_email=comment.content_object.decision.get_email())
def decision_signal_handler(sender, **kwargs): """ All users except the author will get a notification informing them of new content. All users are made observers of the decision. """ instance = kwargs.get('instance') headers = {'Message-ID' : instance.get_message_id()} headers.update(STANDARD_SENDING_HEADERS) if kwargs.get('created', True): active_users = instance.organization.users.filter(is_active=True) extra_context = {"observed": instance} observation_manager = ObservationManager() observation_manager.send_notifications(active_users, instance, DECISION_NEW, extra_context, headers, from_email=instance.get_email())
def decision_signal_handler(sender, **kwargs): """ All users except the author will get a notification informing them of new content. All users are made observers of the decision. """ instance = kwargs.get('instance') headers = {'Message-ID': instance.get_message_id()} headers.update(STANDARD_SENDING_HEADERS) if kwargs.get('created', True): active_users = instance.organization.users.filter(is_active=True) extra_context = {"observed": instance} observation_manager = ObservationManager() observation_manager.send_notifications(active_users, instance, DECISION_NEW, extra_context, headers, from_email=instance.get_email())
def test_send_notifications_for_main_items_sends_correct_messages(self): initial_count = len(mail.outbox) number_of_users = 3 organization = OrganizationFactory() decision = DecisionFactory(organization=organization) decision = add_watchers(decision) user1, user2, user3 = UserFactory.create_batch(number_of_users, email="*****@*****.**") NotificationSettingsFactory(user=user1, organization=organization, notification_level=NO_NOTIFICATIONS), NotificationSettingsFactory( user=user2, organization=organization, notification_level=MAIN_ITEMS_NOTIFICATIONS_ONLY), NotificationSettingsFactory( user=user3, organization=organization, notification_level=MINOR_CHANGES_NOTIFICATIONS), settings_handler = ObservationManager() recipients = [user1, user2, user3] settings_handler.send_notifications( recipients, decision, DECISION_NEW, {"observed": decision}, { 'Message-ID': decision.get_message_id(), 'Precedence': 'bulk', 'Auto-Submitted': 'auto-generated' }, "*****@*****.**") final_count = len(mail.outbox) expected_number_messages_sent = len( decision.watchers.all()) + number_of_users - 1 actual_number_messages_sent = final_count - initial_count self.assertEqual(expected_number_messages_sent, actual_number_messages_sent)
def send_comment_notifications(comment, users): headers = { 'Message-ID': "comment-%s@%s" % (comment.id, Site.objects.get_current().domain) } headers.update(STANDARD_SENDING_HEADERS) headers.update({'In-Reply-To': comment.content_object.get_message_id()}) comment.content_object.decision.note_external_modification() observation_manager = ObservationManager() extra_context = dict({"observed": comment}) observation_manager.send_notifications( users, comment, COMMENT_NEW, extra_context, headers, from_email=comment.content_object.decision.get_email())
def feedback_signal_handler(sender, **kwargs): """ All watchers of a decision will get a notification informing them of new feedback. All watchers become observers of the feedback. """ instance = kwargs.get('instance') headers = { 'Message-ID': instance.get_message_id(), 'In-Reply-To': instance.decision.get_message_id(), 'References': ' '.join(( instance.decision.get_message_id(), instance.get_message_id())) } headers.update(STANDARD_SENDING_HEADERS) instance.decision.note_external_modification() observation_manager = ObservationManager() org_users = list(instance.decision.organization.users.filter(is_active=True)) extra_context = dict({"observed": instance}) if kwargs.get('created', True): # All watchers of parent get notified of new feedback. observation_manager.send_notifications(org_users, instance, FEEDBACK_NEW, extra_context, headers, from_email=instance.decision.get_email()) else: # An edit by someone other than the author never counts as minor if instance.author != instance.editor or not instance.minor_edit: observation_manager.send_notifications(org_users, instance, FEEDBACK_CHANGE, extra_context, headers, from_email=instance.decision.get_email()) else: observation_manager.send_notifications(org_users, instance, MINOR_CHANGE, extra_context, headers, from_email=instance.decision.get_email())
def test_send_notifications_for_main_items_sends_correct_messages(self): initial_count = len(mail.outbox) number_of_users = 3 organization = OrganizationFactory() decision = DecisionFactory( organization=organization ) decision = add_watchers(decision) user1, user2, user3 = UserFactory.create_batch( number_of_users, email="*****@*****.**" ) NotificationSettingsFactory(user=user1, organization=organization, notification_level=NO_NOTIFICATIONS), NotificationSettingsFactory(user=user2, organization=organization, notification_level=MAIN_ITEMS_NOTIFICATIONS_ONLY), NotificationSettingsFactory(user=user3, organization=organization, notification_level=MINOR_CHANGES_NOTIFICATIONS), settings_handler = ObservationManager() recipients = [user1, user2, user3] settings_handler.send_notifications( recipients, decision, DECISION_NEW, {"observed": decision}, { 'Message-ID' : decision.get_message_id(), 'Precedence': 'bulk', 'Auto-Submitted': 'auto-generated' }, "*****@*****.**" ) final_count = len(mail.outbox) expected_number_messages_sent = len(decision.watchers.all()) + number_of_users - 1 actual_number_messages_sent = final_count - initial_count self.assertEqual(expected_number_messages_sent, actual_number_messages_sent)
def feedback_signal_handler(sender, **kwargs): """ All watchers of a decision will get a notification informing them of new feedback. All watchers become observers of the feedback. """ instance = kwargs.get('instance') headers = { 'Message-ID': instance.get_message_id(), 'In-Reply-To': instance.decision.get_message_id(), 'References': ' '.join( (instance.decision.get_message_id(), instance.get_message_id())) } headers.update(STANDARD_SENDING_HEADERS) instance.decision.note_external_modification() observation_manager = ObservationManager() org_users = list( instance.decision.organization.users.filter(is_active=True)) extra_context = dict({"observed": instance}) if kwargs.get('created', True): # All watchers of parent get notified of new feedback. observation_manager.send_notifications( org_users, instance, FEEDBACK_NEW, extra_context, headers, from_email=instance.decision.get_email()) else: # An edit by someone other than the author never counts as minor if instance.author != instance.editor or not instance.minor_edit: observation_manager.send_notifications( org_users, instance, FEEDBACK_CHANGE, extra_context, headers, from_email=instance.decision.get_email()) else: observation_manager.send_notifications( org_users, instance, MINOR_CHANGE, extra_context, headers, from_email=instance.decision.get_email())
def _send_change_notifications(self, notification_type): headers = {'Message-ID': self.get_message_id()} headers.update(STANDARD_SENDING_HEADERS) org_users = self.organization.users.all() observation_manager = ObservationManager() observation_manager.send_notifications(org_users, self, notification_type, {"observed": self}, headers=headers, from_email=self.get_email())