def _FormatBulkIssuesEmail( self, dest_email, issues, users_by_id, commenter_view, hostport, comment_text, amendments, config, project, is_member): """Format an email to one user listing many issues.""" from_addr = emailfmt.FormatFromAddr( project, commenter_view=commenter_view, reveal_addr=is_member, can_reply_to=False) subject, body = self._FormatBulkIssues( issues, users_by_id, commenter_view, hostport, comment_text, amendments, config) body = notify_helpers._TruncateBody(body) return dict(from_addr=from_addr, to=dest_email, subject=subject, body=body)
def _MakeRulesDeletedEmailTasks(self, hostport, project, emails_by_id, rules): rules_url = framework_helpers.FormatAbsoluteURLForDomain( hostport, project.project_name, urls.ADMIN_RULES) email_data = { 'project_name': project.project_name, 'rules': rules, 'rules_url': rules_url, } logging.info(email_data) subject = '%s Project: Deleted Filter Rules' % project.project_name email_body = self.email_template.GetResponse(email_data) body = notify_helpers._TruncateBody(email_body) email_tasks = [] for rid in project.owner_ids: from_addr = emailfmt.FormatFromAddr( project, reveal_addr=True, can_reply_to=False) dest_email = emails_by_id.get(rid) email_tasks.append( dict(from_addr=from_addr, to=dest_email, subject=subject, body=body)) return email_tasks
def _MakeApprovalEmailTasks( self, hostport, issue, project, approval_value, approval_name, comment, users_by_id, user_ids_from_fields, perms): """Formulate emails to be sent.""" # TODO(jojwang): avoid need to make MonorailRequest and autolinker # for comment_view OR make make tracker_views._ParseTextRuns public # and only pass text_runs to email_data. mr = monorailrequest.MonorailRequest(self.services) mr.project_name = project.project_name mr.project = project mr.perms = perms autolinker = autolink.Autolink() approval_url = framework_helpers.IssueCommentURL( hostport, project, issue.local_id, seq_num=comment.sequence) comment_view = tracker_views.IssueCommentView( project.project_name, comment, users_by_id, autolinker, {}, mr, issue) domain_url = framework_helpers.FormatAbsoluteURLForDomain( hostport, project.project_name, '/issues/') commenter_view = users_by_id[comment.user_id] email_data = { 'domain_url': domain_url, 'approval_url': approval_url, 'comment': comment_view, 'issue_local_id': issue.local_id, 'summary': issue.summary, } subject = '%s Approval: %s (Issue %s)' % ( approval_name, issue.summary, issue.local_id) email_body = self.email_template.GetResponse(email_data) body = notify_helpers._TruncateBody(email_body) recipient_ids = self._GetApprovalEmailRecipients( approval_value, comment, issue, user_ids_from_fields, omit_ids=[comment.user_id]) direct, indirect = self.services.usergroup.ExpandAnyGroupEmailRecipients( mr.cnxn, recipient_ids) # group ids were found in recipient_ids. # Re-set recipient_ids to remove group_ids if indirect: recipient_ids = set(direct + indirect) users_by_id.update(framework_views.MakeAllUserViews( mr.cnxn, self.services.user, indirect)) # already contains direct # TODO(jojwang): monorail:3588, refine email contents based on direct # and indirect user_ids returned. email_tasks = [] for rid in recipient_ids: # TODO(jojwang): monorail:3588, add reveal_addr based on # recipient member status from_addr = emailfmt.FormatFromAddr( project, commenter_view=commenter_view, can_reply_to=False) dest_email = users_by_id[rid].email email_tasks.append( dict(from_addr=from_addr, to=dest_email, subject=subject, body=body) ) return email_tasks