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
=== modified file 'lib/lp/soyuz/adapters/notification.py'
--- lib/lp/soyuz/adapters/notification.py 2011-07-26 10:57:47 +0000
+++ lib/lp/soyuz/adapters/notification.py 2011-07-28 20:49:48 +0000
@@ -125,7 +125,8 @@
125125
126def notify(blamer, spr, bprs, customfiles, archive, distroseries, pocket,126def notify(blamer, spr, bprs, customfiles, archive, distroseries, pocket,
127 summary_text=None, changes=None, changesfile_content=None,127 summary_text=None, changes=None, changesfile_content=None,
128 changesfile_object=None, action=None, dry_run=False, logger=None):128 changesfile_object=None, action=None, dry_run=False,
129 logger=None, announce_from_person=None):
129 """Notify about130 """Notify about
130131
131 :param blamer: The `IPerson` who is to blame for this notification.132 :param blamer: The `IPerson` who is to blame for this notification.
@@ -144,6 +145,9 @@
144 :param action: A string of what action to notify for, such as 'new',145 :param action: A string of what action to notify for, such as 'new',
145 'accepted'.146 'accepted'.
146 :param dry_run: If True, only log the mail.147 :param dry_run: If True, only log the mail.
148 :param announce_from_person: If passed, use this `IPerson` as the From: in
149 announcement emails. If the person has no preferred email address,
150 the person is ignored and the default From: is used instead.
147 """151 """
148 # If this is a binary or mixed upload, we don't send *any* emails152 # If this is a binary or mixed upload, we don't send *any* emails
149 # provided it's not a rejection or a security upload:153 # provided it's not a rejection or a security upload:
@@ -224,6 +228,11 @@
224228
225 (changesfile, date, from_addr, maintainer) = fetch_information(229 (changesfile, date, from_addr, maintainer) = fetch_information(
226 spr, bprs, changes)230 spr, bprs, changes)
231 if announce_from_person is not None:
232 email = announce_from_person.preferredemail
233 if email:
234 from_addr = email.email
235
227 # If we're sending an acceptance notification for a non-PPA upload,236 # If we're sending an acceptance notification for a non-PPA upload,
228 # announce if possible. Avoid announcing backports, binary-only237 # announce if possible. Avoid announcing backports, binary-only
229 # security uploads, or autosync uploads.238 # security uploads, or autosync uploads.
230239
=== modified file 'lib/lp/soyuz/adapters/tests/test_notification.py'
--- lib/lp/soyuz/adapters/tests/test_notification.py 2011-07-26 10:55:05 +0000
+++ lib/lp/soyuz/adapters/tests/test_notification.py 2011-07-28 20:49:48 +0000
@@ -10,6 +10,7 @@
10 ZopelessDatabaseLayer,10 ZopelessDatabaseLayer,
11 )11 )
12from lp.archivepublisher.utils import get_ppa_reference12from lp.archivepublisher.utils import get_ppa_reference
13from lp.registry.interfaces.pocket import PackagePublishingPocket
13from lp.services.mail.sendmail import format_address_for_person14from lp.services.mail.sendmail import format_address_for_person
14from lp.services.log.logger import BufferLogger15from lp.services.log.logger import BufferLogger
15from lp.soyuz.adapters.notification import (16from lp.soyuz.adapters.notification import (
@@ -52,6 +53,28 @@
52 'accepted')53 'accepted')
53 self.assertEqual(expected_subject, subject)54 self.assertEqual(expected_subject, subject)
5455
56 def test_notify_from_person_override(self):
57 # notify() takes an optional from_person to override the calculated
58 # From: address in announcement emails.
59 spr = self.factory.makeSourcePackageRelease()
60 self.factory.makeSourcePackageReleaseFile(sourcepackagerelease=spr)
61 archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY)
62 pocket = PackagePublishingPocket.RELEASE
63 distroseries = self.factory.makeDistroSeries()
64 distroseries.changeslist = "blah@example.com"
65 blamer = self.factory.makePerson()
66 from_person = self.factory.makePerson()
67 notify(
68 blamer, spr, [], [], archive, distroseries, pocket,
69 action='accepted', announce_from_person=from_person)
70 notifications = pop_notifications()
71 self.assertEqual(2, len(notifications))
72 # The first notification is to the blamer,
73 # the second is the announce list, which is the one that gets the
74 # overridden From:
75 self.assertEqual(
76 from_person.preferredemail.email, notifications[1]["From"])
77
5578
56class TestNotification(TestCaseWithFactory):79class TestNotification(TestCaseWithFactory):
5780
5881
=== modified file 'lib/lp/soyuz/model/packagecopyjob.py'
--- lib/lp/soyuz/model/packagecopyjob.py 2011-07-26 11:44:28 +0000
+++ lib/lp/soyuz/model/packagecopyjob.py 2011-07-28 20:49:48 +0000
@@ -511,7 +511,7 @@
511 series=self.target_distroseries, pocket=self.target_pocket,511 series=self.target_distroseries, pocket=self.target_pocket,
512 include_binaries=self.include_binaries, check_permissions=True,512 include_binaries=self.include_binaries, check_permissions=True,
513 person=self.requester, overrides=[override],513 person=self.requester, overrides=[override],
514 send_email=send_email)514 send_email=send_email, announce_from_person=self.requester)
515515
516 if pu is not None:516 if pu is not None:
517 # A PackageUpload will only exist if the copy job had to be517 # A PackageUpload will only exist if the copy job had to be
518518
=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
--- lib/lp/soyuz/scripts/packagecopier.py 2011-07-22 11:12:23 +0000
+++ lib/lp/soyuz/scripts/packagecopier.py 2011-07-28 20:49:48 +0000
@@ -525,7 +525,7 @@
525def do_copy(sources, archive, series, pocket, include_binaries=False,525def do_copy(sources, archive, series, pocket, include_binaries=False,
526 allow_delayed_copies=True, person=None, check_permissions=True,526 allow_delayed_copies=True, person=None, check_permissions=True,
527 overrides=None, send_email=False, strict_binaries=True,527 overrides=None, send_email=False, strict_binaries=True,
528 close_bugs=True, create_dsd_job=True):528 close_bugs=True, create_dsd_job=True, announce_from_person=None):
529 """Perform the complete copy of the given sources incrementally.529 """Perform the complete copy of the given sources incrementally.
530530
531 Verifies if each copy can be performed using `CopyChecker` and531 Verifies if each copy can be performed using `CopyChecker` and
@@ -557,6 +557,8 @@
557 override must be for the corresponding source in the sources list.557 override must be for the corresponding source in the sources list.
558 Overrides will be ignored for delayed copies.558 Overrides will be ignored for delayed copies.
559 :param send_email: Should we notify for the copy performed?559 :param send_email: Should we notify for the copy performed?
560 :param announce_from_person: If send_email is True,
561 then send announcement emails with this person as the From:
560 :param strict_binaries: If 'include_binaries' is True then setting this562 :param strict_binaries: If 'include_binaries' is True then setting this
561 to True will make the copy fail if binaries cannot be also copied.563 to True will make the copy fail if binaries cannot be also copied.
562 :param close_bugs: A boolean indicating whether or not bugs on the564 :param close_bugs: A boolean indicating whether or not bugs on the
@@ -616,7 +618,8 @@
616 notify(618 notify(
617 person, source.sourcepackagerelease, [], [], archive,619 person, source.sourcepackagerelease, [], [], archive,
618 destination_series, pocket, changes=None,620 destination_series, pocket, changes=None,
619 action='accepted')621 action='accepted',
622 announce_from_person=announce_from_person)
620623
621 overrides_index += 1624 overrides_index += 1
622 copies.extend(sub_copies)625 copies.extend(sub_copies)
623626
=== modified file 'lib/lp/soyuz/tests/test_packagecopyjob.py'
--- lib/lp/soyuz/tests/test_packagecopyjob.py 2011-07-26 11:39:14 +0000
+++ lib/lp/soyuz/tests/test_packagecopyjob.py 2011-07-28 20:49:48 +0000
@@ -816,6 +816,7 @@
816 self.assertEquals(2, len(emails))816 self.assertEquals(2, len(emails))
817 self.assertIn("requester@example.com", emails[0]['To'])817 self.assertIn("requester@example.com", emails[0]['To'])
818 self.assertIn("changes@example.com", emails[1]['To'])818 self.assertIn("changes@example.com", emails[1]['To'])
819 self.assertEqual("requester@example.com", emails[1]['From'])
819820
820 def test_findMatchingDSDs_matches_all_DSDs_for_job(self):821 def test_findMatchingDSDs_matches_all_DSDs_for_job(self):
821 # findMatchingDSDs finds matching DSDs for any of the packages822 # findMatchingDSDs finds matching DSDs for any of the packages