def testIssueCommentURL(self): hostport = 'port.someplex.com' proj = project_pb2.Project() proj.project_name = 'proj' url = 'https://port.someplex.com/p/proj/issues/detail?id=2' actual_url = framework_helpers.IssueCommentURL(hostport, proj, 2) self.assertEqual(actual_url, url) url = 'https://port.someplex.com/p/proj/issues/detail?id=2#c2' actual_url = framework_helpers.IssueCommentURL(hostport, proj, 2, seq_num=2) self.assertEqual(actual_url, url)
def _MakeEmailTasks(self, cnxn, issue, project, config, comment, hostport, users_by_id, pings): """Return a list of dicts for tasks to notify people.""" detail_url = framework_helpers.IssueCommentURL( hostport, project, issue.local_id, seq_num=comment.sequence) fields = sorted((field_def for (field_def, _date_value) in pings), key=lambda fd: fd.field_name) email_data = { 'issue': tracker_views.IssueView(issue, users_by_id, config), 'summary': issue.summary, 'ping_comment_content': comment.content, 'detail_url': detail_url, 'fields': fields, } # Generate two versions of email body: members version has all # full email addresses exposed. body_for_non_members = self.email_template.GetResponse(email_data) framework_views.RevealAllEmails(users_by_id) body_for_members = self.email_template.GetResponse(email_data) logging.info('body for non-members is:\n%r' % body_for_non_members) logging.info('body for members is:\n%r' % body_for_members) contributor_could_view = permissions.CanViewIssue( set(), permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET, project, issue) # Note: We never notify the reporter of any issue just because they # reported it, only if they star it. # TODO(jrobbins): add a user preference for notifying starrers. starrer_ids = [] # TODO(jrobbins): consider IsNoisy() when we support notifying starrers. group_reason_list = notify_reasons.ComputeGroupReasonList( cnxn, self.services, project, issue, config, users_by_id, [], contributor_could_view, starrer_ids=starrer_ids, commenter_in_project=True) commenter_view = users_by_id[comment.user_id] email_tasks = notify_helpers.MakeBulletedEmailWorkItems( group_reason_list, issue, body_for_non_members, body_for_members, project, hostport, commenter_view, detail_url, seq_num=comment.sequence, subject_prefix='Follow up on issue ', compact_subject_prefix='Follow up ') 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
def _MakeEmailTasks( self, cnxn, project, issue, config, old_owner_id, users_by_id, all_comments, comment, starrer_ids, contributor_could_view, hostport, omit_ids, perms): """Formulate emails to be sent.""" detail_url = framework_helpers.IssueCommentURL( hostport, project, issue.local_id, seq_num=comment.sequence) # TODO(jrobbins): avoid the need to make a MonorailRequest object. mr = monorailrequest.MonorailRequest(self.services) mr.project_name = project.project_name mr.project = project mr.perms = perms # We do not autolink in the emails, so just use an empty # registry of autolink rules. # TODO(jrobbins): offer users an HTML email option w/ autolinks. autolinker = autolink.Autolink() was_created = ezt.boolean(comment.sequence == 0) email_data = { # Pass open_related and closed_related into this method and to # the issue view so that we can show it on new issue email. 'issue': tracker_views.IssueView(issue, users_by_id, config), 'summary': issue.summary, 'comment': tracker_views.IssueCommentView( project.project_name, comment, users_by_id, autolinker, {}, mr, issue), 'comment_text': comment.content, 'detail_url': detail_url, 'was_created': was_created, } # Generate three versions of email body: link-only is just the link, # non-members see some obscured email addresses, and members version has # all full email addresses exposed. body_link_only = self.link_only_email_template.GetResponse( {'detail_url': detail_url, 'was_created': was_created}) body_for_non_members = self.email_template.GetResponse(email_data) framework_views.RevealAllEmails(users_by_id) email_data['comment'] = tracker_views.IssueCommentView( project.project_name, comment, users_by_id, autolinker, {}, mr, issue) body_for_members = self.email_template.GetResponse(email_data) logging.info('link-only body is:\n%r' % body_link_only) logging.info('body for non-members is:\n%r' % body_for_non_members) logging.info('body for members is:\n%r' % body_for_members) commenter_email = users_by_id[comment.user_id].email omit_addrs = set([commenter_email] + [users_by_id[omit_id].email for omit_id in omit_ids]) auth = authdata.AuthData.FromUserID( cnxn, comment.user_id, self.services) commenter_in_project = framework_bizobj.UserIsInProject( project, auth.effective_ids) noisy = tracker_helpers.IsNoisy(len(all_comments) - 1, len(starrer_ids)) # Give each user a bullet-list of all the reasons that apply for that user. group_reason_list = notify_reasons.ComputeGroupReasonList( cnxn, self.services, project, issue, config, users_by_id, omit_addrs, contributor_could_view, noisy=noisy, starrer_ids=starrer_ids, old_owner_id=old_owner_id, commenter_in_project=commenter_in_project) commenter_view = users_by_id[comment.user_id] detail_url = framework_helpers.FormatAbsoluteURLForDomain( hostport, issue.project_name, urls.ISSUE_DETAIL, id=issue.local_id) email_tasks = notify_helpers.MakeBulletedEmailWorkItems( group_reason_list, issue, body_link_only, body_for_non_members, body_for_members, project, hostport, commenter_view, detail_url, seq_num=comment.sequence) return email_tasks
def _MakeEmailTasks(self, cnxn, issue, project, config, comment, starrer_ids, hostport, users_by_id, pings): """Return a list of dicts for tasks to notify people.""" detail_url = framework_helpers.IssueCommentURL( hostport, project, issue.local_id, seq_num=comment.sequence) fields = sorted((field_def for (field_def, _date_value) in pings), key=lambda fd: fd.field_name) email_data = { 'issue': tracker_views.IssueView(issue, users_by_id, config), 'summary': issue.summary, 'ping_comment_content': comment.content, 'detail_url': detail_url, 'fields': fields, } # Generate three versions of email body with progressively more info. body_link_only = self.link_only_email_template.GetResponse({ 'detail_url': detail_url, 'was_created': ezt.boolean(False) }) body_for_non_members = self.email_template.GetResponse(email_data) framework_views.RevealAllEmails(users_by_id) body_for_members = self.email_template.GetResponse(email_data) logging.info('body for non-members is:\n%r' % body_for_non_members) logging.info('body for members is:\n%r' % body_for_members) contributor_could_view = permissions.CanViewIssue( set(), permissions.CONTRIBUTOR_ACTIVE_PERMISSIONSET, project, issue) group_reason_list = notify_reasons.ComputeGroupReasonList( cnxn, self.services, project, issue, config, users_by_id, [], contributor_could_view, starrer_ids=starrer_ids, commenter_in_project=True, include_subscribers=False, include_notify_all=False, starrer_pref_check_function=lambda u: u.notify_starred_ping) commenter_view = users_by_id[comment.user_id] email_tasks = notify_helpers.MakeBulletedEmailWorkItems( group_reason_list, issue, body_link_only, body_for_non_members, body_for_members, project, hostport, commenter_view, detail_url, seq_num=comment.sequence, subject_prefix='Follow up on issue ', compact_subject_prefix='Follow up ') return email_tasks