Merge lp:~julian-edwards/launchpad/sync-email-from-addr-bug-817102 into lp:launchpad

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: no longer in the source branch.
Merged at revision: 13555
Proposed branch: lp:~julian-edwards/launchpad/sync-email-from-addr-bug-817102
Merge into: lp:launchpad
Diff against target: 133 lines (+40/-4)
5 files modified
lib/lp/soyuz/adapters/notification.py (+10/-1)
lib/lp/soyuz/adapters/tests/test_notification.py (+23/-0)
lib/lp/soyuz/model/packagecopyjob.py (+1/-1)
lib/lp/soyuz/scripts/packagecopier.py (+5/-2)
lib/lp/soyuz/tests/test_packagecopyjob.py (+1/-0)
To merge this branch: bzr merge lp:~julian-edwards/launchpad/sync-email-from-addr-bug-817102
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+69659@code.launchpad.net

Commit message

[r=jtv][bug=817102] Sync announcement emails now come from the sync requester not the package changer.

Description of the change

The announcement emails for syncs into a distro were heading out with the From: address set as the Changed-by on the package being synced. This is wrong, it should be the person who requested the sync.

This branch fixes that.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

That should do the trick. May be worth documenting that the override doesn't happen if the given user has no email address; I believe you hit snags with that case in the real world.

