def prepare_reply_published_mail(user, reply, review, review_request): """Return an e-mail representing the supplied reply to a review. Args: user (django.contrib.auth.models.User): The user who published the reply. reply (reviewboard.reviews.models.review.Review): The review reply to send an e-mail about. review (reviewboard.reviews.models.review.Review): The review that was replied to. review_request (reviewboard.reviews.models.review_request.ReviewRequest): The review request. Returns: EmailMessage: The generated e-mail message. """ from reviewboard.reviews.views import build_diff_comment_fragments extra_context = { 'user': reply.user, 'review': review, 'reply': reply, 'site_url': _get_server_base_url(), } extra_context['comment_entries'] = build_diff_comment_fragments( reply.comments.order_by('filediff', 'first_line'), extra_context, 'notifications/email_diff_comment_fragment.html')[1] to_field, cc_field = build_recipients( user=reply.user, review_request=review_request, extra_recipients=review_request.review_participants) to_field, cc_field = filter_email_recipients_from_hooks( to_field, cc_field, reply_published, reply=reply, user=user, review=review, review_request=review_request) summary = _ensure_unicode(review_request.summary) return prepare_base_review_request_mail( user, review_request, 'Re: Review Request %d: %s' % (review_request.display_id, summary), review.email_message_id, to_field, cc_field, 'notifications/reply_email', extra_context)
def prepare_reply_published_mail(user, reply, review, review_request): """Return an e-mail representing the supplied reply to a review. Args: user (django.contrib.auth.models.User): The user who published the reply. reply (reviewboard.reviews.models.review.Review): The review reply to send an e-mail about. review (reviewboard.reviews.models.review.Review): The review that was replied to. review_request (reviewboard.reviews.models.review_request.ReviewRequest): The review request. Returns: EmailMessage: The generated e-mail message. """ from reviewboard.reviews.views import build_diff_comment_fragments extra_context = { 'user': reply.user, 'review': review, 'reply': reply, 'site_url': _get_server_base_url(), } extra_context['comment_entries'] = build_diff_comment_fragments( reply.comments.order_by('filediff', 'first_line'), extra_context, 'notifications/email_diff_comment_fragment.html')[1] to_field, cc_field = build_recipients( user=reply.user, review_request=review_request, extra_recipients=review_request.review_participants) to_field, cc_field = filter_email_recipients_from_hooks( to_field, cc_field, reply_published, reply=reply, user=user, review=review, review_request=review_request) summary = _ensure_unicode(review_request.summary) return prepare_base_review_request_mail( user, review_request, 'Re: Review Request %d: %s' % (review_request.display_id, summary), review.email_message_id, to_field, cc_field, 'notifications/reply_email', extra_context)
def prepare_review_request_mail(user, review_request, changedesc=None, close_type=None): """Return an e-mail representing the supplied review request. Args: user (django.contrib.auth.models.User): The user who triggered the e-mail (i.e., they published or closed he review request). review_request (reviewboard.reviews.models.ReviewRequest): The review request to send an e-mail about. changedesc (reviewboard.changedescs.models.ChangeDescription): An optional change description showing what has changed in the review request, possibly with explanatory text from the submitter. This is created when saving a draft on a public review request and will be ``None`` when publishing initially. This is used by the template to add contextual (updated) flags to inform people what has changed. close_type (unicode): How the review request was closed or ``None`` if it was published. If this is not ``None`` it must be one of: * :py:attr:`~reviewboard.reviews.models.ReviewRequest.SUBMITTED` * :py:attr:`~reviewboard.reviews.models.ReviewRequest.DISCARDED` Returns: EmailMessage: The e-mail message representing the review request. """ if not user: user = review_request.submitter summary = _ensure_unicode(review_request.summary) subject = 'Review Request %d: %s' % (review_request.display_id, summary) reply_message_id = review_request.email_message_id extra_recipients = None if reply_message_id: # Fancy quoted "replies". subject = 'Re: %s' % subject extra_recipients = review_request.participants extra_context = {} extra_filter_kwargs = {} if close_type: changedesc = review_request.changedescs.filter(public=True).latest() signal = review_request_closed extra_filter_kwargs['close_type'] = close_type else: signal = review_request_published limit_recipients_to = None if changedesc: fields_changed = changedesc.fields_changed changed_field_names = set(fields_changed) extra_context.update({ 'change_text': changedesc.text, 'change_rich_text': changedesc.rich_text, 'changes': fields_changed, }) if (changed_field_names and changed_field_names <= {'target_people', 'target_groups'}): # If the only changes are to the target reviewers, try to send a # much more targeted e-mail. Rather than having it be sent out to # everyone, it will only be sent to new reviewers. limit_recipients_to = set() for model, field in ((User, 'target_people'), (Group, 'target_groups')): if field in changed_field_names: limit_recipients_to.update( model.objects.filter(pk__in=[ item[2] for item in fields_changed[field]['added'] ])) to_field, cc_field = build_recipients( user, review_request, extra_recipients, limit_recipients_to=limit_recipients_to) to_field, cc_field = filter_email_recipients_from_hooks( to_field, cc_field, signal, review_request=review_request, user=user, **extra_filter_kwargs) return prepare_base_review_request_mail( user, review_request, subject, reply_message_id, to_field, cc_field, 'notifications/review_request_email', extra_context)
def prepare_review_published_mail(user, review, review_request, request, to_submitter_only=False): """Return an e-mail representing the supplied review. Args: user (django.contrib.auth.models.User): The user who published the review. review (reviewboard.reviews.models.review.Review): The review to send an e-mail about. review_request (reviewboard.reviews.models.review_request.ReviewRequest): The review request that was reviewed. to_submitter_only (bool): Whether or not the review should be sent to the submitter only. Returns: EmailMessage: The generated e-mail message. """ from reviewboard.reviews.views import build_diff_comment_fragments review.ordered_comments = review.comments.order_by('filediff', 'first_line') has_issues = (review.ship_it and review.has_comments(only_issues=True)) extra_context = { 'user': review.user, 'review': review, 'has_issues': has_issues, 'request': request, } extra_headers = {} if review.ship_it: extra_headers['X-ReviewBoard-ShipIt'] = '1' if review.ship_it_only: extra_headers['X-ReviewBoard-ShipIt-Only'] = '1' extra_context['comment_entries'] = build_diff_comment_fragments( review.ordered_comments, extra_context, 'notifications/email_diff_comment_fragment.html')[1] limit_to = None if to_submitter_only: limit_to = {review_request.submitter, review.user} to_field, cc_field = build_recipients(review.user, review_request, limit_recipients_to=limit_to) to_field, cc_field = filter_email_recipients_from_hooks( to_field, cc_field, review_published, user=user, review=review, to_submitter_only=to_submitter_only, review_request=review_request) summary = _ensure_unicode(review_request.summary) return prepare_base_review_request_mail( review.user, review_request, 'Re: Review Request %d: %s' % (review_request.display_id, summary), review_request.email_message_id, to_field, cc_field, 'notifications/review_email', extra_context, extra_headers=extra_headers)
def prepare_review_request_mail(user, review_request, changedesc=None, close_type=None): """Return an e-mail representing the supplied review request. Args: user (django.contrib.auth.models.User): The user who triggered the e-mail (i.e., they published or closed he review request). review_request (reviewboard.reviews.models.ReviewRequest): The review request to send an e-mail about. changedesc (reviewboard.changedescs.models.ChangeDescription): An optional change description showing what has changed in the review request, possibly with explanatory text from the submitter. This is created when saving a draft on a public review request and will be ``None`` when publishing initially. This is used by the template to add contextual (updated) flags to inform people what has changed. close_type (unicode): How the review request was closed or ``None`` if it was published. If this is not ``None`` it must be one of: * :py:attr:`~reviewboard.reviews.models.ReviewRequest.SUBMITTED` * :py:attr:`~reviewboard.reviews.models.ReviewRequest.DISCARDED` Returns: EmailMessage: The e-mail message representing the review request. """ if not user: user = review_request.submitter summary = _ensure_unicode(review_request.summary) subject = 'Review Request %d: %s' % (review_request.display_id, summary) reply_message_id = review_request.email_message_id extra_recipients = None if reply_message_id: # Fancy quoted "replies". subject = 'Re: %s' % subject extra_recipients = review_request.review_participants extra_context = {} extra_filter_kwargs = {} if close_type: changedesc = review_request.changedescs.filter(public=True).latest() signal = review_request_closed extra_filter_kwargs['close_type'] = close_type else: signal = review_request_published limit_recipients_to = None if changedesc: fields_changed = changedesc.fields_changed changed_field_names = set(fields_changed) extra_context.update({ 'change_text': changedesc.text, 'change_rich_text': changedesc.rich_text, 'changes': fields_changed, }) if (changed_field_names and changed_field_names <= {'target_people', 'target_groups'}): # If the only changes are to the target reviewers, try to send a # much more targeted e-mail. Rather than having it be sent out to # everyone, it will only be sent to new reviewers. limit_recipients_to = set() for model, field in ((User, 'target_people'), (Group, 'target_groups')): if field in changed_field_names: limit_recipients_to.update( model.objects.filter(pk__in=[ item[2] for item in fields_changed[field]['added'] ])) to_field, cc_field = build_recipients( user, review_request, extra_recipients, limit_recipients_to=limit_recipients_to) to_field, cc_field = filter_email_recipients_from_hooks( to_field, cc_field, signal, review_request=review_request, user=user, **extra_filter_kwargs) return prepare_base_review_request_mail( user, review_request, subject, reply_message_id, to_field, cc_field, 'notifications/review_request_email', extra_context)
def prepare_review_published_mail(user, review, review_request, request, to_owner_only=False): """Return an e-mail representing the supplied review. Args: user (django.contrib.auth.models.User): The user who published the review. review (reviewboard.reviews.models.review.Review): The review to send an e-mail about. review_request (reviewboard.reviews.models.review_request.ReviewRequest): The review request that was reviewed. to_owner_only (bool): Whether or not the review should be sent to the submitter only. Returns: EmailMessage: The generated e-mail message. """ from reviewboard.reviews.views import build_diff_comment_fragments review.ordered_comments = review.comments.order_by('filediff', 'first_line') has_issues = (review.ship_it and review.has_comments(only_issues=True)) extra_context = { 'user': review.user, 'review': review, 'has_issues': has_issues, 'request': request, 'site_url': _get_server_base_url(), } extra_headers = {} if review.ship_it: extra_headers['X-ReviewBoard-ShipIt'] = '1' if review.ship_it_only: extra_headers['X-ReviewBoard-ShipIt-Only'] = '1' extra_context['comment_entries'] = build_diff_comment_fragments( review.ordered_comments, extra_context, 'notifications/email_diff_comment_fragment.html')[1] limit_to = None if to_owner_only: limit_to = {review_request.submitter, review.user} to_field, cc_field = build_recipients(review.user, review_request, limit_recipients_to=limit_to) to_field, cc_field = filter_email_recipients_from_hooks( to_field, cc_field, review_published, user=user, review=review, to_owner_only=to_owner_only, review_request=review_request) summary = _ensure_unicode(review_request.summary) return prepare_base_review_request_mail( review.user, review_request, 'Re: Review Request %d: %s' % (review_request.display_id, summary), review_request.email_message_id, to_field, cc_field, 'notifications/review_email', extra_context, extra_headers=extra_headers)