def send_notification(self, parent_type, parent_id, errors=None, failed=False): """Send mail notification with information about errors.""" parent_model = models.get_model(parent_type) parent = parent_model.query.get(parent_id) data = { "title": parent.title, "url": get_object_url(parent), } if failed: body = settings.EMAIL_BULK_CHILD_SYNC_EXCEPTION.render() elif errors: data["assessments"] = [{ "url": get_object_url(obj), "code": obj.slug, "title": obj.title, } for (obj, _) in errors] body = settings.EMAIL_BULK_CHILD_SYNC_FAILED.render(sync_data=data) else: body = settings.EMAIL_BULK_CHILD_SYNC_SUCCEEDED.render( sync_data=data) receiver = login.get_current_user() common.send_email(receiver.email, self.ISSUETRACKER_SYNC_TITLE, body)
def send_notification(self, filename, recipient, errors=None, failed=False): """Send mail notification with information about errors.""" data = {} if failed: data["title"] = self.ERROR_TITLE.format(filename=filename) data["email_text"] = self.EXCEPTION_TEXT body = settings.EMAIL_BULK_SYNC_EXCEPTION.render(sync_data=data) elif errors: data["objects"] = [{ "url": get_object_url(obj), "code": obj.slug, "title": obj.title, } for (obj, _) in errors] data["title"] = self.ERROR_TITLE.format(filename=filename) data["email_text"] = self.ERROR_TEXT.format(filename=filename) body = settings.EMAIL_BULK_SYNC_FAILED.render(sync_data=data) else: data["title"] = self.SUCCESS_TITLE.format(filename=filename) data["email_text"] = self.SUCCESS_TEXT.format(filename=filename) body = settings.EMAIL_BULK_SYNC_SUCCEEDED.render(sync_data=data) common.send_email(recipient, self.ISSUETRACKER_SYNC_TITLE, body)
def send_notification(self, parent_type, parent_id, errors=None, failed=False): """Send mail notification with information about errors.""" parent_model = models.get_model(parent_type) parent = parent_model.query.get(parent_id) data = {"title": parent.title} if failed: body = settings.EMAIL_BULK_CHILD_SYNC_EXCEPTION.render() elif errors: data["assessments"] = [ { "url": get_object_url(obj), "code": obj.slug, "title": obj.title, } for (obj, _) in errors ] body = settings.EMAIL_BULK_CHILD_SYNC_FAILED.render(sync_data=data) else: body = settings.EMAIL_BULK_CHILD_SYNC_SUCCEEDED.render(sync_data=data) receiver = login.get_current_user() common.send_email(receiver.email, self.ISSUETRACKER_SYNC_TITLE, body)
def _create_notif_data(assessments): """Create data in format applicable for template rendering""" result = [ {"title": assessment.title, "url": get_object_url(assessment)} for assessment in assessments ] return result
def build_prosal_data(proposals): """Generator, that returns pairs addresse and text mailing to addressee.""" # cache wormup cads_dict = dict( all_models.CustomAttributeDefinition.query.values( all_models.CustomAttributeDefinition.id, all_models.CustomAttributeDefinition.title, ) ) person_dict = dict( all_models.Person.query.values( all_models.Person.id, all_models.Person.email, ) ) acr_dict = dict( all_models.AccessControlRole.query.values( all_models.AccessControlRole.id, all_models.AccessControlRole.name ) ) proposal_email_pools = collections.defaultdict(dict) for proposal in proposals: if not isinstance(proposal.instance, roleable.Roleable): continue single_values = get_field_single_values(proposal, person_dict, cads_dict) list_values = get_fields_list_values(proposal, acr_dict, person_dict) field_value_converter(single_values, proposal.instance.__class__) field_value_converter(list_values, proposal.instance.__class__) field_name_converter(single_values, proposal.instance.__class__) field_name_converter(list_values, proposal.instance.__class__) if not (single_values or list_values): continue proposal_email_context = EmailProposalContext( proposal.agenda, proposal.proposed_by.name or proposal.proposed_by.email, proposal.instance, single_values, list_values, object_url=get_object_url(proposal.instance), ) for person, acl in proposal.instance.access_control_list: if person == proposal.proposed_by: # Don't need to send proposal digest to person who make proposal continue if acl.ac_role.notify_about_proposal: proposal_email_pools[person][proposal.id] = proposal_email_context return proposal_email_pools
def build_review_data(review_notifications): """Build data for review notification template fast_digest.html """ reviewers_data = collections.defaultdict(dict) owners_data = collections.defaultdict(dict) for notification in review_notifications: review = notification.object reviewable = review.reviewable if not reviewable: continue link = get_object_url(reviewable) fill_reviewers_data(link, review, reviewable, reviewers_data) fill_owners_data(link, notification, owners_data, review, reviewable) return {"reviewers_data": reviewers_data, "owners_data": owners_data}
def test_error_notification(self): """Test notification about bulk generation with errors""" creator = issuetracker_bulk_sync.IssueTrackerBulkCreator() filename = "test_file.csv" recipient = "*****@*****.**" assmt = factories.AssessmentFactory() with mock.patch("ggrc.notifications.common.send_email") as send_mock: creator.send_notification(filename, recipient, errors=[(assmt, "")]) self.assertEqual(send_mock.call_count, 1) (email, title, body), _ = send_mock.call_args_list[0] self.assertEqual(title, creator.ISSUETRACKER_SYNC_TITLE) self.assertEqual(email, recipient) self.assertIn(creator.ERROR_TITLE.format(filename=filename), body) self.assertIn(assmt.slug, body) self.assertIn(assmt.title, body) self.assertIn(data_handlers.get_object_url(assmt), body)
def build_review_data(review_notifications): """Build data for review notification template fast_digest.html """ reviewers_data = collections.defaultdict(dict) owners_data = collections.defaultdict(dict) for notification in review_notifications: review = notification.object reviewable = review.reviewable if not reviewable: continue link = get_object_url(reviewable) fill_reviewers_data(link, review, reviewable, reviewers_data) fill_owners_data(link, notification, owners_data, review, reviewable) return { "reviewers_data": reviewers_data, "owners_data": owners_data }
def send_notification(self, filename, recipient, errors=None, failed=False): """Send mail notification with information about errors.""" data = {} if failed: data["title"] = self.ERROR_TITLE.format(filename=filename) data["email_text"] = self.EXCEPTION_TEXT body = settings.EMAIL_BULK_SYNC_EXCEPTION.render(sync_data=data) elif errors: data["objects"] = [ { "url": get_object_url(obj), "code": obj.slug, "title": obj.title, } for (obj, _) in errors ] data["title"] = self.ERROR_TITLE.format(filename=filename) data["email_text"] = self.ERROR_TEXT.format(filename=filename) body = settings.EMAIL_BULK_SYNC_FAILED.render(sync_data=data) else: data["title"] = self.SUCCESS_TITLE.format(filename=filename) data["email_text"] = self.SUCCESS_TEXT.format(filename=filename) body = settings.EMAIL_BULK_SYNC_SUCCEEDED.render(sync_data=data) common.send_email(recipient, self.ISSUETRACKER_SYNC_TITLE, body)