There's a stupendous amount of setup for such a simple test. Would be nice if that could be avoided somehow, but I'll admit it's a thorny case.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/adapters/notification.py'
2--- lib/lp/soyuz/adapters/notification.py 2011-07-26 10:57:47 +0000
3+++ lib/lp/soyuz/adapters/notification.py 2011-07-28 20:49:48 +0000
4@@ -125,7 +125,8 @@
5
6 def notify(blamer, spr, bprs, customfiles, archive, distroseries, pocket,
7 summary_text=None, changes=None, changesfile_content=None,
8- changesfile_object=None, action=None, dry_run=False, logger=None):
9+ changesfile_object=None, action=None, dry_run=False,
10+ logger=None, announce_from_person=None):
11 """Notify about
12
13 :param blamer: The `IPerson` who is to blame for this notification.
14@@ -144,6 +145,9 @@
15 :param action: A string of what action to notify for, such as 'new',
16 'accepted'.
17 :param dry_run: If True, only log the mail.
18+ :param announce_from_person: If passed, use this `IPerson` as the From: in
19+ announcement emails. If the person has no preferred email address,
20+ the person is ignored and the default From: is used instead.
21 """
22 # If this is a binary or mixed upload, we don't send *any* emails
23 # provided it's not a rejection or a security upload:
24@@ -224,6 +228,11 @@
25
26 (changesfile, date, from_addr, maintainer) = fetch_information(
27 spr, bprs, changes)
28+ if announce_from_person is not None:
29+ email = announce_from_person.preferredemail
30+ if email:
31+ from_addr = email.email
32+
33 # If we're sending an acceptance notification for a non-PPA upload,
34 # announce if possible. Avoid announcing backports, binary-only
35 # security uploads, or autosync uploads.
36
37=== modified file 'lib/lp/soyuz/adapters/tests/test_notification.py'
38--- lib/lp/soyuz/adapters/tests/test_notification.py 2011-07-26 10:55:05 +0000
39+++ lib/lp/soyuz/adapters/tests/test_notification.py 2011-07-28 20:49:48 +0000
40@@ -10,6 +10,7 @@
41 ZopelessDatabaseLayer,
42 )
43 from lp.archivepublisher.utils import get_ppa_reference
44+from lp.registry.interfaces.pocket import PackagePublishingPocket
45 from lp.services.mail.sendmail import format_address_for_person
46 from lp.services.log.logger import BufferLogger
47 from lp.soyuz.adapters.notification import (
48@@ -52,6 +53,28 @@
49 'accepted')
50 self.assertEqual(expected_subject, subject)
51
52+ def test_notify_from_person_override(self):
53+ # notify() takes an optional from_person to override the calculated
54+ # From: address in announcement emails.
55+ spr = self.factory.makeSourcePackageRelease()
56+ self.factory.makeSourcePackageReleaseFile(sourcepackagerelease=spr)
57+ archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
58+ pocket = PackagePublishingPocket.RELEASE
59+ distroseries = self.factory.makeDistroSeries()
60+ distroseries.changeslist = "blah@example.com"
61+ blamer = self.factory.makePerson()
62+ from_person = self.factory.makePerson()
63+ notify(
64+ blamer, spr, [], [], archive, distroseries, pocket,
65+ action='accepted', announce_from_person=from_person)
66+ notifications = pop_notifications()
67+ self.assertEqual(2, len(notifications))
68+ # The first notification is to the blamer,
69+ # the second is the announce list, which is the one that gets the
70+ # overridden From:
71+ self.assertEqual(
72+ from_person.preferredemail.email, notifications[1]["From"])
73+
74
75 class TestNotification(TestCaseWithFactory):
76
77
78=== modified file 'lib/lp/soyuz/model/packagecopyjob.py'
79--- lib/lp/soyuz/model/packagecopyjob.py 2011-07-26 11:44:28 +0000
80+++ lib/lp/soyuz/model/packagecopyjob.py 2011-07-28 20:49:48 +0000
81@@ -511,7 +511,7 @@
82 series=self.target_distroseries, pocket=self.target_pocket,
83 include_binaries=self.include_binaries, check_permissions=True,
84 person=self.requester, overrides=[override],
85- send_email=send_email)
86+ send_email=send_email, announce_from_person=self.requester)
87
88 if pu is not None:
89 # A PackageUpload will only exist if the copy job had to be
90
91=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
92--- lib/lp/soyuz/scripts/packagecopier.py 2011-07-22 11:12:23 +0000
93+++ lib/lp/soyuz/scripts/packagecopier.py 2011-07-28 20:49:48 +0000
94@@ -525,7 +525,7 @@
95 def do_copy(sources, archive, series, pocket, include_binaries=False,
96 allow_delayed_copies=True, person=None, check_permissions=True,
97 overrides=None, send_email=False, strict_binaries=True,
98- close_bugs=True, create_dsd_job=True):
99+ close_bugs=True, create_dsd_job=True, announce_from_person=None):
100 """Perform the complete copy of the given sources incrementally.
101
102 Verifies if each copy can be performed using `CopyChecker` and
103@@ -557,6 +557,8 @@
104 override must be for the corresponding source in the sources list.
105 Overrides will be ignored for delayed copies.
106 :param send_email: Should we notify for the copy performed?
107+ :param announce_from_person: If send_email is True,
108+ then send announcement emails with this person as the From:
109 :param strict_binaries: If 'include_binaries' is True then setting this
110 to True will make the copy fail if binaries cannot be also copied.
111 :param close_bugs: A boolean indicating whether or not bugs on the
112@@ -616,7 +618,8 @@
113 notify(
114 person, source.sourcepackagerelease, [], [], archive,
115 destination_series, pocket, changes=None,
116- action='accepted')
117+ action='accepted',
118+ announce_from_person=announce_from_person)
119
120 overrides_index += 1
121 copies.extend(sub_copies)
122
123=== modified file 'lib/lp/soyuz/tests/test_packagecopyjob.py'
124--- lib/lp/soyuz/tests/test_packagecopyjob.py 2011-07-26 11:39:14 +0000
125+++ lib/lp/soyuz/tests/test_packagecopyjob.py 2011-07-28 20:49:48 +0000
126@@ -816,6 +816,7 @@
127 self.assertEquals(2, len(emails))
128 self.assertIn("requester@example.com", emails[0]['To'])
129 self.assertIn("changes@example.com", emails[1]['To'])
130+ self.assertEqual("requester@example.com", emails[1]['From'])
131
132 def test_findMatchingDSDs_matches_all_DSDs_for_job(self):
133 # findMatchingDSDs finds matching DSDs for any of the packages