Review Board

beta

Ability for Review Request emails to make use of the cc field when sending out emails to the Review Group.

Updated 4 months ago

Tarun Anupoju Reviewers
reviewboard
None Review Board SVN
A high priority for us was to differentiate between the Reviewer and non-reviewer when the review request emails were being sent out. This differentiation informs easily who the Reviewer is for a given Request. I have coded up the following to meet those requirements.

The attached patch adds the following properties:
In the emails that are sent out by Review Board, if there is a reviewer present( i.e someone mentioned in the people category) then the 'to' field will have the email of the Reviewer and the 'cc' field will consists of the other members present in the group(except the reviewer ...of course).
If no one is mentioned then the email will be sent out normally.


!!!Requirements:
The EmailMessage class in django (django/core/mail.py) does not make use of the 'cc' field. Therefore to make use of the 'cc' field, the following needs to be done:

1)Go to this link--> http://code.djangoproject.com/ticket/7722 <-- and download the mail.diff  and patch it to your django/core/maily.py . This allows for email messages to now use the 'cc' field. Once the patch has been applied a slight change needs to be done. The patch results in an indentation error at line 215. Once that has been adjusted, you are good to go!



---
I know this requires some additional changes to be made to the EmailMessage class.....but this is the best that can be done to use the 'cc' field.

************************************************************************************************************
UPDATE 2 : 9/2/2008

Instead of going through the above process where you have to apply a patch to Django, it is now possible for ReviewBoard to make use of the cc fields when sending out emails. To reiterate...there is no need to make any changes to Django the feature has been incorporated into ReviewBoard.
I have tested it on my Review Board setup and It works fine.

*******************************************************************************************************
UPDATE 2 : 9/2/2008

Tested on local ReviewBoard setup (Fedora 9)

Diff revision 2 (Latest)

1 2
1 2

  1. trunk/reviewboard/reviews/email.py: 13 changes [ 1 2 3 4 5 6 7 8 9 10 11 12 13 ]
trunk/reviewboard/reviews/email.py
Revision 1477 New Change
27
        return [get_email_address_for_user(u)
27
        return [get_email_address_for_user(u)
28
                for u in g.users.filter(is_active=True)]
28
                for u in g.users.filter(is_active=True)]
29
29
30
30
31
class SpiffyEmailMessage(EmailMessage):
31
class SpiffyEmailMessage(EmailMessage):
32
    def __init__(self, subject, body, from_email, to, in_reply_to):
32
    def __init__(self, subject, body, from_email, to, cc, in_reply_to):
33
        EmailMessage.__init__(self, subject, body, from_email, to)
33
	EmailMessage.__init__(self, subject, body, from_email, to)
34
35
        if cc:
36
	   self.cc = cc
37
	else:
38
	   self.cc = []
39
	   
34
        self.in_reply_to = in_reply_to
40
	self.in_reply_to = in_reply_to
35
        self.message_id = None
41
        self.message_id = None
36
42
	
37
    def message(self):
43
    def message(self):
38
        msg = super(SpiffyEmailMessage, self).message()
44
        msg = super(SpiffyEmailMessage, self).message()
39
45
46
	if self.cc:
47
	    msg['Cc'] =','.join(self.cc)
48
40
        if self.in_reply_to:
49
        if self.in_reply_to:
41
            msg['In-Reply-To'] = self.in_reply_to
50
            msg['In-Reply-To'] = self.in_reply_to
42
            msg['References'] = self.in_reply_to
51
            msg['References'] = self.in_reply_to
43
52
	
44
        self.message_id = msg['Message-ID']
53
	self.message_id = msg['Message-ID']
45
54
       
46
        return msg
55
        return msg
47
56
48
57
49
def send_review_mail(user, review_request, subject, in_reply_to,
58
def send_review_mail(user, review_request, subject, in_reply_to,
50
                     extra_recipients, template_name, context={}):
59
                     extra_recipients, template_name, context={}):
55
    current_site = Site.objects.get_current()
64
    current_site = Site.objects.get_current()
56
65
57
    from_email = get_email_address_for_user(user)
66
    from_email = get_email_address_for_user(user)
58
67
59
    recipients = set([from_email])
68
    recipients = set([from_email])
69
    to_field = set()
60
70
61
    if review_request.submitter.is_active:
71
    if review_request.submitter.is_active:
62
        recipients.add(get_email_address_for_user(review_request.submitter))
72
        recipients.add(get_email_address_for_user(review_request.submitter))
63
73
    
64
    for u in review_request.target_people.filter(is_active=True):
74
    for u in review_request.target_people.filter(is_active=True):
65
        recipients.add(get_email_address_for_user(u))
75
        recipients.add(get_email_address_for_user(u))
66
76
	to_field.add(get_email_address_for_user(u))
77
    
67
    for group in review_request.target_groups.all():
78
    for group in review_request.target_groups.all():
68
        for address in get_email_addresses_for_group(group):
79
        for address in get_email_addresses_for_group(group):
69
            recipients.add(address)
80
            recipients.add(address)
70
81
71
    for profile in review_request.starred_by.all():
82
    for profile in review_request.starred_by.all():
82
    context['user'] = user
93
    context['user'] = user
83
    context['domain'] = current_site.domain
94
    context['domain'] = current_site.domain
84
    context['domain_method'] = siteconfig.get("site_domain_method")
95
    context['domain_method'] = siteconfig.get("site_domain_method")
85
    context['review_request'] = review_request
96
    context['review_request'] = review_request
86
    body = render_to_string(template_name, context)
97
    body = render_to_string(template_name, context)
98
    
99
    # Set the cc field only when the to field (i.e People) are mentioned,
100
    # so that to field consists of Reviewers and cc consists of all the
101
    # other members of the group
102
    if to_field:
103
	cc_field = recipients.symmetric_difference(to_field)
104
    else:
105
	to_field = recipients
106
	cc_field = set()
87
107
88
    message = SpiffyEmailMessage(subject.strip(), body, from_email,
108
    message = SpiffyEmailMessage(subject.strip(), body, from_email,
89
                                 list(recipients), in_reply_to)
109
                                 list(to_field),list(cc_field), in_reply_to)
110
    
90
    message.send()
111
    message.send()
91
112
92
    return message.message_id
113
    return message.message_id
93
114
94
115
  1. trunk/reviewboard/reviews/email.py: 13 changes [ 1 2 3 4 5 6 7 8 9 10 11 12 13 ]